diff --git a/pkg/controller/main.go b/pkg/controller/main.go index 549eea0eed..9a70bb29d1 100644 --- a/pkg/controller/main.go +++ b/pkg/controller/main.go @@ -196,9 +196,7 @@ func Main(f *Flags, version string) error { } } - sinformer := informers.NewFilteredSharedInformerFactory(clientset, 0, namespace, tweakopts) - ssinformer := ssinformers.NewFilteredSharedInformerFactory(ssclientset, 0, namespace, tweakopts) - controller, err := NewController(clientset, ssclientset, ssinformer, sinformer, keyRegistry) + controller, err := prepareController(clientset, namespace, tweakopts, f, ssclientset, keyRegistry) if err != nil { return err } @@ -213,10 +211,6 @@ func Main(f *Flags, version string) error { if f.AdditionalNamespaces != "" { addNS := removeDuplicates(strings.Split(f.AdditionalNamespaces, ",")) - var ssinf ssinformers.SharedInformerFactory - var sinf informers.SharedInformerFactory - var ctlr *Controller - for _, ns := range addNS { if _, err := clientset.CoreV1().Namespaces().Get(ctx, ns, metav1.GetOptions{}); err != nil { if errors.IsNotFound(err) { @@ -226,9 +220,7 @@ func Main(f *Flags, version string) error { return err } if ns != namespace { - ssinf = ssinformers.NewFilteredSharedInformerFactory(ssclientset, 0, ns, tweakopts) - sinf = initSecretInformerFactory(clientset, ns, tweakopts, f.SkipRecreate) - ctlr, err = NewController(clientset, ssclientset, ssinf, sinf, keyRegistry) + ctlr, err := prepareController(clientset, ns, tweakopts, f, ssclientset, keyRegistry) if err != nil { return err } @@ -257,6 +249,13 @@ func Main(f *Flags, version string) error { return server.Shutdown(context.Background()) } +func prepareController(clientset *kubernetes.Clientset, namespace string, tweakopts func( *metav1.ListOptions), f *Flags, ssclientset *sealedsecrets.Clientset, keyRegistry *KeyRegistry) (*Controller, error) { + sinformer := initSecretInformerFactory(clientset, namespace, tweakopts, f.SkipRecreate) + ssinformer := ssinformers.NewFilteredSharedInformerFactory(ssclientset, 0, namespace, tweakopts) + controller, err := NewController(clientset, ssclientset, ssinformer, sinformer, keyRegistry) + return controller, err +} + func initSecretInformerFactory(clientset kubernetes.Interface, ns string, tweakopts func(*metav1.ListOptions), skipRecreate bool) informers.SharedInformerFactory { if skipRecreate { return nil