Skip to content

Commit

Permalink
factory: configReloaderExtraArgs adds sorting
Browse files Browse the repository at this point in the history
* previously extraArgs for config-reloader container was not sorted
 it triggers pod recreation on each reconcile loop. Since golang map produces random
 key result with range iteration
* this commit adds sorting for args if configReloaderArgs defined and not empty

follow-up after 6f35883

Signed-off-by: f41gh7 <[email protected]>
  • Loading branch information
f41gh7 committed Aug 26, 2024
1 parent 73dad51 commit b081eb0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ aliases:
- [operator](https://docs.victoriametrics.com/operator/): fixes statefulset `rollingUpdate` strategyType readiness check.
- [operator](https://docs.victoriametrics.com/operator/): fixes statefulset reconcile endless loop bug introduced at v0.47.1 version with [commit](https://github.com/VictoriaMetrics/operator/commit/57b65771b29ffd8b5d577e160aacddf0481295ee).
- [vmuser](https://docs.victoriametrics.com/operator/resources/vmuser/): fixes `crd.kind` enum param for `VMAlertmanager`, it now supports both `VMAlertmanager` and `VMAlertManager`. See this [issue](https://github.com/VictoriaMetrics/operator/issues/1083) for details.
- [operator](https://docs.victoriametrics.com/operator/): adds sorting for `configReloaderExtraArgs`.

## [v0.47.1](https://github.com/VictoriaMetrics/operator/releases/tag/v0.47.1) - 23 Aug 2024

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ func buildVMAlertmanagerConfigReloader(cr *vmv1beta1.VMAlertmanager, c *config.B
for k, v := range cr.Spec.ConfigReloaderExtraArgs {
configReloaderArgs = append(configReloaderArgs, fmt.Sprintf(`--%s=%s`, k, v))
}
sort.Strings(configReloaderArgs)
}

configReloaderContainer := corev1.Container{
Expand Down
1 change: 1 addition & 0 deletions internal/controller/operator/factory/vmagent/vmagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ func buildConfigReloaderArgs(cr *vmv1beta1.VMAgent, c *config.BaseOperatorConf)
for k, v := range cr.Spec.ConfigReloaderExtraArgs {
args = append(args, fmt.Sprintf(`--%s=%s`, k, v))
}
sort.Strings(args)
}

return args
Expand Down
14 changes: 12 additions & 2 deletions internal/controller/operator/factory/vmalert/vmalert.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,18 @@ func vmAlertSpecGen(cr *vmv1beta1.VMAlert, c *config.BaseOperatorConf, ruleConfi
for _, cm := range ruleConfigMapNames {
confReloadArgs = append(confReloadArgs, fmt.Sprintf("-volume-dir=%s", path.Join(vmAlertConfigDir, cm)))
}
for k, v := range cr.Spec.ConfigReloaderExtraArgs {
confReloadArgs = append(confReloadArgs, fmt.Sprintf(`--%s=%s`, k, v))
if len(cr.Spec.ConfigReloaderExtraArgs) > 0 {
for idx, arg := range confReloadArgs {
cleanArg := strings.Split(strings.TrimLeft(arg, "-"), "=")[0]
if replacement, ok := cr.Spec.ConfigReloaderExtraArgs[cleanArg]; ok {
delete(cr.Spec.ConfigReloaderExtraArgs, cleanArg)
confReloadArgs[idx] = fmt.Sprintf(`--%s=%s`, cleanArg, replacement)
}
}
for k, v := range cr.Spec.ConfigReloaderExtraArgs {
confReloadArgs = append(confReloadArgs, fmt.Sprintf(`--%s=%s`, k, v))
}
sort.Strings(confReloadArgs)
}

args := buildVMAlertArgs(cr, ruleConfigMapNames, remoteSecrets)
Expand Down
1 change: 1 addition & 0 deletions internal/controller/operator/factory/vmauth/vmauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ func buildVMAuthConfigReloaderContainer(cr *vmv1beta1.VMAuth, c *config.BaseOper
for k, v := range cr.Spec.ConfigReloaderExtraArgs {
configReloaderArgs = append(configReloaderArgs, fmt.Sprintf(`--%s=%s`, k, v))
}
sort.Strings(configReloaderArgs)
}
configReloader := corev1.Container{
Name: "config-reloader",
Expand Down

0 comments on commit b081eb0

Please sign in to comment.