diff --git a/packages/apps/kubernetes/templates/helmreleases/monitoring-agents.yaml b/packages/apps/kubernetes/templates/helmreleases/monitoring-agents.yaml index f51ef297f..76037f10a 100644 --- a/packages/apps/kubernetes/templates/helmreleases/monitoring-agents.yaml +++ b/packages/apps/kubernetes/templates/helmreleases/monitoring-agents.yaml @@ -70,18 +70,12 @@ fluent-bit: {{- if .Values.addons.monitoringAgents.enabled }} {{- $values := deepCopy .Values.addons.monitoringAgents.valuesOverride | mergeOverwrite (fromYaml (include "cozystack.defaultMonitoringAgentsValues" .)) }} {{- /* - The monitoring-agents chart refuses the same combination by rendering - outputs, but only once the HelmRelease reconciles inside the tenant - cluster. That render needs the subchart's context, which this chart does - not have, so the check here is textual: a with on extraOutputs whose - closing braces keep the newline, followed by {{ . }} on a line of its own. - A hook that is only mentioned, commented out or compacted fails here and - is reported on the application itself; anything subtler still fails in - the tenant cluster. + Coarse on purpose: monitoring-agents renders outputs and checks it exactly, + but executing a tenant template here would run it in the management cluster. */}} {{- $fluentBitConfig := (index $values "fluent-bit").config | default dict }} -{{- if and $fluentBitConfig.extraOutputs (not (regexMatch "\\{\\{-?\\s*with\\s+\\.Values\\.config\\.extraOutputs\\s*\\}\\}[ \\t]*\\n[ \\t]*\\{\\{\\s*\\.\\s*-?\\}\\}" ($fluentBitConfig.outputs | default ""))) }} -{{- fail "addons.monitoringAgents.valuesOverride sets fluent-bit.config.extraOutputs but overrides fluent-bit.config.outputs without a hook that emits it on a line of its own, so the extra destinations would be dropped. Keep the hook from the default outputs at the end of yours, each part on a line of its own: {{- with .Values.config.extraOutputs }}, then {{ . }}, then {{- end }}. Or move the destinations into outputs and unset extraOutputs." }} +{{- if and $fluentBitConfig.extraOutputs (not (contains ".Values.config.extraOutputs" ($fluentBitConfig.outputs | default ""))) }} +{{- fail "addons.monitoringAgents.valuesOverride sets fluent-bit.config.extraOutputs but overrides fluent-bit.config.outputs without a hook that emits it, so the extra destinations would be dropped. Keep the hook from the default outputs at the end of yours, each part on a line of its own: {{- with .Values.config.extraOutputs }}, then {{ . }}, then {{- end }}. Or move the destinations into outputs and unset extraOutputs." }} {{- end }} apiVersion: helm.toolkit.fluxcd.io/v2 kind: HelmRelease diff --git a/packages/apps/kubernetes/tests/monitoring_agents_test.yaml b/packages/apps/kubernetes/tests/monitoring_agents_test.yaml index 6d2b45383..b220a8070 100644 --- a/packages/apps/kubernetes/tests/monitoring_agents_test.yaml +++ b/packages/apps/kubernetes/tests/monitoring_agents_test.yaml @@ -124,43 +124,7 @@ tests: Host logs-b.example.org asserts: - failedTemplate: - errorPattern: 'overrides fluent-bit\.config\.outputs without a hook that emits it on a line of its own' - - - it: refuses extraOutputs when the hook in an outputs override is commented out - set: - addons.monitoringAgents.valuesOverride: - fluent-bit: - config: - outputs: | - [OUTPUT] - Name http - Host logs-a.example.org - {{/* .Values.config.extraOutputs */}} - extraOutputs: | - [OUTPUT] - Name http - Host logs-b.example.org - asserts: - - failedTemplate: - errorPattern: 'without a hook that emits it on a line of its own' - - - it: refuses extraOutputs when the hook in an outputs override trims the newline - set: - addons.monitoringAgents.valuesOverride: - fluent-bit: - config: - outputs: | - [OUTPUT] - Name http - Host logs-a.example.org - {{- with .Values.config.extraOutputs }}{{ . }}{{- end }} - extraOutputs: | - [OUTPUT] - Name http - Host logs-b.example.org - asserts: - - failedTemplate: - errorPattern: 'without a hook that emits it on a line of its own' + errorPattern: 'overrides fluent-bit\.config\.outputs without a hook that emits it' - it: passes both destinations through when valuesOverride replaces outputs and keeps the hook set: @@ -185,3 +149,24 @@ tests: - matchRegex: path: spec.values.fluent-bit.config.extraOutputs pattern: 'Host logs-b\.example\.org' + + - it: accepts an outputs override whose hook emits extraOutputs through if + set: + addons.monitoringAgents.valuesOverride: + fluent-bit: + config: + outputs: | + [OUTPUT] + Name http + Host logs-a.example.org + {{- if .Values.config.extraOutputs }} + {{ .Values.config.extraOutputs }} + {{- end }} + extraOutputs: | + [OUTPUT] + Name http + Host logs-b.example.org + asserts: + - matchRegex: + path: spec.values.fluent-bit.config.extraOutputs + pattern: 'Host logs-b\.example\.org'