From 1a4687a40a65bd7f861d24ebc6e2e6d401bac799 Mon Sep 17 00:00:00 2001 From: Matt Moyer Date: Wed, 26 May 2021 12:54:40 -0500 Subject: [PATCH] Switch impersonatorconfig to all singleton queues. We also no longer need an initial event, since we don't do anything unless the CredentialIssuer exists, so we'll always be triggered at the appropriate time. Signed-off-by: Matt Moyer --- .../impersonatorconfig/impersonator_config.go | 13 +++++-------- .../impersonatorconfig/impersonator_config_test.go | 12 ------------ internal/controllermanager/prepare_controllers.go | 1 - 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/internal/controller/impersonatorconfig/impersonator_config.go b/internal/controller/impersonatorconfig/impersonator_config.go index 6af92288..2e6a106a 100644 --- a/internal/controller/impersonatorconfig/impersonator_config.go +++ b/internal/controller/impersonatorconfig/impersonator_config.go @@ -93,7 +93,6 @@ func NewImpersonatorConfigController( servicesInformer corev1informers.ServiceInformer, secretsInformer corev1informers.SecretInformer, withInformer pinnipedcontroller.WithInformerOptionFunc, - withInitialEvent pinnipedcontroller.WithInitialEventOptionFunc, generatedLoadBalancerServiceName string, generatedClusterIPServiceName string, tlsSecretName string, @@ -140,20 +139,18 @@ func NewImpersonatorConfigController( ), withInformer( servicesInformer, - pinnipedcontroller.NameAndNamespaceExactMatchFilterFactory(generatedLoadBalancerServiceName, namespace), + pinnipedcontroller.SimpleFilterWithSingletonQueue(func(obj metav1.Object) bool { + return obj.GetNamespace() == namespace && obj.GetName() == generatedLoadBalancerServiceName + }), controllerlib.InformerOption{}, ), withInformer( secretsInformer, - pinnipedcontroller.SimpleFilter(func(obj metav1.Object) bool { + pinnipedcontroller.SimpleFilterWithSingletonQueue(func(obj metav1.Object) bool { return obj.GetNamespace() == namespace && secretNames.Has(obj.GetName()) - }, nil), + }), controllerlib.InformerOption{}, ), - // Be sure to run once even if the CredentialIssuer that the informer is watching doesn't exist so we can implement - // the default configuration behavior. - withInitialEvent(controllerlib.Key{Name: credentialIssuerResourceName}), - // TODO fix these controller options to make this a singleton queue ) } diff --git a/internal/controller/impersonatorconfig/impersonator_config_test.go b/internal/controller/impersonatorconfig/impersonator_config_test.go index c9dbe992..349ee974 100644 --- a/internal/controller/impersonatorconfig/impersonator_config_test.go +++ b/internal/controller/impersonatorconfig/impersonator_config_test.go @@ -57,7 +57,6 @@ func TestImpersonatorConfigControllerOptions(t *testing.T) { var r *require.Assertions var observableWithInformerOption *testutil.ObservableWithInformerOption - var observableWithInitialEventOption *testutil.ObservableWithInitialEventOption var credIssuerInformerFilter controllerlib.Filter var servicesInformerFilter controllerlib.Filter var secretsInformerFilter controllerlib.Filter @@ -66,7 +65,6 @@ func TestImpersonatorConfigControllerOptions(t *testing.T) { it.Before(func() { r = require.New(t) observableWithInformerOption = testutil.NewObservableWithInformerOption() - observableWithInitialEventOption = testutil.NewObservableWithInitialEventOption() pinnipedInformerFactory := pinnipedinformers.NewSharedInformerFactory(nil, 0) sharedInformerFactory := kubeinformers.NewSharedInformerFactory(nil, 0) credIssuerInformer := pinnipedInformerFactory.Config().V1alpha1().CredentialIssuers() @@ -83,7 +81,6 @@ func TestImpersonatorConfigControllerOptions(t *testing.T) { servicesInformer, secretsInformer, observableWithInformerOption.WithInformer, - observableWithInitialEventOption.WithInitialEvent, generatedLoadBalancerServiceName, generatedClusterIPServiceName, tlsSecretName, @@ -240,14 +237,6 @@ func TestImpersonatorConfigControllerOptions(t *testing.T) { }) }) }) - - when("starting up", func() { - it("asks for an initial event because the CredentialIssuer may not exist yet and it needs to run anyway", func() { - r.Equal(&controllerlib.Key{ - Name: credentialIssuerResourceName, - }, observableWithInitialEventOption.GetInitialEventKey()) - }) - }) }, spec.Parallel(), spec.Report(report.Terminal{})) } @@ -531,7 +520,6 @@ func TestImpersonatorConfigControllerSync(t *testing.T) { kubeInformers.Core().V1().Services(), kubeInformers.Core().V1().Secrets(), controllerlib.WithInformer, - controllerlib.WithInitialEvent, loadBalancerServiceName, clusterIPServiceName, tlsSecretName, diff --git a/internal/controllermanager/prepare_controllers.go b/internal/controllermanager/prepare_controllers.go index 60c759f9..e6b69ec1 100644 --- a/internal/controllermanager/prepare_controllers.go +++ b/internal/controllermanager/prepare_controllers.go @@ -259,7 +259,6 @@ func PrepareControllers(c *Config) (func(ctx context.Context), error) { informers.installationNamespaceK8s.Core().V1().Services(), informers.installationNamespaceK8s.Core().V1().Secrets(), controllerlib.WithInformer, - controllerlib.WithInitialEvent, c.NamesConfig.ImpersonationLoadBalancerService, c.NamesConfig.ImpersonationClusterIPService, c.NamesConfig.ImpersonationTLSCertificateSecret,