Merge pull request #139 from enj/enj/i/use_parent_func

Use parent func to indicate when the controller queue is a singleton
This commit is contained in:
Matt Moyer 2020-11-04 14:21:50 -06:00 committed by GitHub
commit 8684f8f628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 19 deletions

View File

@ -31,7 +31,7 @@ func New(cache *authncache.Cache, webhooks authinformers.WebhookAuthenticatorInf
}, },
controllerlib.WithInformer( controllerlib.WithInformer(
webhooks, webhooks,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(pinnipedcontroller.SingletonQueue()),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -40,7 +40,7 @@ func New(cache *authncache.Cache, webhooks authinformers.WebhookAuthenticatorInf
}, },
controllerlib.WithInformer( controllerlib.WithInformer(
webhooks, webhooks,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(nil), // nil parent func is fine because each event is distinct
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -71,12 +71,12 @@ func NewAnnotaterController(
}, },
withInformer( withInformer(
kubeSystemPodInformer, kubeSystemPodInformer,
pinnipedcontroller.SimpleFilter(isControllerManagerPod), pinnipedcontroller.SimpleFilterWithSingletonQueue(isControllerManagerPod),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
withInformer( withInformer(
agentPodInformer, agentPodInformer,
pinnipedcontroller.SimpleFilter(isAgentPod), pinnipedcontroller.SimpleFilterWithSingletonQueue(isAgentPod),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -65,12 +65,12 @@ func NewCreaterController(
}, },
withInformer( withInformer(
kubeSystemPodInformer, kubeSystemPodInformer,
pinnipedcontroller.SimpleFilter(isControllerManagerPod), pinnipedcontroller.SimpleFilterWithSingletonQueue(isControllerManagerPod),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
withInformer( withInformer(
agentPodInformer, agentPodInformer,
pinnipedcontroller.SimpleFilter(isAgentPod), pinnipedcontroller.SimpleFilterWithSingletonQueue(isAgentPod),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
// Be sure to run once even to make sure the CI is updated if there are no controller manager // Be sure to run once even to make sure the CI is updated if there are no controller manager

View File

@ -43,12 +43,12 @@ func NewDeleterController(
}, },
withInformer( withInformer(
kubeSystemPodInformer, kubeSystemPodInformer,
pinnipedcontroller.SimpleFilter(isControllerManagerPod), pinnipedcontroller.SimpleFilterWithSingletonQueue(isControllerManagerPod),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
withInformer( withInformer(
agentPodInformer, agentPodInformer,
pinnipedcontroller.SimpleFilter(isAgentPod), pinnipedcontroller.SimpleFilterWithSingletonQueue(isAgentPod),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -56,7 +56,7 @@ func NewExecerController(
}, },
withInformer( withInformer(
agentPodInformer, agentPodInformer,
pinnipedcontroller.SimpleFilter(isAgentPod), pinnipedcontroller.SimpleFilter(isAgentPod, nil), // nil parent func is fine because each event is distinct
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -49,12 +49,12 @@ func NewJWKSObserverController(
}, },
withInformer( withInformer(
secretInformer, secretInformer,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(nil),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
withInformer( withInformer(
oidcProviderInformer, oidcProviderInformer,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(nil),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -110,7 +110,7 @@ func NewJWKSWriterController(
// We want to be notified when anything happens to an OPC. // We want to be notified when anything happens to an OPC.
withInformer( withInformer(
opcInformer, opcInformer,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(nil), // nil parent func is fine because each event is distinct
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -60,7 +60,7 @@ func NewOIDCProviderWatcherController(
}, },
withInformer( withInformer(
opcInformer, opcInformer,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(pinnipedcontroller.SingletonQueue()),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -49,12 +49,12 @@ func NewTLSCertObserverController(
}, },
withInformer( withInformer(
secretInformer, secretInformer,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(nil),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
withInformer( withInformer(
oidcProviderInformer, oidcProviderInformer,
pinnipedcontroller.MatchAnythingFilter(), pinnipedcontroller.MatchAnythingFilter(nil),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
) )

View File

@ -12,23 +12,38 @@ import (
func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controllerlib.Filter { func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controllerlib.Filter {
return SimpleFilter(func(obj metav1.Object) bool { return SimpleFilter(func(obj metav1.Object) bool {
return obj.GetName() == name && obj.GetNamespace() == namespace return obj.GetName() == name && obj.GetNamespace() == namespace
}) // nil parent func is fine because we only match a key with the given name and namespace
// i.e. it is equivalent to having a SingletonQueue() parent func
}, nil)
} }
// MatchAnythingFilter returns a controllerlib.Filter that allows all objects. // MatchAnythingFilter returns a controllerlib.Filter that allows all objects.
func MatchAnythingFilter() controllerlib.Filter { func MatchAnythingFilter(parentFunc controllerlib.ParentFunc) controllerlib.Filter {
return SimpleFilter(func(object metav1.Object) bool { return true }) return SimpleFilter(func(object metav1.Object) bool { return true }, parentFunc)
} }
// SimpleFilter takes a single boolean match function on a metav1.Object and wraps it into a proper controllerlib.Filter. // SimpleFilter takes a single boolean match function on a metav1.Object and wraps it into a proper controllerlib.Filter.
func SimpleFilter(match func(metav1.Object) bool) controllerlib.Filter { func SimpleFilter(match func(metav1.Object) bool, parentFunc controllerlib.ParentFunc) controllerlib.Filter {
return controllerlib.FilterFuncs{ return controllerlib.FilterFuncs{
AddFunc: match, AddFunc: match,
UpdateFunc: func(oldObj, newObj metav1.Object) bool { return match(oldObj) || match(newObj) }, UpdateFunc: func(oldObj, newObj metav1.Object) bool { return match(oldObj) || match(newObj) },
DeleteFunc: match, DeleteFunc: match,
ParentFunc: parentFunc,
} }
} }
// SingletonQueue returns a parent func that treats all events as the same key.
func SingletonQueue() controllerlib.ParentFunc {
return func(_ metav1.Object) controllerlib.Key {
return controllerlib.Key{}
}
}
// SimpleFilterWithSingletonQueue returns a Filter based on the given match function that treats all events as the same key.
func SimpleFilterWithSingletonQueue(match func(metav1.Object) bool) controllerlib.Filter {
return SimpleFilter(match, SingletonQueue())
}
// Same signature as controllerlib.WithInformer(). // Same signature as controllerlib.WithInformer().
type WithInformerOptionFunc func( type WithInformerOptionFunc func(
getter controllerlib.InformerGetter, getter controllerlib.InformerGetter,