diff --git a/pkg/config/config.go b/pkg/config/config.go index 5cb00d6..92be7d2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -33,7 +33,7 @@ const ( flagAWSEndpointURL = "aws-endpoint-url" flagLogLevel = "log-level" flagResourceTags = "resource-tags" - flagListenNamespace = "listen-namespace" + flagWatchNamespace = "watch-namespace" ) // Config contains configuration otpions for ACK service controllers @@ -47,7 +47,7 @@ type Config struct { EndpointURL string LogLevel string ResourceTags []string - ListenNamespace string + WatchNamespace string } // BindFlags defines CLI/runtime configuration options @@ -102,9 +102,9 @@ func (cfg *Config) BindFlags() { "Configures the ACK service controller to always set key/value pairs tags on resources that it manages.", ) flag.StringVar( - &cfg.ListenNamespace, flagListenNamespace, + &cfg.WatchNamespace , flagWatchNamespace, "", - "Specific namespace the service controller will listen to for object creation from CRD. "+ + "Specific namespace the service controller will watch for object creation from CRD. "+ " By default it will listen to all namespaces", ) } diff --git a/pkg/runtime/adoption_reconciler.go b/pkg/runtime/adoption_reconciler.go index 560d895..29cfb81 100644 --- a/pkg/runtime/adoption_reconciler.go +++ b/pkg/runtime/adoption_reconciler.go @@ -58,7 +58,7 @@ func (r *adoptionReconciler) BindControllerManager(mgr ctrlrt.Manager) error { return err } r.kc = mgr.GetClient() - r.cache = ackrtcache.New(clientset, r.log, r.cfg.ListenNamespace) + r.cache = ackrtcache.New(clientset, r.log, r.cfg.WatchNamespace) r.cache.Run() return ctrlrt.NewControllerManagedBy( mgr, diff --git a/pkg/runtime/cache/cache.go b/pkg/runtime/cache/cache.go index 5964b01..a8a14f0 100644 --- a/pkg/runtime/cache/cache.go +++ b/pkg/runtime/cache/cache.go @@ -58,10 +58,10 @@ type Caches struct { // New creates a new Caches object from a kubernetes.Interface and // a logr.Logger -func New(clientset kubernetes.Interface, log logr.Logger, listenNamespace string) Caches { +func New(clientset kubernetes.Interface, log logr.Logger, watchNamespace string) Caches { return Caches{ Accounts: NewAccountCache(clientset, log), - Namespaces: NewNamespaceCache(clientset, log, listenNamespace), + Namespaces: NewNamespaceCache(clientset, log, watchNamespace), } } diff --git a/pkg/runtime/cache/namespace.go b/pkg/runtime/cache/namespace.go index 897c2c6..56a64dd 100644 --- a/pkg/runtime/cache/namespace.go +++ b/pkg/runtime/cache/namespace.go @@ -57,7 +57,7 @@ type NamespaceCache struct { log logr.Logger // Provide a namespace specifically to listen to. // Provide empty string to listen to all namespaces except kube-system and kube-public. - listenNamespace string + watchNamespace string // Namespace informer informer k8scache.SharedInformer @@ -67,7 +67,7 @@ type NamespaceCache struct { // NewNamespaceCache makes a new NamespaceCache from a // kubernetes.Interface and a logr.Logger -func NewNamespaceCache(clientset kubernetes.Interface, log logr.Logger, listenNamespace string) *NamespaceCache { +func NewNamespaceCache(clientset kubernetes.Interface, log logr.Logger, watchNamespace string) *NamespaceCache { sharedInformer := informersv1.NewNamespaceInformer( clientset, informerResyncPeriod, @@ -76,20 +76,20 @@ func NewNamespaceCache(clientset kubernetes.Interface, log logr.Logger, listenNa return &NamespaceCache{ informer: sharedInformer, log: log.WithName("cache.namespace"), - listenNamespace: listenNamespace, + watchNamespace: watchNamespace, namespaceInfos: make(map[string]*namespaceInfo), } } // Check if the provided namespace should be listened to or not -func isListenNamespace(raw interface{}, listenNamespace string) bool { +func isWatchNamespace(raw interface{}, watchNamespace string) bool { object, ok := raw.(*corev1.Namespace) if !ok { return false } - if listenNamespace != "" { - return listenNamespace == object.ObjectMeta.Name + if watchNamespace != "" { + return watchNamespace == object.ObjectMeta.Name } return object.ObjectMeta.Name != "kube-system" && object.ObjectMeta.Name != "kube-public" } @@ -99,21 +99,21 @@ func isListenNamespace(raw interface{}, listenNamespace string) bool { func (c *NamespaceCache) Run(stopCh <-chan struct{}) { c.informer.AddEventHandler(k8scache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - if isListenNamespace(obj, c.listenNamespace) { + if isWatchNamespace(obj, c.watchNamespace) { ns := obj.(*corev1.Namespace) c.setNamespaceInfoFromK8sObject(ns) c.log.V(1).Info("created namespace", "name", ns.ObjectMeta.Name) } }, UpdateFunc: func(orig, desired interface{}) { - if isListenNamespace(desired, c.listenNamespace) { + if isWatchNamespace(desired, c.watchNamespace) { ns := desired.(*corev1.Namespace) c.setNamespaceInfoFromK8sObject(ns) c.log.V(1).Info("updated namespace", "name", ns.ObjectMeta.Name) } }, DeleteFunc: func(obj interface{}) { - if isListenNamespace(obj, c.listenNamespace) { + if isWatchNamespace(obj, c.watchNamespace) { ns := obj.(*corev1.Namespace) c.deleteNamespaceInfo(ns.ObjectMeta.Name) c.log.V(1).Info("deleted namespace", "name", ns.ObjectMeta.Name) diff --git a/pkg/runtime/reconciler.go b/pkg/runtime/reconciler.go index f685c53..4a40e98 100644 --- a/pkg/runtime/reconciler.go +++ b/pkg/runtime/reconciler.go @@ -79,7 +79,7 @@ func (r *resourceReconciler) BindControllerManager(mgr ctrlrt.Manager) error { return err } r.kc = mgr.GetClient() - r.cache = ackrtcache.New(clientset, r.log, r.cfg.ListenNamespace) + r.cache = ackrtcache.New(clientset, r.log, r.cfg.WatchNamespace) r.cache.Run() rd := r.rmf.ResourceDescriptor() return ctrlrt.NewControllerManagedBy(