Skip to content

Commit 2c0c631

Browse files
a1exx-kclaude
andcommitted
feat(controller): add --configmap-name flag to override controller ConfigMap
The controller ConfigMap name was hardcoded to "argo-rollouts-config" with no way to override it. This adds a --configmap-name flag so operators can specify an alternative name, which is useful when running multiple controller instances in the same namespace or when the default name conflicts with existing resources. Signed-off-by: Alex Kazantcev <aleksandr.kazantcev@ticketmaster.co.uk> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 16d28f8 commit 2c0c631

5 files changed

Lines changed: 32 additions & 2 deletions

File tree

cmd/rollouts-controller/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func newCommand() *cobra.Command {
8888
selfServiceNotificationEnabled bool
8989
controllersEnabled []string
9090
pprofAddress string
91+
rolloutsConfigMapName string
9192
)
9293
electOpts := controller.NewLeaderElectionOptions()
9394
var command = cobra.Command{
@@ -119,6 +120,7 @@ func newCommand() *cobra.Command {
119120
defaults.SetAppMeshCRDVersion(appmeshCRDVersion)
120121
defaults.SetTraefikAPIGroup(traefikAPIGroup)
121122
defaults.SetTraefikVersion(traefikVersion)
123+
defaults.SetRolloutsConfigMapName(rolloutsConfigMapName)
122124

123125
config, err := clientConfig.ClientConfig()
124126
errors.CheckError(err)
@@ -340,6 +342,7 @@ func newCommand() *cobra.Command {
340342
command.Flags().BoolVar(&selfServiceNotificationEnabled, "self-service-notification-enabled", false, "Allows rollouts controller to pull notification config from the namespace that the rollout resource is in. This is useful for self-service notification.")
341343
command.Flags().StringSliceVar(&controllersEnabled, "controllers", nil, "Explicitly specify the list of controllers to run, currently only supports 'analysis', eg. --controller=analysis. Default: all controllers are enabled")
342344
command.Flags().StringVar(&pprofAddress, "enable-pprof-address", "", "Enable pprof profiling on controller by providing a server address.")
345+
command.Flags().StringVar(&rolloutsConfigMapName, "configmap-name", defaults.DefaultRolloutsConfigMapName, "Name of the ConfigMap used to configure the controller.")
343346
return &command
344347
}
345348

cmd/rollouts-controller/main_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/assert"
7+
8+
"github.com/argoproj/argo-rollouts/utils/defaults"
79
)
810

911
func TestMetricsPortFlagCompatibility(t *testing.T) {
@@ -19,3 +21,11 @@ func TestMetricsPortFlagCompatibility(t *testing.T) {
1921
// Test that deprecated flag is marked as deprecated
2022
assert.True(t, metricsportFlag.Deprecated != "", "metricsport flag should be marked as deprecated")
2123
}
24+
25+
func TestConfigMapNameFlag(t *testing.T) {
26+
cmd := newCommand()
27+
28+
configmapNameFlag := cmd.Flags().Lookup("configmap-name")
29+
assert.NotNil(t, configmapNameFlag, "configmap-name flag should exist")
30+
assert.Equal(t, defaults.DefaultRolloutsConfigMapName, configmapNameFlag.DefValue, "configmap-name flag should default to %s", defaults.DefaultRolloutsConfigMapName)
31+
}

controller/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func NewAnalysisManager(
233233
onlyAnalysisMode: true,
234234
}
235235

236-
_, err := rolloutsConfig.InitializeConfig(kubeclientset, defaults.DefaultRolloutsConfigMapName)
236+
_, err := rolloutsConfig.InitializeConfig(kubeclientset, defaults.GetRolloutsConfigMapName())
237237
if err != nil {
238238
log.Fatalf("Failed to init config: %v", err)
239239
}
@@ -443,7 +443,7 @@ func NewManager(
443443
notificationSecretInformerFactory: notificationSecretInformerFactory,
444444
}
445445

446-
_, err := rolloutsConfig.InitializeConfig(kubeclientset, defaults.DefaultRolloutsConfigMapName)
446+
_, err := rolloutsConfig.InitializeConfig(kubeclientset, defaults.GetRolloutsConfigMapName())
447447
if err != nil {
448448
log.Fatalf("Failed to init config: %v", err)
449449
}

utils/defaults/defaults.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var (
8080
appmeshCRDVersion = DefaultAppMeshCRDVersion
8181
defaultMetricCleanupDelay = DefaultMetricCleanupDelay
8282
defaultDescribeTagsLimit = DefaultDescribeTagsLimit
83+
rolloutsConfigMapName = DefaultRolloutsConfigMapName
8384
)
8485

8586
const (
@@ -366,3 +367,13 @@ func GetDescribeTagsLimit() int {
366367
func SetDescribeTagsLimit(limit int) {
367368
defaultDescribeTagsLimit = limit
368369
}
370+
371+
// SetRolloutsConfigMapName overrides the name of the ConfigMap used to configure the controller.
372+
func SetRolloutsConfigMapName(name string) {
373+
rolloutsConfigMapName = name
374+
}
375+
376+
// GetRolloutsConfigMapName returns the name of the ConfigMap used to configure the controller.
377+
func GetRolloutsConfigMapName() string {
378+
return rolloutsConfigMapName
379+
}

utils/defaults/defaults_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,10 @@ func TestSetDefaults(t *testing.T) {
429429
assert.Equal(t, DefaultDescribeTagsLimit, GetDescribeTagsLimit())
430430
SetDescribeTagsLimit(2)
431431
assert.Equal(t, 2, GetDescribeTagsLimit())
432+
433+
assert.Equal(t, DefaultRolloutsConfigMapName, GetRolloutsConfigMapName())
434+
SetRolloutsConfigMapName("my-custom-config")
435+
assert.Equal(t, "my-custom-config", GetRolloutsConfigMapName())
436+
SetRolloutsConfigMapName(DefaultRolloutsConfigMapName)
437+
assert.Equal(t, DefaultRolloutsConfigMapName, GetRolloutsConfigMapName())
432438
}

0 commit comments

Comments
 (0)