mirror of
https://github.com/stakater/Reloader.git
synced 2026-08-23 22:16:45 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
c46937c5b0
commit
8f94e3051e
@@ -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")
|
||||
|
||||
@@ -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{},
|
||||
|
||||
Reference in New Issue
Block a user