Skip to content

Commit

Permalink
Change all controller setups
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Luis Vazquez Gonzalez <[email protected]>
  • Loading branch information
Jose Luis Vazquez Gonzalez committed Mar 6, 2023
1 parent a0344ee commit f1958dc
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pkg/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f1958dc

Please sign in to comment.