From 985607b08cef948dfb628d29b30fe96c526a0160 Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Fri, 24 May 2024 09:03:15 +0200 Subject: [PATCH] if list of controllers only contains disabled controllers, implicitly enable all default controllers Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- cmd/controller/app/options/options.go | 5 +++++ cmd/controller/app/options/options_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/cmd/controller/app/options/options.go b/cmd/controller/app/options/options.go index 9a6d1e159..4798b2472 100644 --- a/cmd/controller/app/options/options.go +++ b/cmd/controller/app/options/options.go @@ -243,6 +243,11 @@ func EnabledControllers(o *config.ControllerConfiguration) sets.Set[string] { } } + // Detect if "*" was implied (in case only disabled controllers were specified) + if len(disabled) > 0 && len(enabled) == 0 { + enabled = enabled.Insert(defaults.DefaultEnabledControllers...) + } + enabled = enabled.Delete(disabled...) if utilfeature.DefaultFeatureGate.Enabled(feature.ExperimentalCertificateSigningRequestControllers) { diff --git a/cmd/controller/app/options/options_test.go b/cmd/controller/app/options/options_test.go index 8c86f308c..99256498e 100644 --- a/cmd/controller/app/options/options_test.go +++ b/cmd/controller/app/options/options_test.go @@ -50,6 +50,14 @@ func TestEnabledControllers(t *testing.T) { controllers: []string{"*", "-clusterissuers", "-issuers"}, expEnabled: sets.New(defaults.DefaultEnabledControllers...).Delete("clusterissuers", "issuers"), }, + "if only disabled controllers are specified, implicitly enable all default controllers": { + controllers: []string{"-clusterissuers", "-issuers"}, + expEnabled: sets.New(defaults.DefaultEnabledControllers...).Delete("clusterissuers", "issuers"), + }, + "if both enabled and disabled controllers are specified, return specified controllers": { + controllers: []string{"foo", "-bar"}, + expEnabled: sets.New("foo"), + }, } for name, test := range tests {