Last active
September 12, 2017 11:17
-
-
Save treacher/b38c7383cebe01f57730f1f8956784fb to your computer and use it in GitHub Desktop.
Namespace Rolebinding Operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NamespaceController watches the kubernetes api for changes to namespaces and | |
// creates a RoleBinding for that particular namespace. | |
type NamespaceController struct { | |
namespaceInformer cache.SharedIndexInformer | |
kclient *kubernetes.Clientset | |
} | |
// NewNamespaceController creates a new NewNamespaceController | |
func NewNamespaceController(kclient *kubernetes.Clientset) *NamespaceController { | |
namespaceWatcher := &NamespaceController{} | |
// Create informer for watching Namespaces | |
namespaceInformer := cache.NewSharedIndexInformer( | |
&cache.ListWatch{ | |
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { | |
return kclient.Core().Namespaces().List(options) | |
}, | |
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { | |
return kclient.Core().Namespaces().Watch(options) | |
}, | |
}, | |
&v1.Namespace{}, | |
3*time.Minute, | |
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, | |
) | |
namespaceInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ | |
AddFunc: namespaceWatcher.createRoleBinding, | |
}) | |
namespaceWatcher.kclient = kclient | |
namespaceWatcher.namespaceInformer = namespaceInformer | |
return namespaceWatcher | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// NewNamespaceController creates a new NamespaceController