Skip to content

Commit

Permalink
fix validation in resource prefix flag
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviassss committed Oct 24, 2024
1 parent 96e66f6 commit 8261a45
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
11 changes: 0 additions & 11 deletions pkg/config/controller_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
fs.StringToStringVar(&cfg.ResourcePrefix, flagResourcePrefix, defaultResourcePrefix,
"the prefixes for resource tags, backend SG name and worker node SG rules label.")

cfg.mergeDefaultResourcePrefixVal()
cfg.FeatureGates.BindFlags(fs)
cfg.AWSConfig.BindFlags(fs)
cfg.RuntimeConfig.BindFlags(fs)
Expand Down Expand Up @@ -268,13 +267,3 @@ func (cfg *ControllerConfig) validateResourcePrefixKeys() error {
}
return nil
}

// mergeDefaultResourcePrefixVal make sure the ResourcePrefix map always has default val for unspecified key in user-passed flag
func (cfg *ControllerConfig) mergeDefaultResourcePrefixVal() {
// Merge user-provided values with defaults
for key, defaultVal := range defaultResourcePrefix {
if _, exists := cfg.ResourcePrefix[key]; !exists {
cfg.ResourcePrefix[key] = defaultVal
}
}
}
2 changes: 1 addition & 1 deletion pkg/config/controller_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func TestControllerConfig_validateResourcePrefixKeys(t *testing.T) {
"backendSGNamePrefix": "k8s-traffic",
},
},
wantErr: errors.New("invalid number of keys. Expected 5 keys, but got 4 keys"),
wantErr: errors.New("invalid number of keys. Expected 5 keys, only got 4 keys"),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 8261a45

Please sign in to comment.