Skip to content

feat(chart): add extraEnv and rollout on secrets - #672

Merged
uniqueg merged 7 commits into
devfrom
feat/626-chart-extra-env
Nov 4, 2026
Merged

uniqueg merged 7 commits into
devfrom
feat/626-chart-extra-env

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

foca-common 0.5.0:

  • <valuesKey>.extraEnv, extraEnvFrom and rolloutOnSecrets, for the app and worker containers, not for the bundled broker or MongoDB.
  • Rendering fails if extraEnv sets a variable that the chart sets (FOCA_CONFIG_OVERLAY, PORT, and GUNICORN_CMD_ARGS, MONGO_USERNAME, MONGO_PASSWORD, CELERY_BROKER_URL, CELERY_RESULT_BACKEND, FOCA_PLUGINS_STORE_KEY_SECRET if the chart's settings for them are in use).
  • Beyond the issue, as the chart already refuses the key secret in the overlay: rendering fails on secrets as literal values in extraEnv (MONGO_PASSWORD, FOCA_PLUGINS_STORE_KEY_SECRET, and MONGO_URI or CELERY_* with credentials), and on wrong types for app charts without the schema.
  • rolloutOnSecrets: a checksum of the data of the named Secrets becomes the annotation checksum/secrets, via lookup; nothing in helm template and Argo CD, without an error. Documented, with Stakater Reloader as the alternative, with no dependency on it.
  • Schema, petstore example, docs (docs/helm-chart.md, including what older app charts need).

Closes #626

Verification

  • pytest charts/foca-common/tests with Helm 3.22.1 (not necessarily the CI version; CI runs the snapshots with its own), helm lint --strict: pass.
  • ruff check, ruff format --check, mypy, mkdocs build --strict: pass.
  • The kind install couldn't run locally (no kind): the new CI step "Check rollout annotation" in Chart install is the only real test of lookup; see the checks of this PR.
  • Both reviewer subagents, then a second adversarial round (no high or medium findings in round 2).

Declined review findings

  • CI step changing a Secret and asserting that the annotation changes: more machinery than a checksum of the data needs; the presence is checked on the app and the worker.
  • A helper for the blocks shared by the app's and the worker's Deployments: the templates keep them side by side, and their tests compare them.
  • {"name": "A", "value": 1}: the API server rejects non-string values at install.

🤖 Generated with Claude Code

Summary by Sourcery

Extend the common Helm chart with safe custom environment configuration and optional Secret-triggered rollouts for application and worker pods.

New Features:

  • Add configurable extra environment variables and environment sources for application and worker containers.
  • Add optional Secret-based pod rollouts by annotating application and worker Deployments with checksums of named Secret data.

Bug Fixes:

  • Prevent chart-managed environment variables from being overridden and reject literal Secret credentials in extra environment configuration.

Enhancements:

  • Add value schemas and rendering validation for the new environment and Secret rollout settings.

Build:

  • Bump the foca-common chart to version 0.5.0 and update example chart dependencies.

CI:

  • Verify rollout annotations are present on the application and worker Deployments during chart installation.

Documentation:

  • Document extra environment configuration, Secret handling, rollout behavior, Helm lookup limitations, and compatibility requirements for older app charts.

Tests:

  • Add template coverage for extra environment settings, validation failures, Secret handling, and rollout behavior.

uniqueg and others added 3 commits November 4, 2026 04:48
Operators can't inject settings from their own Secrets or ConfigMaps,
such as MONGO_URI, and pods don't restart when a Secret they read
changes. Add extraEnv, extraEnvFrom and rolloutOnSecrets to the app's
values, for the app and the worker. Rendering fails if extraEnv sets a
variable that the chart sets. foca-common 0.5.0.

Closes #626

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fail if extraEnv has a secret as a literal value, as the chart does for
the key secret in the overlay, or sets a name twice. Check the types of
the new values for app charts without the schema. Check the annotation
in CI for the app and the worker. Docs: the MONGO_URI example needs
config.db.host; the annotation is an unsalted hash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The chart's Service and probes expect port 8080, and foca.gunicorn_config
reads PORT.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.21.0 milestone Nov 4, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR releases foca-common 0.5.0 with validated extraEnv/extraEnvFrom support for app and worker containers and optional Secret-based rollout checksums, backed by schema/template tests, installation-time CI verification, updated examples, and documentation.

Sequence diagram for Secret checksum rollout during Helm upgrade

sequenceDiagram
    actor User
    participant Helm
    participant Kubernetes
    participant AppDeployment
    participant WorkerDeployment

    User->>Helm: helm upgrade
    Helm->>Kubernetes: lookup Secret data
    Kubernetes-->>Helm: Secret data or not found
    Helm->>Helm: sha256sum rolloutOnSecrets data
    Helm->>Kubernetes: apply Deployments with checksum/secrets
    Kubernetes->>AppDeployment: roll out pods when annotation changes
    Kubernetes->>WorkerDeployment: roll out pods when annotation changes
Loading

Flow diagram for validated extra environment configuration

flowchart TD
    Start["Read extraEnv and extraEnvFrom"] --> Types{"Valid list types?"}
    Types -- No --> Fail["Rendering fails"]
    Types -- Yes --> EnvChecks["Check duplicate, reserved, and literal secret values"]
    EnvChecks --> Safe{"Validation passes?"}
    Safe -- No --> Fail
    Safe -- Yes --> Render["Render env and envFrom"]
    Render --> Targets["App and worker containers"]
Loading

File-Level Changes

Change Details Files
Add configurable environment variables and environment sources to application and worker containers with render-time safety validation.
  • Render extraEnv and extraEnvFrom only for app and worker containers.
  • Reject malformed values, duplicate names, chart-owned variables, and literal secret credentials.
  • Add schema coverage and tests for valid, invalid, and schema-less chart configurations.
charts/foca-common/templates/_helpers.tpl
charts/foca-common/templates/_deployment.tpl
charts/foca-common/templates/_worker.tpl
charts/foca-common/app-values.schema.json
examples/petstore/chart/values.schema.json
charts/foca-common/tests/test_templates.py
Add optional Secret-driven pod rollout annotations using Helm lookup.
  • Hash the data of found Secrets listed in rolloutOnSecrets into checksum/secrets.
  • Apply the annotation to app and worker Deployments while remaining inert for helm template and Argo CD.
  • Document permissions, missing-Secret behavior, hash considerations, and Stakater Reloader as an alternative.
  • Verify annotations during the CI chart installation.
charts/foca-common/templates/_helpers.tpl
charts/foca-common/templates/_deployment.tpl
charts/foca-common/templates/_worker.tpl
.github/actions/install-chart/action.yml
charts/foca-common/tests/test_templates.py
docs/helm-chart.md
examples/petstore/chart/ci/celery-values.yaml
examples/petstore/chart/values.yaml
Publish the common chart as version 0.5.0 and update bundled example chart dependencies and configuration.
  • Bump the library chart and example dependency lock versions.
  • Expose and document the new values in the petstore example.
  • Expand Helm chart guidance, including compatibility requirements for older app charts.
charts/foca-common/Chart.yaml
examples/gateway/chart/Chart.yaml
examples/gateway/chart/Chart.lock
examples/petstore/chart/Chart.yaml
examples/petstore/chart/Chart.lock
examples/petstore/chart/values.yaml
docs/helm-chart.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@uniqueg
uniqueg marked this pull request as ready for review November 4, 2026 04:43
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e5b2fb1) to head (ee93e59).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #672   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         7231      7231           
=========================================
  Hits          7231      7231           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="charts/foca-common/templates/_helpers.tpl" line_range="353" />
<code_context>
+{{- end -}}
+{{- end -}}
+{{- if $data -}}
+{{- toJson $data | sha256sum -}}
+{{- end -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Weak secrets become guessable**

When a listed Secret contains a weak value and a cluster reader can read Deployments, `rolloutChecksum` hashes all listed Secret data without a key, then exposes that digest in `checksum/secrets`; the reader can test guesses offline and recover the weak value.

Use a keyed MAC with a separately protected key, or avoid the annotation and use a Secret-watching controller.
</issue_to_address>

### Comment 2
<location path="charts/foca-common/templates/_deployment.tpl" line_range="79" />
<code_context>
+        {{- . | nindent 8 }}
+        {{- end }}
+        {{- with include "foca-common.extraEnvFrom" . }}
+        envFrom:
+        {{- . | nindent 8 }}
+        {{- end }}
</code_context>
<issue_to_address>
**EnvFrom can override the app port**

When an `extraEnvFrom` Secret or ConfigMap contains `PORT` with a value other than `8080` and the app uses `foca.gunicorn_config`, the chart does not set `PORT` in `env`, so `extraEnvFrom` can supply it despite `extraEnv` rejecting it. `foca.gunicorn_config` then binds to that port (or fails on an invalid value), while the Service and probes remain fixed at 8080, leaving the app unavailable.

Set `PORT` explicitly to `8080` in the app container’s `env` so it takes precedence over `envFrom`.
</issue_to_address>

### Comment 3
<location path="charts/foca-common/templates/_helpers.tpl" line_range="347" />
<code_context>
+{{- if not (and (kindIs "string" .) .) -}}
+{{- fail (printf "%s.rolloutOnSecrets must be a list of names of Secrets" $key) -}}
+{{- end -}}
+{{- $secret := lookup "v1" "Secret" $root.Release.Namespace . -}}
+{{- if $secret -}}
+{{- $_ := set $data . $secret.data -}}
</code_context>
<issue_to_address>
**Pods keep stale Secret values**

When a listed Secret is created or updated by the release, or changes after `lookup` reads it but before the upgrade completes, `lookup` reads the current cluster Secret, and `rolloutChecksum` hashes that snapshot rather than the Secret data ultimately applied; on first install the data can also be absent. The checksum therefore misses the change and existing pods keep using stale Secret-derived values.

Use a rollout mechanism that reacts to the Secret data actually applied or changed, rather than relying solely on the pre-apply `lookup` snapshot.
</issue_to_address>

### Comment 4
<location path="charts/foca-common/templates/_helpers.tpl" line_range="246" />
<code_context>
+{{- define "foca-common.extraEnv" -}}
+{{- $key := .settings.valuesKey -}}
+{{- $values := index .root.Values $key -}}
+{{- $extraEnv := $values.extraEnv | default list -}}
+{{- if not (kindIs "slice" $extraEnv) -}}
+{{- fail (printf "%s.extraEnv must be a list of EnvVar" $key) -}}
</code_context>
<issue_to_address>
**Invalid settings are ignored**

When a schema-less app chart sets `extraEnv`, `extraEnvFrom`, or `rolloutOnSecrets` to `false`, `0`, an empty string, or an empty map, `default list` converts these values to an empty list before the type checks in the helpers run, so the checks pass and the invalid setting is silently ignored.

Validate each setting's type before applying `default list`.

Also at `charts/foca-common/templates/_helpers.tpl:293`, `charts/foca-common/templates/_helpers.tpl:338`.
</issue_to_address>

Linked issues

#626 feat(chart): add extraEnv and rollout on secrets · 5 of 6 met · 1 to check by hand

# Requirement Status Notes
1 Add extraEnv, extraEnvFrom, and rolloutOnSecrets for the app and worker containers, not the bundled broker or MongoDB. ✅ Met Both Deployment templates use the new helpers for their app/worker containers.
2 Fail rendering when extraEnv sets variables the chart owns, when the relevant chart settings are in use. ✅ Met The reserved-name helper checks the chart-owned variables, including the conditional MongoDB, broker, plugin-store, and Gunicorn variables.
3 Use lookup for rolloutOnSecrets and document that helm template and Argo CD do not read Secrets, with Stakater Reloader as an alternative and no dependency on it. ✅ Met The checksum helper uses lookup; the documentation describes its behavior and the Reloader alternative.
4 Add the schema, petstore example, documentation, and migration notes. ✅ Met The schema and example values are updated, and the docs explain that older app charts need the updated app-values schema to use the new settings.
5 Test app and worker environment lists, reserved-name failures, and rolloutOnSecrets rendering with helm template. ✅ Met Template tests cover both Deployments, reserved variables, and rendering without a Secret lookup result.
6 Pass helm lint, chart unit tests, and the kind install. 👀 Check by hand (runtime) Confirm the PR's CI run passes the chart install check; the description says the local kind install could not run.

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and when a listed Secret changes, Helm puts an unsalted hash of its data in the Deployment annotation; anyone who can read Deployments can test guesses against that hash, potentially exposing weak secret values. Reverting removes the annotation going forward, but cannot undo guesses or disclosure that already occurred.

Blocking findings: charts/foca-common/templates/_helpers.tpl:353, charts/foca-common/templates/_deployment.tpl:79, charts/foca-common/templates/_helpers.tpl:347, charts/foca-common/templates/_helpers.tpl:246


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

uniqueg and others added 4 commits November 4, 2026 05:59
extraEnvFrom could set PORT, which the Service and probes fix at 8080,
so set it in the app container. Wrong types such as false or {} were
ignored without the schema, as `default list` replaced them before
the type checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 78a18c9 into dev Nov 4, 2026
56 checks passed
@uniqueg
uniqueg deleted the feat/626-chart-extra-env branch November 4, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(chart): add extraEnv and rollout on secrets

1 participant