Skip to content

Commit 000fda2

Browse files
authored
Merge pull request #1145 from yvjessestephens/fix/configmaps-resources-to-ignore-mismatch
fix: align --resources-to-ignore=configMaps with renamed ResourceMap key
2 parents b9718d5 + f12425e commit 000fda2

3 files changed

Lines changed: 107 additions & 7 deletions

File tree

deployments/kubernetes/chart/reloader/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ spec:
225225
- "--resources-to-ignore=secrets"
226226
{{- end }}
227227
{{- if .Values.reloader.ignoreConfigMaps }}
228-
- "--resources-to-ignore=configMaps"
228+
- "--resources-to-ignore=configmaps"
229229
{{- end }}
230230
{{- if and (.Values.reloader.ignoreJobs) (.Values.reloader.ignoreCronJobs) }}
231231
- "--ignored-workload-types=jobs,cronjobs"

internal/pkg/util/util.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func ConfigureReloaderFlags(cmd *cobra.Command) {
9494
cmd.PersistentFlags().StringVar(&options.LogFormat, "log-format", "", "Log format to use (empty string for text, or JSON)")
9595
cmd.PersistentFlags().StringVar(&options.LogLevel, "log-level", "info", "Log level to use (trace, debug, info, warning, error, fatal and panic)")
9696
cmd.PersistentFlags().StringVar(&options.WebhookUrl, "webhook-url", "", "webhook to trigger instead of performing a reload")
97-
cmd.PersistentFlags().StringSliceVar(&options.ResourcesToIgnore, "resources-to-ignore", options.ResourcesToIgnore, "list of resources to ignore (valid options 'configMaps' or 'secrets')")
97+
cmd.PersistentFlags().StringSliceVar(&options.ResourcesToIgnore, "resources-to-ignore", options.ResourcesToIgnore, "list of resources to ignore (valid options 'configmaps' or 'secrets')")
9898
cmd.PersistentFlags().StringSliceVar(&options.WorkloadTypesToIgnore, "ignored-workload-types", options.WorkloadTypesToIgnore, "list of workload types to ignore (valid options: 'jobs', 'cronjobs', or both)")
9999
cmd.PersistentFlags().StringSliceVar(&options.NamespacesToIgnore, "namespaces-to-ignore", options.NamespacesToIgnore, "list of namespaces to ignore")
100100
cmd.PersistentFlags().StringSliceVar(&options.NamespaceSelectors, "namespace-selector", options.NamespaceSelectors, "list of key:value labels to filter on for namespaces")
@@ -114,17 +114,26 @@ func GetIgnoredResourcesList() (List, error) {
114114

115115
ignoredResourcesList := options.ResourcesToIgnore // getStringSliceFromFlags(cmd, "resources-to-ignore")
116116

117+
// Normalize to the canonical lowercase keys used in kube.ResourceMap so the
118+
// comparison is case-insensitive (e.g. "configMaps", "ConfigMaps", "sEcrets"
119+
// all map to their canonical lowercase form).
120+
normalized := make(List, 0, len(ignoredResourcesList))
117121
for _, v := range ignoredResourcesList {
118-
if v != "configMaps" && v != "secrets" {
119-
return nil, fmt.Errorf("'resources-to-ignore' only accepts 'configMaps' or 'secrets', not '%s'", v)
122+
switch strings.ToLower(v) {
123+
case "configmaps":
124+
normalized = append(normalized, "configmaps")
125+
case "secrets":
126+
normalized = append(normalized, "secrets")
127+
default:
128+
return nil, fmt.Errorf("'resources-to-ignore' only accepts 'configmaps' or 'secrets', not '%s'", v)
120129
}
121130
}
122131

123-
if len(ignoredResourcesList) > 1 {
124-
return nil, errors.New("'resources-to-ignore' only accepts 'configMaps' or 'secrets', not both")
132+
if len(normalized) > 1 {
133+
return nil, errors.New("'resources-to-ignore' only accepts 'configmaps' or 'secrets', not both")
125134
}
126135

127-
return ignoredResourcesList, nil
136+
return normalized, nil
128137
}
129138

130139
func GetIgnoredWorkloadTypesList() (List, error) {

internal/pkg/util/util_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,97 @@ func TestGetIgnoredWorkloadTypesList(t *testing.T) {
136136
}
137137
}
138138

139+
func TestGetIgnoredResourcesList(t *testing.T) {
140+
// Save original state
141+
originalResources := options.ResourcesToIgnore
142+
defer func() {
143+
options.ResourcesToIgnore = originalResources
144+
}()
145+
146+
tests := []struct {
147+
name string
148+
resources []string
149+
expectError bool
150+
expected []string
151+
}{
152+
{
153+
name: "Lowercase configmaps (canonical) normalizes to configmaps",
154+
resources: []string{"configmaps"},
155+
expectError: false,
156+
expected: []string{"configmaps"},
157+
},
158+
{
159+
name: "Legacy camelCase configMaps normalizes to configmaps",
160+
resources: []string{"configMaps"},
161+
expectError: false,
162+
expected: []string{"configmaps"},
163+
},
164+
{
165+
name: "Mixed-case ConfigMaps normalizes to configmaps",
166+
resources: []string{"ConfigMaps"},
167+
expectError: false,
168+
expected: []string{"configmaps"},
169+
},
170+
{
171+
name: "secrets",
172+
resources: []string{"secrets"},
173+
expectError: false,
174+
expected: []string{"secrets"},
175+
},
176+
{
177+
name: "Mixed-case sEcrets normalizes to secrets",
178+
resources: []string{"sEcrets"},
179+
expectError: false,
180+
expected: []string{"secrets"},
181+
},
182+
{
183+
name: "Empty list",
184+
resources: []string{},
185+
expectError: false,
186+
expected: []string{},
187+
},
188+
{
189+
name: "Invalid resource",
190+
resources: []string{"deployments"},
191+
expectError: true,
192+
expected: nil,
193+
},
194+
{
195+
name: "Both configmaps and secrets rejected",
196+
resources: []string{"configmaps", "secrets"},
197+
expectError: true,
198+
expected: nil,
199+
},
200+
}
201+
202+
for _, tt := range tests {
203+
t.Run(tt.name, func(t *testing.T) {
204+
options.ResourcesToIgnore = tt.resources
205+
result, err := GetIgnoredResourcesList()
206+
207+
if tt.expectError && err == nil {
208+
t.Errorf("Expected error but got none")
209+
}
210+
if !tt.expectError && err != nil {
211+
t.Errorf("Expected no error but got: %v", err)
212+
}
213+
214+
if !tt.expectError {
215+
if len(result) != len(tt.expected) {
216+
t.Errorf("Expected %v, got %v", tt.expected, result)
217+
return
218+
}
219+
for i, expected := range tt.expected {
220+
if result[i] != expected {
221+
t.Errorf("Expected %v, got %v", tt.expected, result)
222+
break
223+
}
224+
}
225+
}
226+
})
227+
}
228+
}
229+
139230
func TestListContains(t *testing.T) {
140231
tests := []struct {
141232
name string

0 commit comments

Comments
 (0)