fix(kubernetes): stop refusing extraOutputs hooks monitoring-agents accepts (#5427)

## What this PR does

The tenant Kubernetes application checked fluent-bit `extraOutputs` with
a regular expression over the text of an `outputs` override, written
against the exact layout of the default hook. The monitoring-agents
chart decides the same question by rendering `outputs`, so a hook
written with `{{- if .Values.config.extraOutputs }}` / `{{
.Values.config.extraOutputs }}` / `{{- end }}`, or a bare `{{
.Values.config.extraOutputs }}`, was refused by the application although
monitoring-agents renders it into `fluent-bit.conf`. I confirmed this
with `helm template` on both charts.

I kept a check in the application, because the addon fails in a
HelmRelease the tenant cannot read and the Application status reflects
only its own release. It now only requires `outputs` to mention
`.Values.config.extraOutputs`. The check stays textual because executing
a tenant template in this chart would run it in the management cluster,
and the exact check is already made by the monitoring-agents render
guard.

A new test covers the `if` form. The application tests for a
commented-out or newline-trimming hook are removed, since only the
monitoring-agents guard catches those now, and it already has tests for
both.

Follow-up to #5376.

### Screenshots

Not a UI change.

### Downstream repositories

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

### Release note

```release-note
fix(kubernetes): an `addons.monitoringAgents.valuesOverride` that overrides fluent-bit `outputs` and emits `extraOutputs` with an `if` block or a bare `{{ .Values.config.extraOutputs }}` is no longer refused by the application.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Monitoring-agent output configuration now accepts a wider range of
template formats when including extra destinations, including
conditional hooks. Validation still requires the configuration to
reference the extra destinations setting.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-11-25 19:51:54 +03:00
commit 7067313c95
2 files changed
+26 -47

No files matched your search

@@ -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
@@ -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'