From 8f94e3051eb2d108e5cc852a64bd90443c8d79d9 Mon Sep 17 00:00:00 2001 From: Jesse Stephens Date: Fri, 12 Jun 2026 08:29:56 -0500 Subject: [PATCH] refactor: case-insensitive normalization for resources-to-ignore Use strings.ToLower so any casing (configMaps, ConfigMaps, sEcrets) normalizes to the canonical lowercase ResourceMap key, and simplify the flag help text. Addresses PR review feedback. Co-Authored-By: Claude Opus 4.8 (1M context) --- internal/pkg/util/util.go | 12 ++++++------ internal/pkg/util/util_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index 8e057baa..e6c3eff2 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -93,7 +93,7 @@ func ConfigureReloaderFlags(cmd *cobra.Command) { cmd.PersistentFlags().StringVar(&options.LogFormat, "log-format", "", "Log format to use (empty string for text, or JSON)") cmd.PersistentFlags().StringVar(&options.LogLevel, "log-level", "info", "Log level to use (trace, debug, info, warning, error, fatal and panic)") cmd.PersistentFlags().StringVar(&options.WebhookUrl, "webhook-url", "", "webhook to trigger instead of performing a reload") - cmd.PersistentFlags().StringSliceVar(&options.ResourcesToIgnore, "resources-to-ignore", options.ResourcesToIgnore, "list of resources to ignore (valid options 'configmaps' or 'secrets'; 'configMaps' is also accepted for backward compatibility)") + cmd.PersistentFlags().StringSliceVar(&options.ResourcesToIgnore, "resources-to-ignore", options.ResourcesToIgnore, "list of resources to ignore (valid options 'configmaps' or 'secrets')") cmd.PersistentFlags().StringSliceVar(&options.WorkloadTypesToIgnore, "ignored-workload-types", options.WorkloadTypesToIgnore, "list of workload types to ignore (valid options: 'jobs', 'cronjobs', or both)") cmd.PersistentFlags().StringSliceVar(&options.NamespacesToIgnore, "namespaces-to-ignore", options.NamespacesToIgnore, "list of namespaces to ignore") cmd.PersistentFlags().StringSliceVar(&options.NamespaceSelectors, "namespace-selector", options.NamespaceSelectors, "list of key:value labels to filter on for namespaces") @@ -113,13 +113,13 @@ func GetIgnoredResourcesList() (List, error) { ignoredResourcesList := options.ResourcesToIgnore // getStringSliceFromFlags(cmd, "resources-to-ignore") - // Normalize to the canonical lowercase keys used in kube.ResourceMap. - // Accept the legacy "configMaps" spelling for backward compatibility with - // charts that still emit the camelCase form. + // Normalize to the canonical lowercase keys used in kube.ResourceMap so the + // comparison is case-insensitive (e.g. "configMaps", "ConfigMaps", "sEcrets" + // all map to their canonical lowercase form). normalized := make(List, 0, len(ignoredResourcesList)) for _, v := range ignoredResourcesList { - switch v { - case "configMaps", "configmaps": + switch strings.ToLower(v) { + case "configmaps": normalized = append(normalized, "configmaps") case "secrets": normalized = append(normalized, "secrets") diff --git a/internal/pkg/util/util_test.go b/internal/pkg/util/util_test.go index 7399e4b3..31c82c41 100644 --- a/internal/pkg/util/util_test.go +++ b/internal/pkg/util/util_test.go @@ -161,12 +161,24 @@ func TestGetIgnoredResourcesList(t *testing.T) { expectError: false, expected: []string{"configmaps"}, }, + { + name: "Mixed-case ConfigMaps normalizes to configmaps", + resources: []string{"ConfigMaps"}, + expectError: false, + expected: []string{"configmaps"}, + }, { name: "secrets", resources: []string{"secrets"}, expectError: false, expected: []string{"secrets"}, }, + { + name: "Mixed-case sEcrets normalizes to secrets", + resources: []string{"sEcrets"}, + expectError: false, + expected: []string{"secrets"}, + }, { name: "Empty list", resources: []string{},