Skip to content

Commit 70f3783

Browse files
committed
fix: Controller not respecting ignore* flags
1 parent 177d275 commit 70f3783

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ spec:
210210
{{- . | toYaml | nindent 10 }}
211211
{{- end }}
212212
{{- end }}
213-
{{- if or (.Values.reloader.logFormat) (.Values.reloader.logLevel) (.Values.reloader.ignoreSecrets) (.Values.reloader.ignoreNamespaces) (include "reloader-namespaceSelector" .) (.Values.reloader.resourceLabelSelector) (.Values.reloader.ignoreConfigMaps) (.Values.reloader.custom_annotations) (eq .Values.reloader.isArgoRollouts true) (eq .Values.reloader.reloadOnCreate true) (eq .Values.reloader.reloadOnDelete true) (ne .Values.reloader.reloadStrategy "default") (.Values.reloader.enableHA) (.Values.reloader.autoReloadAll)}}
213+
{{- if or (.Values.reloader.logFormat) (.Values.reloader.logLevel) (.Values.reloader.ignoreSecrets) (.Values.reloader.ignoreNamespaces) (include "reloader-namespaceSelector" .) (.Values.reloader.resourceLabelSelector) (.Values.reloader.ignoreConfigMaps) (.Values.reloader.custom_annotations) (eq .Values.reloader.isArgoRollouts true) (eq .Values.reloader.reloadOnCreate true) (eq .Values.reloader.reloadOnDelete true) (ne .Values.reloader.reloadStrategy "default") (.Values.reloader.enableHA) (.Values.reloader.autoReloadAll) (.Values.reloader.ignoreJobs) (.Values.reloader.ignoreCronJobs)}}
214214
args:
215215
{{- if .Values.reloader.logFormat }}
216216
- "--log-format={{ .Values.reloader.logFormat }}"
@@ -224,6 +224,13 @@ spec:
224224
{{- if .Values.reloader.ignoreConfigMaps }}
225225
- "--resources-to-ignore=configMaps"
226226
{{- end }}
227+
{{- if and (.Values.reloader.ignoreJobs) (.Values.reloader.ignoreCronJobs) }}
228+
- "--ignored-workload-types=jobs,cronjobs"
229+
{{- else if .Values.reloader.ignoreJobs }}
230+
- "--ignored-workload-types=jobs"
231+
{{- else if .Values.reloader.ignoreCronJobs }}
232+
- "--ignored-workload-types=cronjobs"
233+
{{- end }}
227234
{{- if .Values.reloader.ignoreNamespaces }}
228235
- "--namespaces-to-ignore={{ .Values.reloader.ignoreNamespaces }}"
229236
{{- end }}

internal/pkg/handler/upgrade.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,33 @@ func sendWebhook(url string) (string, []error) {
172172
func doRollingUpgrade(config common.Config, collectors metrics.Collectors, recorder record.EventRecorder, invoke invokeStrategy) error {
173173
clients := kube.GetClients()
174174

175-
err := rollingUpgrade(clients, config, GetDeploymentRollingUpgradeFuncs(), collectors, recorder, invoke)
175+
// Get the list of ignored workload types
176+
ignoredWorkloadTypes, err := util.GetIgnoredWorkloadTypesList()
176177
if err != nil {
177178
return err
178179
}
179-
err = rollingUpgrade(clients, config, GetCronJobCreateJobFuncs(), collectors, recorder, invoke)
180+
181+
err = rollingUpgrade(clients, config, GetDeploymentRollingUpgradeFuncs(), collectors, recorder, invoke)
180182
if err != nil {
181183
return err
182184
}
183-
err = rollingUpgrade(clients, config, GetJobCreateJobFuncs(), collectors, recorder, invoke)
184-
if err != nil {
185-
return err
185+
186+
// Only process CronJobs if not in ignored workload types
187+
if !ignoredWorkloadTypes.Contains("cronjobs") {
188+
err = rollingUpgrade(clients, config, GetCronJobCreateJobFuncs(), collectors, recorder, invoke)
189+
if err != nil {
190+
return err
191+
}
192+
}
193+
194+
// Only process Jobs if not in ignored workload types
195+
if !ignoredWorkloadTypes.Contains("jobs") {
196+
err = rollingUpgrade(clients, config, GetJobCreateJobFuncs(), collectors, recorder, invoke)
197+
if err != nil {
198+
return err
199+
}
186200
}
201+
187202
err = rollingUpgrade(clients, config, GetDaemonSetRollingUpgradeFuncs(), collectors, recorder, invoke)
188203
if err != nil {
189204
return err

internal/pkg/handler/upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4267,7 +4267,7 @@ func TestGetContainerUsingResourceWithArgoRolloutEmptyContainers(t *testing.T) {
42674267
// Use proper Argo Rollout object instead of Pod
42684268
mockRollout := MockArgoRolloutWithEmptyContainers(namespace, "test-rollout")
42694269

4270-
config := util.Config{
4270+
config := common.Config{
42714271
Namespace: namespace,
42724272
ResourceName: resourceName,
42734273
Type: constants.ConfigmapEnvVarPostfix,

internal/pkg/options/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ var (
6565
WebhookUrl = ""
6666
// ResourcesToIgnore is a list of resources to ignore when watching for changes
6767
ResourcesToIgnore = []string{}
68+
// WorkloadTypesToIgnore is a list of workload types to ignore when watching for changes
69+
WorkloadTypesToIgnore = []string{}
6870
// NamespacesToIgnore is a list of namespace names to ignore when watching for changes
6971
NamespacesToIgnore = []string{}
7072
// NamespaceSelectors is a list of namespace selectors to watch for changes

internal/pkg/util/util.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func ConfigureReloaderFlags(cmd *cobra.Command) {
8383
cmd.PersistentFlags().StringVar(&options.LogLevel, "log-level", "info", "Log level to use (trace, debug, info, warning, error, fatal and panic)")
8484
cmd.PersistentFlags().StringVar(&options.WebhookUrl, "webhook-url", "", "webhook to trigger instead of performing a reload")
8585
cmd.PersistentFlags().StringSliceVar(&options.ResourcesToIgnore, "resources-to-ignore", options.ResourcesToIgnore, "list of resources to ignore (valid options 'configMaps' or 'secrets')")
86+
cmd.PersistentFlags().StringSliceVar(&options.WorkloadTypesToIgnore, "ignored-workload-types", options.WorkloadTypesToIgnore, "list of workload types to ignore (valid options: 'jobs', 'cronjobs', or both)")
8687
cmd.PersistentFlags().StringSliceVar(&options.NamespacesToIgnore, "namespaces-to-ignore", options.NamespacesToIgnore, "list of namespaces to ignore")
8788
cmd.PersistentFlags().StringSliceVar(&options.NamespaceSelectors, "namespace-selector", options.NamespaceSelectors, "list of key:value labels to filter on for namespaces")
8889
cmd.PersistentFlags().StringSliceVar(&options.ResourceSelectors, "resource-label-selector", options.ResourceSelectors, "list of key:value labels to filter on for configmaps and secrets")
@@ -112,3 +113,16 @@ func GetIgnoredResourcesList() (List, error) {
112113

113114
return ignoredResourcesList, nil
114115
}
116+
117+
func GetIgnoredWorkloadTypesList() (List, error) {
118+
119+
ignoredWorkloadTypesList := options.WorkloadTypesToIgnore
120+
121+
for _, v := range ignoredWorkloadTypesList {
122+
if v != "jobs" && v != "cronjobs" {
123+
return nil, fmt.Errorf("'ignored-workload-types' only accepts 'jobs' and/or 'cronjobs', not '%s'", v)
124+
}
125+
}
126+
127+
return ignoredWorkloadTypesList, nil
128+
}

pkg/common/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type ReloaderOptions struct {
7474
WebhookUrl string `json:"webhookUrl"`
7575
// ResourcesToIgnore is a list of resource types to ignore (e.g., "configmaps" or "secrets")
7676
ResourcesToIgnore []string `json:"resourcesToIgnore"`
77+
// WorkloadTypesToIgnore is a list of workload types to ignore (e.g., "jobs" or "cronjobs")
78+
WorkloadTypesToIgnore []string `json:"workloadTypesToIgnore"`
7779
// NamespaceSelectors is a list of label selectors to filter namespaces to watch
7880
NamespaceSelectors []string `json:"namespaceSelectors"`
7981
// ResourceSelectors is a list of label selectors to filter ConfigMaps and Secrets to watch
@@ -304,6 +306,7 @@ func GetCommandLineOptions() *ReloaderOptions {
304306
CommandLineOptions.EnableHA = options.EnableHA
305307
CommandLineOptions.WebhookUrl = options.WebhookUrl
306308
CommandLineOptions.ResourcesToIgnore = options.ResourcesToIgnore
309+
CommandLineOptions.WorkloadTypesToIgnore = options.WorkloadTypesToIgnore
307310
CommandLineOptions.NamespaceSelectors = options.NamespaceSelectors
308311
CommandLineOptions.ResourceSelectors = options.ResourceSelectors
309312
CommandLineOptions.NamespacesToIgnore = options.NamespacesToIgnore

0 commit comments

Comments
 (0)