From 2b4371dae44ad69a7cfe1c9ceaf3d668f15f1f3f Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Wed, 25 Nov 2026 12:18:31 +0300 Subject: [PATCH] fix(kubernetes): stop refusing extraOutputs hooks monitoring-agents accepts The tenant Kubernetes application refused fluent-bit extraOutputs unless an outputs override spelled the hook exactly as the default outputs do, matched by a regular expression over the template text. monitoring-agents decides the same question by rendering outputs, so a hook written with if, or a bare {{ .Values.config.extraOutputs }}, was refused by the application although the addon renders it. Keep a check in the application, because the addon fails in a HelmRelease the tenant cannot read, but reduce it to whether outputs mentions .Values.config.extraOutputs at all. That catches an override that drops the hook and is never stricter than the addon for a hook that names the value. It cannot be exact without executing the tenant template, which here would run it in the management cluster; a hook that is commented out or trims its newline is left to the addon's render guard, which already tests both. Fixes: 64fa40e255bd ("feat(monitoring): add destinations to the agents without replacing the defaults") Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- .../helmreleases/monitoring-agents.yaml | 14 ++--- .../tests/monitoring_agents_test.yaml | 59 +++++++------------ 2 files changed, 26 insertions(+), 47 deletions(-) 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'