Skip to content

Commit 2ab09c6

Browse files
authored
fix: force disable CARM when only one namespace is watched (#201)
fixes aws-controllers-k8s/community#2625 Description of changes: - force disables CARM when --watch-namespace has only one namespace even when "--enable-carm" is set to true. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2130565 commit 2ab09c6

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

pkg/runtime/service_controller.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,25 @@ func (c *serviceController) BindControllerManager(mgr ctrlrt.Manager, cfg ackcfg
221221
cfg.FeatureGates,
222222
)
223223
// The caches are only used for cross account resource management. We
224-
// want to run them only when --enable-carm is set to true.
224+
// want to run them only when --enable-carm is set to true and
225+
// --watch-namespace is set to zero or more than one namespaces.
225226
if cfg.EnableCARM {
226-
clusterConfig := mgr.GetConfig()
227-
clientSet, err := kubernetes.NewForConfig(clusterConfig)
228-
if err != nil {
229-
return err
227+
if len(namespaces) == 1 {
228+
c.log.V(0).Info("--enable-carm is set to true but --watch-namespace is set to a single namespace. CARM will not be enabled.")
229+
} else {
230+
clusterConfig := mgr.GetConfig()
231+
clientSet, err := kubernetes.NewForConfig(clusterConfig)
232+
if err != nil {
233+
return err
234+
}
235+
// Run the caches. This will not block as the caches are run in
236+
// separate goroutines.
237+
cache.Run(clientSet)
238+
// Wait for the caches to sync
239+
ctx := context.TODO()
240+
synced := cache.WaitForCachesToSync(ctx)
241+
c.log.Info("Waited for the caches to sync", "synced", synced)
230242
}
231-
// Run the caches. This will not block as the caches are run in
232-
// separate goroutines.
233-
cache.Run(clientSet)
234-
// Wait for the caches to sync
235-
ctx := context.TODO()
236-
synced := cache.WaitForCachesToSync(ctx)
237-
c.log.Info("Waited for the caches to sync", "synced", synced)
238243
}
239244

240245
if cfg.EnableAdoptedResourceReconciler {

0 commit comments

Comments
 (0)