Skip to content

Commit 2130565

Browse files
authored
feat: adds EnableCARM flag to prevent watching namespaces in ns scope (#199)
fixes aws-controllers-k8s/community#2625 Description of changes: - adds explicit EnableCARM flag to enable/disable Cross Account Resource Management By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 8a0f463 commit 2130565

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pkg/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
flagEnableAdoptedResourceReconciler = "enable-adopted-resource-reconciler"
4646
flagEnableFieldExportReconciler = "enable-field-export-reconciler"
4747
flagEnableLeaderElection = "enable-leader-election"
48+
flagEnableCARM = "enable-carm"
4849
flagLeaderElectionNamespace = "leader-election-namespace"
4950
flagMetricAddr = "metrics-addr"
5051
flagHealthzAddr = "healthz-addr"
@@ -89,6 +90,7 @@ type Config struct {
8990
EnableLeaderElection bool
9091
EnableAdoptedResourceReconciler bool
9192
EnableFieldExportReconciler bool
93+
EnableCARM bool
9294
LeaderElectionNamespace string
9395
EnableDevelopmentLogging bool
9496
AccountID string
@@ -151,6 +153,11 @@ func (cfg *Config) BindFlags() {
151153
true,
152154
"Enable the FieldExport reconciler.",
153155
)
156+
flag.BoolVar(
157+
&cfg.EnableCARM, flagEnableCARM,
158+
true,
159+
"Enable Cross Account Resource Management.",
160+
)
154161
flag.StringVar(
155162
// In the context of the controller-runtime library, if the LeaderElectionNamespace parametere is not
156163
// explicitly set, the library will automatically default its value to the content of the file

pkg/runtime/service_controller.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,9 @@ func (c *serviceController) BindControllerManager(mgr ctrlrt.Manager, cfg ackcfg
220220
}},
221221
cfg.FeatureGates,
222222
)
223-
// We want to run the caches if the length of the namespaces slice is
224-
// either 0 (watching all namespaces) or greater than 1 (watching multiple
225-
// namespaces).
226-
//
227-
// The caches are only used for cross account resource management. If the
228-
// controller is not configured to watch multiple namespaces, then we don't
229-
// need to run the caches.
230-
if len(namespaces) == 0 || len(namespaces) >= 2 {
223+
// The caches are only used for cross account resource management. We
224+
// want to run them only when --enable-carm is set to true.
225+
if cfg.EnableCARM {
231226
clusterConfig := mgr.GetConfig()
232227
clientSet, err := kubernetes.NewForConfig(clusterConfig)
233228
if err != nil {

pkg/runtime/service_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ func TestServiceController(t *testing.T) {
177177

178178
mgr := &fakeManager{}
179179
cfg := ackcfg.Config{
180-
// Disable caches, by setting a mono-namespace watch mode
181-
WatchNamespace: "default",
180+
// Disable caches, by setting EnableCARM to false
181+
EnableCARM: false,
182182
}
183183
err := sc.BindControllerManager(mgr, cfg)
184184
require.Nil(err)

0 commit comments

Comments
 (0)