diff --git a/radix-operator/alert/controller.go b/radix-operator/alert/controller.go index 86829a7a5..a1c9768f4 100644 --- a/radix-operator/alert/controller.go +++ b/radix-operator/alert/controller.go @@ -27,28 +27,28 @@ const ( ) // NewController creates a new controller that handles RadixAlerts -func NewController(ctx context.Context, client kubernetes.Interface, - radixClient radixclient.Interface, handler common.Handler, +func NewController(ctx context.Context, + kubeClient kubernetes.Interface, + radixClient radixclient.Interface, + handler common.Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, - waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { logger := log.With().Str("controller", controllerAgentName).Logger() alertInformer := radixInformerFactory.Radix().V1().RadixAlerts() registrationInformer := radixInformerFactory.Radix().V1().RadixRegistrations() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: crType, - KubeClient: client, - RadixClient: radixClient, - Informer: alertInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamespacePartitionKey, + Name: controllerAgentName, + HandlerOf: crType, + KubeClient: kubeClient, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamespacePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/alert/controller_test.go b/radix-operator/alert/controller_test.go index fdff1f471..87eaaed8f 100644 --- a/radix-operator/alert/controller_test.go +++ b/radix-operator/alert/controller_test.go @@ -26,7 +26,7 @@ func (s *controllerTestSuite) Test_RadixAlertEvents() { alertName, namespace := "any-alert", "any-ns" alert := &v1.RadixAlert{ObjectMeta: metav1.ObjectMeta{Name: alertName}} - sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, false, s.EventRecorder) + sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, s.EventRecorder) s.RadixInformerFactory.Start(s.Ctx.Done()) s.KubeInformerFactory.Start(s.Ctx.Done()) go func() { @@ -69,7 +69,7 @@ func (s *controllerTestSuite) Test_RadixRegistrationEvents() { s.Require().NoError(err) } - sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, false, s.EventRecorder) + sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, s.EventRecorder) s.RadixInformerFactory.Start(s.Ctx.Done()) s.KubeInformerFactory.Start(s.Ctx.Done()) go func() { diff --git a/radix-operator/application/controller.go b/radix-operator/application/controller.go index 490add4e0..d45f54913 100644 --- a/radix-operator/application/controller.go +++ b/radix-operator/application/controller.go @@ -26,28 +26,28 @@ const ( ) // NewController creates a new controller that handles RadixApplications -func NewController(ctx context.Context, client kubernetes.Interface, - radixClient radixclient.Interface, handler common.Handler, +func NewController(ctx context.Context, + kubeClient kubernetes.Interface, + radixClient radixclient.Interface, + handler common.Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, - waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { logger := log.With().Str("controller", controllerAgentName).Logger() applicationInformer := radixInformerFactory.Radix().V1().RadixApplications() registrationInformer := radixInformerFactory.Radix().V1().RadixRegistrations() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: crType, - KubeClient: client, - RadixClient: radixClient, - Informer: applicationInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamespacePartitionKey, + Name: controllerAgentName, + HandlerOf: crType, + KubeClient: kubeClient, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamespacePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/application/controller_test.go b/radix-operator/application/controller_test.go index 55787eaba..bff58d049 100644 --- a/radix-operator/application/controller_test.go +++ b/radix-operator/application/controller_test.go @@ -26,7 +26,7 @@ func (s *controllerTestSuite) Test_Controller_Calls_Handler() { namespace := utils.GetAppNamespace(appName) appNamespace := test.CreateAppNamespace(s.KubeClient, appName) - sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, false, s.EventRecorder) + sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, s.EventRecorder) s.RadixInformerFactory.Start(s.Ctx.Done()) s.KubeInformerFactory.Start(s.Ctx.Done()) @@ -53,7 +53,7 @@ func (s *controllerTestSuite) Test_Controller_Calls_Handler_On_Admin_Or_Reader_C s.Require().NoError(err) } - sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, false, s.EventRecorder) + sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, s.EventRecorder) s.RadixInformerFactory.Start(s.Ctx.Done()) s.KubeInformerFactory.Start(s.Ctx.Done()) diff --git a/radix-operator/batch/controller.go b/radix-operator/batch/controller.go index b923b8433..895316f3d 100644 --- a/radix-operator/batch/controller.go +++ b/radix-operator/batch/controller.go @@ -23,28 +23,28 @@ const ( ) // NewController creates a new controller that handles RadixBatches -func NewController(ctx context.Context, client kubernetes.Interface, - radixClient radixclient.Interface, handler common.Handler, +func NewController(ctx context.Context, + kubeClient kubernetes.Interface, + radixClient radixclient.Interface, + handler common.Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, - waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { logger := log.With().Str("controller", controllerAgentName).Logger() batchInformer := radixInformerFactory.Radix().V1().RadixBatches() jobInformer := kubeInformerFactory.Batch().V1().Jobs() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: crType, - KubeClient: client, - RadixClient: radixClient, - Informer: batchInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamespacePartitionKey, + Name: controllerAgentName, + HandlerOf: crType, + KubeClient: kubeClient, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamespacePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/batch/controller_test.go b/radix-operator/batch/controller_test.go index 896583789..dc62beebc 100644 --- a/radix-operator/batch/controller_test.go +++ b/radix-operator/batch/controller_test.go @@ -26,7 +26,7 @@ func (s *controllerTestSuite) Test_RadixBatchEvents() { batchName, namespace := "a-batch-job", "a-ns" jobName := "a-job" - sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, false, s.EventRecorder) + sut := NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, s.EventRecorder) s.RadixInformerFactory.Start(s.Ctx.Done()) s.KubeInformerFactory.Start(s.Ctx.Done()) go func() { diff --git a/radix-operator/common/controller.go b/radix-operator/common/controller.go index 950072647..c40fe2b85 100644 --- a/radix-operator/common/controller.go +++ b/radix-operator/common/controller.go @@ -8,6 +8,7 @@ import ( "github.com/equinor/radix-operator/pkg/apis/metrics" radixclient "github.com/equinor/radix-operator/pkg/client/clientset/versioned" + informers "github.com/equinor/radix-operator/pkg/client/informers/externalversions" "github.com/rs/zerolog/log" "golang.org/x/sync/errgroup" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -21,18 +22,17 @@ import ( // Controller Instance variables type Controller struct { - Name string - HandlerOf string - KubeClient kubernetes.Interface - RadixClient radixclient.Interface - WorkQueue workqueue.RateLimitingInterface - Informer cache.SharedIndexInformer - KubeInformerFactory kubeinformers.SharedInformerFactory - Handler Handler - WaitForChildrenToSync bool - Recorder record.EventRecorder - LockKeyAndIdentifier LockKeyAndIdentifierFunc - locker resourceLocker + Name string + HandlerOf string + KubeClient kubernetes.Interface + RadixClient radixclient.Interface + WorkQueue workqueue.RateLimitingInterface + KubeInformerFactory kubeinformers.SharedInformerFactory + RadixInformerFactory informers.SharedInformerFactory + Handler Handler + Recorder record.EventRecorder + LockKeyAndIdentifier LockKeyAndIdentifierFunc + locker resourceLocker } // Run starts the shared informer, which will be stopped when stopCh is closed. @@ -48,24 +48,12 @@ func (c *Controller) Run(ctx context.Context, threadiness int) error { logger := log.Ctx(ctx) logger.Debug().Msgf("Starting") - cacheSyncs := []cache.InformerSynced{ - c.hasSynced, - } - - logger.Debug().Msg("Start WaitForChildrenToSync") - if c.WaitForChildrenToSync { - cacheSyncs = append(cacheSyncs, - c.KubeInformerFactory.Core().V1().Namespaces().Informer().HasSynced, - c.KubeInformerFactory.Core().V1().Secrets().Informer().HasSynced, - ) - } - logger.Debug().Msg("Completed WaitForChildrenToSync") - // Wait for the caches to be synced before starting workers - logger.Info().Msg("Waiting for informer caches to sync") - if ok := cache.WaitForCacheSync(ctx.Done(), cacheSyncs...); !ok { - return fmt.Errorf("failed to wait for caches to sync") - } + logger.Info().Msg("Waiting for Kube objects caches to sync") + c.KubeInformerFactory.WaitForCacheSync(ctx.Done()) + logger.Info().Msg("Waiting for Radix objects caches to sync") + c.RadixInformerFactory.WaitForCacheSync(ctx.Done()) + logger.Info().Msg("Completed syncing informer caches") logger.Info().Msg("Starting workers") @@ -252,7 +240,3 @@ func (c *Controller) HandleObject(ctx context.Context, obj interface{}, ownerKin return } } - -func (c *Controller) hasSynced() bool { - return c.Informer.HasSynced() -} diff --git a/radix-operator/common/controller_test.go b/radix-operator/common/controller_test.go index 9449e6fc9..79742ed8f 100644 --- a/radix-operator/common/controller_test.go +++ b/radix-operator/common/controller_test.go @@ -66,13 +66,14 @@ func (s *commonControllerTestSuite) Test_SyncSuccess() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { parts := strings.Split(obj.(string), "/") return parts[0], obj.(string), nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -111,13 +112,14 @@ func (s *commonControllerTestSuite) Test_RequeueWhenSyncError() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { parts := strings.Split(obj.(string), "/") return parts[0], obj.(string), nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -156,12 +158,13 @@ func (s *commonControllerTestSuite) Test_ForgetWhenLockKeyAndIdentifierError() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { return "", "", errors.New("any error") }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -197,12 +200,13 @@ func (s *commonControllerTestSuite) Test_SkipItemWhenNil() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { return "any", "any", nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -236,12 +240,13 @@ func (s *commonControllerTestSuite) Test_SkipItemWhenEmpty() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { return "any", "any", nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -275,12 +280,13 @@ func (s *commonControllerTestSuite) Test_QuitRunWhenShutdownTrue() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { return "any", "any", nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -313,12 +319,13 @@ func (s *commonControllerTestSuite) Test_QuitRunWhenShuttingDownTrue() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { return "any", "any", nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -353,13 +360,14 @@ func (s *commonControllerTestSuite) Test_RequeueWhenLocked() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { parts := strings.Split(obj.(string), "/") return parts[0], obj.(string), nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(stopCh) @@ -396,13 +404,14 @@ func (s *commonControllerTestSuite) Test_ProcessParallell() { sut := &Controller{ Handler: s.Handler, RadixClient: s.RadixClient, - Informer: s.KubeInformerFactory.Core().V1().ConfigMaps().Informer(), LockKeyAndIdentifier: func(obj interface{}) (lockKey string, identifier string, err error) { parts := strings.Split(obj.(string), "/") return parts[0], obj.(string), nil }, - WorkQueue: queue, - locker: locker, + WorkQueue: queue, + locker: locker, + KubeInformerFactory: s.KubeInformerFactory, + RadixInformerFactory: s.RadixInformerFactory, } s.KubeInformerFactory.Start(ctx.Done()) diff --git a/radix-operator/deployment/controller.go b/radix-operator/deployment/controller.go index 4a72d7aaa..d70bf0170 100644 --- a/radix-operator/deployment/controller.go +++ b/radix-operator/deployment/controller.go @@ -28,12 +28,12 @@ const ( ) // NewController creates a new controller that handles RadixDeployments -func NewController(ctx context.Context, client kubernetes.Interface, +func NewController(ctx context.Context, + kubeClient kubernetes.Interface, radixClient radixclient.Interface, handler common.Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, - waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { logger := log.Ctx(ctx).With().Str("controller", controllerAgentName).Logger() ctx = logger.WithContext(ctx) @@ -42,17 +42,16 @@ func NewController(ctx context.Context, client kubernetes.Interface, registrationInformer := radixInformerFactory.Radix().V1().RadixRegistrations() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: crType, - KubeClient: client, - RadixClient: radixClient, - Informer: deploymentInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamespacePartitionKey, + Name: controllerAgentName, + HandlerOf: crType, + KubeClient: kubeClient, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamespacePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/deployment/controller_test.go b/radix-operator/deployment/controller_test.go index 3913b0f85..12e72f2fc 100644 --- a/radix-operator/deployment/controller_test.go +++ b/radix-operator/deployment/controller_test.go @@ -165,14 +165,7 @@ func startDeploymentController(ctx context.Context, client kubernetes.Interface, eventRecorder := &record.FakeRecorder{} - const waitForChildrenToSync = false - controller := NewController( - ctx, - client, radixClient, handler, - kubeInformerFactory, - radixInformerFactory, - waitForChildrenToSync, - eventRecorder) + controller := NewController(ctx, client, radixClient, handler, kubeInformerFactory, radixInformerFactory, eventRecorder) kubeInformerFactory.Start(ctx.Done()) radixInformerFactory.Start(ctx.Done()) diff --git a/radix-operator/dnsalias/controller.go b/radix-operator/dnsalias/controller.go index f6d8e4026..84b9e9286 100644 --- a/radix-operator/dnsalias/controller.go +++ b/radix-operator/dnsalias/controller.go @@ -33,23 +33,21 @@ func NewController(ctx context.Context, kubeClient kubernetes.Interface, handler common.Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, - waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { logger := log.With().Str("controller", controllerAgentName).Logger() radixDNSAliasInformer := radixInformerFactory.Radix().V1().RadixDNSAliases() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: radixv1.KindRadixDNSAlias, - KubeClient: kubeClient, - RadixClient: radixClient, - Informer: radixDNSAliasInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, radixv1.KindRadixDNSAlias), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamePartitionKey, + Name: controllerAgentName, + HandlerOf: radixv1.KindRadixDNSAlias, + KubeClient: kubeClient, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, radixv1.KindRadixDNSAlias), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/dnsalias/controller_test.go b/radix-operator/dnsalias/controller_test.go index 50efffdf7..1fcd6eb0e 100644 --- a/radix-operator/dnsalias/controller_test.go +++ b/radix-operator/dnsalias/controller_test.go @@ -36,7 +36,7 @@ func (s *controllerTestSuite) TearDownTest() { } func (s *controllerTestSuite) Test_RadixDNSAliasEvents() { - sut := dnsalias.NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, false, s.EventRecorder) + sut := dnsalias.NewController(context.Background(), s.KubeClient, s.RadixClient, s.Handler, s.KubeInformerFactory, s.RadixInformerFactory, s.EventRecorder) s.RadixInformerFactory.Start(s.Ctx.Done()) s.KubeInformerFactory.Start(s.Ctx.Done()) go func() { diff --git a/radix-operator/environment/controller.go b/radix-operator/environment/controller.go index 54aca22b8..ff25d0c90 100644 --- a/radix-operator/environment/controller.go +++ b/radix-operator/environment/controller.go @@ -27,12 +27,12 @@ const ( ) // NewController creates a new controller that handles RadixEnvironments -func NewController(ctx context.Context, client kubernetes.Interface, +func NewController(ctx context.Context, + client kubernetes.Interface, radixClient radixclient.Interface, handler common.Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, - waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { logger := log.With().Str("controller", controllerAgentName).Logger() environmentInformer := radixInformerFactory.Radix().V1().RadixEnvironments() @@ -40,17 +40,16 @@ func NewController(ctx context.Context, client kubernetes.Interface, applicationInformer := radixInformerFactory.Radix().V1().RadixApplications() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: crType, - KubeClient: client, - RadixClient: radixClient, - Informer: environmentInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamePartitionKey, + Name: controllerAgentName, + HandlerOf: crType, + KubeClient: client, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/job/controller.go b/radix-operator/job/controller.go index 0e7f718d5..52e435ae5 100644 --- a/radix-operator/job/controller.go +++ b/radix-operator/job/controller.go @@ -26,24 +26,29 @@ const ( ) // NewController creates a new controller that handles RadixJobs -func NewController(ctx context.Context, client kubernetes.Interface, radixClient radixclient.Interface, handler Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { +func NewController(ctx context.Context, + client kubernetes.Interface, + radixClient radixclient.Interface, + handler Handler, + kubeInformerFactory kubeinformers.SharedInformerFactory, + radixInformerFactory informers.SharedInformerFactory, + recorder record.EventRecorder) *common.Controller { logger := log.With().Str("controller", controllerAgentName).Logger() radixJobInformer := radixInformerFactory.Radix().V1().RadixJobs() kubernetesJobInformer := kubeInformerFactory.Batch().V1().Jobs() podInformer := kubeInformerFactory.Core().V1().Pods() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: crType, - KubeClient: client, - RadixClient: radixClient, - Informer: radixJobInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamespacePartitionKey, + Name: controllerAgentName, + HandlerOf: crType, + KubeClient: client, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamespacePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/job/controller_test.go b/radix-operator/job/controller_test.go index be416a3be..d7f29adda 100644 --- a/radix-operator/job/controller_test.go +++ b/radix-operator/job/controller_test.go @@ -153,8 +153,7 @@ func (s *jobTestSuite) startJobController(ctx context.Context, handler Handler) kubeInformerFactory := kubeinformers.NewSharedInformerFactory(s.kubeUtil.KubeClient(), 0) radixInformerFactory := informers.NewSharedInformerFactory(s.kubeUtil.RadixClient(), 0) eventRecorder := &record.FakeRecorder{} - const waitForChildrenToSync = false - controller := NewController(ctx, s.kubeUtil.KubeClient(), s.kubeUtil.RadixClient(), handler, kubeInformerFactory, radixInformerFactory, waitForChildrenToSync, eventRecorder) + controller := NewController(ctx, s.kubeUtil.KubeClient(), s.kubeUtil.RadixClient(), handler, kubeInformerFactory, radixInformerFactory, eventRecorder) kubeInformerFactory.Start(ctx.Done()) radixInformerFactory.Start(ctx.Done()) return controller.Run(ctx, 4) diff --git a/radix-operator/main.go b/radix-operator/main.go index e037c36a4..ae279d689 100644 --- a/radix-operator/main.go +++ b/radix-operator/main.go @@ -231,14 +231,12 @@ func (a *App) createRegistrationController(ctx context.Context) *common.Controll func(syncedOk bool) {}, // Not interested in getting notifications of synced ) - return registration.NewController( - ctx, + return registration.NewController(ctx, a.kubeUtil.KubeClient(), a.kubeUtil.RadixClient(), &handler, a.kubeInformerFactory, a.radixInformerFactory, - true, a.eventRecorder) } @@ -251,14 +249,12 @@ func (a *App) createApplicationController(ctx context.Context) *common.Controlle func(syncedOk bool) {}, // Not interested in getting notifications of synced ) - return application.NewController( - ctx, + return application.NewController(ctx, a.kubeUtil.KubeClient(), a.kubeUtil.RadixClient(), &handler, a.kubeInformerFactory, a.radixInformerFactory, - true, a.eventRecorder) } @@ -270,19 +266,16 @@ func (a *App) createEnvironmentController(ctx context.Context) *common.Controlle func(syncedOk bool) {}, // Not interested in getting notifications of synced ) - return environment.NewController( - ctx, + return environment.NewController(ctx, a.kubeUtil.KubeClient(), a.kubeUtil.RadixClient(), &handler, a.kubeInformerFactory, a.radixInformerFactory, - true, a.eventRecorder) } func (a *App) createDNSAliasesController(ctx context.Context) *common.Controller { - handler := dnsalias.NewHandler( a.kubeUtil.KubeClient(), a.kubeUtil, @@ -300,12 +293,10 @@ func (a *App) createDNSAliasesController(ctx context.Context) *common.Controller handler, a.kubeInformerFactory, a.radixInformerFactory, - true, a.eventRecorder) } func (a *App) createDeploymentController(ctx context.Context) *common.Controller { - oauth2DockerImage := os.Getenv(defaults.RadixOAuthProxyImageEnvironmentVariable) if oauth2DockerImage == "" { panic(fmt.Errorf("failed to read OAuth2 Docker image from environment variable %s", defaults.RadixOAuthProxyImageEnvironmentVariable)) @@ -323,14 +314,12 @@ func (a *App) createDeploymentController(ctx context.Context) *common.Controller deployment.WithOAuth2ProxyDockerImage(oauth2DockerImage), ) - return deployment.NewController( - ctx, + return deployment.NewController(ctx, a.kubeUtil.KubeClient(), a.kubeUtil.RadixClient(), handler, a.kubeInformerFactory, a.radixInformerFactory, - true, a.eventRecorder) } @@ -342,11 +331,7 @@ func (a *App) createJobController(ctx context.Context) *common.Controller { a.config, func(syncedOk bool) {}) // Not interested in getting notifications of synced - return job.NewController( - ctx, - a.kubeUtil.KubeClient(), - a.kubeUtil.RadixClient(), - handler, a.kubeInformerFactory, a.radixInformerFactory, true, a.eventRecorder) + return job.NewController(ctx, a.kubeUtil.KubeClient(), a.kubeUtil.RadixClient(), handler, a.kubeInformerFactory, a.radixInformerFactory, a.eventRecorder) } func (a *App) createAlertController(ctx context.Context) *common.Controller { @@ -357,15 +342,7 @@ func (a *App) createAlertController(ctx context.Context) *common.Controller { a.prometheusOperatorClient, ) - return alert.NewController( - ctx, - a.kubeUtil.KubeClient(), - a.kubeUtil.RadixClient(), - handler, - a.kubeInformerFactory, - a.radixInformerFactory, - true, - a.eventRecorder) + return alert.NewController(ctx, a.kubeUtil.KubeClient(), a.kubeUtil.RadixClient(), handler, a.kubeInformerFactory, a.radixInformerFactory, a.eventRecorder) } func (a *App) createBatchController(ctx context.Context) *common.Controller { @@ -375,14 +352,11 @@ func (a *App) createBatchController(ctx context.Context) *common.Controller { a.kubeUtil.RadixClient(), ) - return batch.NewController( - ctx, + return batch.NewController(ctx, a.kubeUtil.KubeClient(), a.kubeUtil.RadixClient(), - handler, - a.kubeInformerFactory, + handler, a.kubeInformerFactory, a.radixInformerFactory, - true, a.eventRecorder) } @@ -393,8 +367,7 @@ func loadIngressConfigFromMap(ctx context.Context, kubeutil *kube.Kube) (ingress return ingressConfig, err } - err = yaml.Unmarshal([]byte(configMap.Data["ingressConfiguration"]), &ingressConfig) - if err != nil { + if err = yaml.Unmarshal([]byte(configMap.Data["ingressConfiguration"]), &ingressConfig); err != nil { return ingressConfig, err } return ingressConfig, nil diff --git a/radix-operator/registration/controller.go b/radix-operator/registration/controller.go index b6511d141..4400a13f5 100644 --- a/radix-operator/registration/controller.go +++ b/radix-operator/registration/controller.go @@ -27,26 +27,26 @@ const ( ) // NewController creates a new controller that handles RadixRegistrations -func NewController(ctx context.Context, client kubernetes.Interface, - radixClient radixclient.Interface, handler common.Handler, +func NewController(ctx context.Context, + client kubernetes.Interface, + radixClient radixclient.Interface, + handler common.Handler, kubeInformerFactory kubeinformers.SharedInformerFactory, radixInformerFactory informers.SharedInformerFactory, - waitForChildrenToSync bool, recorder record.EventRecorder) *common.Controller { logger := log.With().Str("controller", controllerAgentName).Logger() registrationInformer := radixInformerFactory.Radix().V1().RadixRegistrations() controller := &common.Controller{ - Name: controllerAgentName, - HandlerOf: crType, - KubeClient: client, - RadixClient: radixClient, - Informer: registrationInformer.Informer(), - KubeInformerFactory: kubeInformerFactory, - WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), - Handler: handler, - WaitForChildrenToSync: waitForChildrenToSync, - Recorder: recorder, - LockKeyAndIdentifier: common.NamePartitionKey, + Name: controllerAgentName, + HandlerOf: crType, + KubeClient: client, + RadixClient: radixClient, + KubeInformerFactory: kubeInformerFactory, + RadixInformerFactory: radixInformerFactory, + WorkQueue: common.NewRateLimitedWorkQueue(ctx, crType), + Handler: handler, + Recorder: recorder, + LockKeyAndIdentifier: common.NamePartitionKey, } logger.Info().Msg("Setting up event handlers") diff --git a/radix-operator/registration/controller_test.go b/radix-operator/registration/controller_test.go index 5986b884e..5d1e3298a 100644 --- a/radix-operator/registration/controller_test.go +++ b/radix-operator/registration/controller_test.go @@ -137,8 +137,7 @@ func startRegistrationController(ctx context.Context, client kubernetes.Interfac eventRecorder := &record.FakeRecorder{} - const waitForChildrenToSync = false - controller := NewController(ctx, client, radixClient, &handler, kubeInformerFactory, radixInformerFactory, waitForChildrenToSync, eventRecorder) + controller := NewController(ctx, client, radixClient, &handler, kubeInformerFactory, radixInformerFactory, eventRecorder) kubeInformerFactory.Start(ctx.Done()) radixInformerFactory.Start(ctx.Done())