Skip to content

Commit

Permalink
Change argument name to watchNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
akartsky committed May 13, 2021
1 parent 3c54a20 commit 13280e0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,7 +47,7 @@ type Config struct {
EndpointURL string
LogLevel string
ResourceTags []string
ListenNamespace string
WatchNamespace string
}

// BindFlags defines CLI/runtime configuration options
Expand Down Expand Up @@ -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",
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/adoption_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/runtime/cache/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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"
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 13280e0

Please sign in to comment.