Skip to content

build(chart): use the FOCA library chart - #176

Merged
uniqueg merged 5 commits into
devfrom
build/chart-foca-common
Oct 22, 2026
Merged

uniqueg merged 5 commits into
devfrom
build/chart-foca-common

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

The Helm chart in deployment/ is now a thin chart over FOCA's library chart foca-common 0.1.0 (oci://ghcr.io/elixir-cloud-aai/charts, pinned in Chart.yaml, locked in Chart.lock). This way all FOCA apps share one chart implementation.

  • Templates: each template is one include of a library template, using the app's settings in cloud-registry.settings:
    • valuesKey: cloudRegistry
    • maxContentLength: 1048576
    • requireAudience: true
    • mongodb.databases: [serviceStore]
    • mongodb.accessControlDatabase: serviceStore
    • custom.endpoints.service, generated from hostName (HTTPS, port 443)
  • Template names: the file names follow the library's petstore example (configmap.yaml, deployment.yaml, mongodb-*.yaml, ...).
  • App-specific checks kept (cloud-registry.validate): renamed keys (host_name, cloud_registry), removed keys (appName, config.custom.max_content_length, config.custom.endpoints.service_info), the admin mapping, and the required hostName. These run from the settings, so in every template, before the library's checks. As a result, the renamed and removed values are reported first, e.g., host_name without hostName. The legacy-release check, which looks up resources in the cluster, runs once, in the ConfigMap template.
  • Rendered output: unchanged for the documented values. I compared the parsed manifests by kind and name for the default, no-auth, OpenShift and a production-like set of values. The adversarial reviewer compared about 30 combinations. The only difference is a comment in the MongoDB init script; the checksum/config annotation is unchanged, so upgrades don't roll the pods.
  • Values: no key was renamed or removed, and the defaults are the same. The library adds new values:
    • mongodb.enabled: an external MongoDB. Rendering fails without config.db.host.
    • cloudRegistry.imagePullPolicy and mongodb.imagePullPolicy: default Always, as before.
    • The library also requires mongodb.image.
  • Schema: values.schema.json is the library's app-values.schema.json with the cloudRegistry key (which also requires gunicorn and preStopSleepSeconds, as before), the minor-version MongoDB pin, and no Celery worker or broker. A test compares the schema against the library's.
  • CI and release:
    • All jobs that render the chart run helm dependency build deployment (the test jobs use the runners' preinstalled Helm).
    • They check the downloaded archive against deployment/charts.sha256, because OCI tags can be pushed again.
    • The release checks that the package contains the locked library version.
  • Chart README links (issue update): the links to the library's docs point to its tag, chart-v0.1.0, which a test checks. Links to this repository's docs and files were already versioned when packaging (ci: version links in the packaged chart #161). The README also has new sections: an intro, "External MongoDB" (with a warning that disabling the bundled MongoDB of an installed release deletes its volume), and the pull policy. docs/development.md describes the dependency and how to bump it. The 0.3.0 release notes have new entries.

Note for later: foca-common 0.2.0 (Gateway API, foca#397) is not released yet, so this PR uses 0.1.0. Bump it as described in "Versioning and releases" in docs/development.md: update Chart.yaml, Chart.lock, charts.sha256, the schema, the values and the README links.

Closes #158

Verification

  • pytest with coverage (Python 3.13, Helm v3.22.1, mongomock): 919 passed before the last fix commit, at 100% coverage. After it, tests/test_chart.py tests/test_config.py: 175 passed.
  • New tests (written first; they failed against the old chart):
    • the library dependency, lock and digest
    • the schema against the library's
    • the packaged library
    • an external MongoDB, with and without authentication, and without a host
    • the required MongoDB image
    • the pull policies
    • the access-control database in the init script
    • renamed keys without hostName
    • config.security: null
    • the README's FOCA links
  • pre-commit run --all-files (ruff, mypy, semgrep, gitleaks, actionlint, ast-grep) and the gitleaks-all hook: passed.
  • mkdocs build --strict: passed.
  • I simulated the release's "Package chart" step locally (0.3.0rc1): it packages the library (0.1.0), the README check passes, and the package renders.
  • CI: all checks passed (tests with mongomock and MongoDB 7.0, Helm chart, Docker Compose, static analysis, docs, CodeQL, codecov patch and project, Read the Docs), also after the fixes for Sourcery's review (37756e0).
  • Sourcery review: 4 threads fixed in 37756e0 (require_admin is parsed as the app parses booleans, and null fails; group mappings that aren't maps fail; the docs cover the readWrite role on a changed access-control database). 2 threads were answered as not applicable: the packaged dependency is expanded by helm package, and the body limit follows config.server.max_content_length. The reviewers checked these fixes too, and their findings were fixed (empty non-map mappings, a shared boolean parser, the command for granting the role as a code block, more test cases).

Declined review findings

  • Avoid repeating the settings include in every template (quality, low). This is the library's documented call pattern, the same as in its petstore example.
  • Move the admin-mapping check into the library (quality, low). It is an app-level check for now. A requireAdmin setting in foca-common could be a later FOCA change, if other apps need it.
  • The Co-Authored-By trailer (quality, low). The trailer is the one this session requires.
  • yq '.dependencies[0].version' assumes a single dependency (quality, low). The tests make the same assumption, so a second dependency fails loudly.
  • Repeated digest check in four workflow steps (quality, low). It sits next to each helm dependency build; docs/development.md documents the bump.
  • Wrap the long "Versioning and releases" link line in the README (quality, low). Link lines are unwrapped throughout the file.
  • Say in the README which values require_admin accepts (quality, low). The error message names the valid values, and feat!: make auth and group config generic #166 rewrites that README paragraph.
  • Check the rendered output in the require_admin tests (quality, low). The only effect of the setting is whether rendering fails, which is what the tests check.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Use FOCA's shared foca-common library chart to simplify and standardize the Helm chart while retaining application-specific behavior and adding external MongoDB support.

New Features:

  • Add support for deploying with an external MongoDB and configurable application and MongoDB image pull policies.

Bug Fixes:

  • Preserve application-specific Helm validation, including legacy upgrade protection and clearer validation for renamed, removed, and invalid settings.

Enhancements:

  • Adopt FOCA's foca-common library chart for shared Kubernetes resource templates while preserving the existing rendered resources and values.
  • Align the chart schema and templates with the pinned library version and include the library in packaged releases for offline installation.

Build:

  • Pin and lock the foca-common OCI chart dependency and verify its downloaded archive with a checksum.

CI:

  • Build and checksum Helm dependencies in chart test and release workflows, and verify the packaged chart contains the locked library version.

Documentation:

  • Document the library chart dependency, external MongoDB configuration, image pull policies, access-control database setup, and dependency upgrade process.
  • Update the 0.3.0 release notes with the chart library migration and new MongoDB options.

Tests:

  • Add coverage for the library dependency, schema alignment, packaged chart contents, external MongoDB, pull policies, validation, and README links.

uniqueg and others added 3 commits October 22, 2026 22:43
Turn the chart into a thin chart over foca-common 0.1.0 (OCI, pinned in
Chart.yaml, locked in Chart.lock): the templates include the library's
resources with the app's settings (values key cloudRegistry, body size
limit, audience required, databases, access control database and the
public URL from hostName). The app keeps its own checks (renamed and
removed keys, legacy releases, admin mapping); the library adds an
external MongoDB (mongodb.enabled), image pull policies and the checks
of an external MongoDB's host and the MongoDB image.

The rendered resources are unchanged for the documented values, except
for a comment of the init script. Values keep their keys and defaults.

CI and the release build the dependency; the release checks that the
package contains the locked library version. The chart README's links
to FOCA point to the library's tag, checked by a test.

Closes #158

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run the app's checks in every template, before the library's, so that
renamed and removed values are reported first (e.g., host_name without
hostName). Pin the digest of the library archive and check it in CI and
on release, as OCI tags can be pushed again. Warn that disabling the
bundled MongoDB of an installed release deletes its volume. Test the
values schema against the library's, an external MongoDB without
authentication and a clear error without built dependencies; tidy the
docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run the legacy release check, which looks up resources in the cluster,
once (in the ConfigMap template) instead of in every template, and
report the missing admin mapping instead of a template error for
config.security: null. Parametrize the renamed keys test and fix the
wording of the release notes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR converts the deployment chart into a thin, pinned wrapper over FOCA’s foca-common library chart, retaining app-specific validation and upgrade safeguards while delegating resource rendering, adding external MongoDB and library-derived configuration behavior, and enforcing dependency integrity through schema/tests, CI, and release packaging.

Sequence diagram for external MongoDB rendering

sequenceDiagram
    participant Helm
    participant Chart as cloud-registry chart
    participant Library as foca-common
    participant Cluster as Kubernetes

    Helm->>Chart: Render with mongodb.enabled=false
    Chart->>Chart: cloud-registry.validate
    Chart->>Chart: required config.db.host
    Chart->>Library: foca-common.configMap
    Chart->>Library: foca-common.deployment
    Library->>Cluster: Render app resources
    Library-->>Helm: Omit MongoDB resources
Loading

Sequence diagram for release packaging of the library chart

sequenceDiagram
    participant Release as Release workflow
    participant Registry as OCI chart registry
    participant Package as Helm package

    Release->>Registry: helm dependency build deployment
    Registry-->>Release: foca-common-0.1.0.tgz
    Release->>Release: sha256sum -c charts.sha256
    Release->>Package: helm package deployment
    Package-->>Release: Chart includes foca-common
    Release->>Release: Compare packaged library version with Chart.lock
Loading

Flow diagram for chart rendering and dependency verification

flowchart TD
    Start[Helm chart render or test] --> Build[helm dependency build deployment]
    Build --> Digest[sha256sum -c charts.sha256]
    Digest --> Templates[Thin wrapper templates]
    Templates --> Validate[cloud-registry.validate]
    Validate --> Settings[cloud-registry.settings]
    Settings --> Library[foca-common resource template]
    Library --> Manifests[Rendered manifests]
    ConfigMap[configmap.yaml] --> Upgrade[cloud-registry.checkUpgrade]
    Upgrade --> Templates
Loading

File-Level Changes

Change Details Files
Replaces the app-owned Helm resource implementations with thin wrappers around the pinned FOCA foca-common library chart.
  • Adds the OCI dependency at version 0.1.0 and locks it with a verified archive digest.
  • Renames templates to the library convention and delegates rendering through foca-common includes.
  • Passes app-specific settings for values, request limits, audience validation, MongoDB databases, and the generated service endpoint.
  • Retains app validation and legacy-release upgrade protection, with app checks executed before library checks and legacy lookup performed once.
deployment/Chart.yaml
deployment/Chart.lock
deployment/charts.sha256
deployment/templates/_helpers.tpl
deployment/templates/configmap.yaml
deployment/templates/deployment.yaml
deployment/templates/ingress.yaml
deployment/templates/mongodb-deployment.yaml
deployment/templates/mongodb-init-script.yaml
deployment/templates/mongodb-networkpolicy.yaml
deployment/templates/mongodb-pvc.yaml
deployment/templates/mongodb-service.yaml
deployment/templates/networkpolicy.yaml
deployment/templates/route.yaml
deployment/templates/service.yaml
deployment/templates/NOTES.txt
deployment/.helmignore
Aligns chart values, validation schema, documentation, and release notes with the library chart while preserving the existing public values and rendered behavior.
  • Adds external MongoDB support with required config.db.host validation and documents migration and volume-deletion risks.
  • Adds app and MongoDB image pull policies, requiring the MongoDB image and preserving Always defaults.
  • Derives the schema from the library schema with the app-specific cloudRegistry, MongoDB, and worker/broker adjustments.
  • Documents the library dependency, dependency bump procedure, versioned library links, installation requirements, and new chart behavior.
deployment/values.yaml
deployment/values.schema.json
deployment/README.md
docs/development.md
docs/releases/0.3.0.md
Makes dependency availability and integrity part of chart testing and release packaging.
  • Builds Helm dependencies before chart tests and linting, then verifies the downloaded archive against charts.sha256.
  • Verifies release packages contain the locked library version so charts install without repository access.
  • Fails local chart rendering with a clear message when the dependency has not been built.
.github/workflows/checks.yaml
.github/workflows/release.yaml
tests/helm.py
Expands automated coverage for dependency integration and newly delegated chart behavior.
  • Checks dependency metadata, lockfile consistency, archive digest, packaged contents, and schema parity with the library.
  • Covers external MongoDB modes, required host and image validation, pull policies, access-control database initialization, null security configuration, and validation ordering.
  • Checks that FOCA documentation links in the chart README target the pinned library tag.
tests/test_chart.py
tests/test_chart_readme.py

Assessment against linked issues

Issue Objective Addressed Explanation
#158 Make deployment/ a thin chart using a pinned FOCA library-chart dependency while preserving the existing values structure, rendered resources, and legacy-key validation checks. ✅
#158 Update chart documentation and 0.3.0 release notes, and ensure CI and release workflows build, verify, and package the library dependency. ✅
#158 Make packaged chart README links to FOCA documentation specific to the pinned library release, and verify those links with a test. ✅

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

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (19c461b) to head (9a65bcc).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #176   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        11           
  Lines          737       737           
=========================================
  Hits           737       737           

☔ 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.

@uniqueg
uniqueg marked this pull request as ready for review October 22, 2026 21:34

@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 6 issues

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

## Individual Comments

### Comment 1
<location path="tests/test_chart.py" line_range="268-269" />
<code_context>
+    lock = yaml.safe_load((CHART / "Chart.lock").read_text())
+    (library,) = lock["dependencies"]
+    with tarfile.open(tmp_path / "cloud-registry-0.0.0.tgz") as package:
+        member = package.extractfile("cloud-registry/charts/foca-common/Chart.yaml")
+        assert member is not None
+        packaged = yaml.safe_load(member.read())
+    assert (packaged["name"], packaged["version"]) == (
</code_context>
<issue_to_address>
**Packaged dependency check fails**

When the chart has been built with `helm dependency build` and then packaged, `helm package` stores the dependency as `charts/foca-common-0.1.0.tgz`, not as an expanded `charts/foca-common/` directory. The test’s `extractfile` returns `None` and fails its assertion; the release step’s `tar` likewise fails, so chart tests and releases cannot complete.

Extract `Chart.yaml` from the nested `foca-common-*.tgz` in the package, or otherwise check the dependency’s actual packaged archive path.

Also at `.github/workflows/release.yaml:142-143`.
</issue_to_address>

### Comment 2
<location path="deployment/templates/_helpers.tpl" line_range="84-85" />
<code_context>
-*/}}
-{{- define "cloud-registry.name" -}}
-{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
-{{- end -}}
-
-{{/*
</code_context>
<issue_to_address>
**Invalid null config reaches startup**

When `config.custom.access_control.require_admin` is null and no group maps to `admin`, `cloud-registry.validate` assigns null to `$requireAdmin`, so the admin-mapping check is skipped. The app’s `AccessControlConfig.require_admin` rejects null, leaving the pods unable to start.

Validate `require_admin` as a non-nullable boolean before using it to skip the admin-mapping check.
</issue_to_address>

### Comment 3
<location path="deployment/templates/_helpers.tpl" line_range="23" />
<code_context>
+requireAudience: true
+mongodb:
+  databases: [serviceStore]
+  accessControlDatabase: serviceStore
+config:
+  custom:
</code_context>
<issue_to_address>
**Policy database writes are denied**

When `config.security.access_control.db_name` differs from `serviceStore` and the bundled MongoDB is already initialized, or an external MongoDB user is provisioned as documented, the app user lacks `readWrite` on the configured access-control database, so MongoDB rejects policy operations. The bundled init script only creates users for an empty data directory, and the external-MongoDB instructions grant access only to `serviceStore`.

Ensure the app user has `readWrite` on the configured access-control database for bundled and external MongoDB, and document that requirement.

Also at `deployment/README.md:756-757`.
</issue_to_address>

### Comment 4
<location path="deployment/templates/_helpers.tpl" line_range="19" />
<code_context>
+{{- define "cloud-registry.settings" -}}
+{{- include "cloud-registry.validate" . -}}
+valuesKey: cloudRegistry
+maxContentLength: 1048576
+requireAudience: true
+mongodb:
</code_context>
<issue_to_address>
**Custom body limit ignored by Ingress**

When `config.server.max_content_length` is set above 1048576 and ingress-nginx handles the Ingress, `foca-common.ingress` receives the fixed 1 MiB `maxContentLength` instead of the configured `config.server.max_content_length`, so ingress-nginx rejects requests larger than 1 MiB even when the app is configured to accept them.

Derive `maxContentLength` from `config.server.max_content_length`, retaining the 1 MiB default and existing validation.
</issue_to_address>

### Comment 5
<location path="deployment/templates/_helpers.tpl" line_range="83-85" />
<code_context>
+{{- end -}}
+{{- $requireAdmin := true -}}
+{{- if kindIs "map" $custom -}}
+{{- $requireAdmin = dig "access_control" "require_admin" true $custom -}}
+{{- end -}}
+{{- if and $requireAdmin (not (has "admin" (values $mapping))) -}}
+{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.custom.access_control.require_admin to false" -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Quoted false blocks rendering**

When a values file quotes `config.custom.access_control.require_admin` as `"false"` and provides no admin group mapping, `dig` returns the string `"false"` unchanged, and Helm treats that nonempty string as true in the following condition. With no admin group mapping, rendering fails even though the app’s Pydantic `require_admin: bool` accepts the string as false and allows the deployment.

Normalize this setting using the same boolean parsing as the app before checking it, or reject non-boolean values explicitly and consistently with the app’s accepted config types.
</issue_to_address>

### Comment 6
<location path="deployment/templates/_helpers.tpl" line_range="86" />
<code_context>
+{{- $requireAdmin = dig "access_control" "require_admin" true $custom -}}
+{{- end -}}
+{{- if and $requireAdmin (not (has "admin" (values $mapping))) -}}
+{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.custom.access_control.require_admin to false" -}}
+{{- end -}}
+{{- $_ := required "hostName must be set" .Values.hostName -}}
</code_context>
<issue_to_address>
**Malformed admin mapping gives opaque error**

When `config.security.access_control.group_mapping` is set to a non-map value, `values $mapping` receives a non-map when `config.security.access_control.group_mapping` is a scalar or list, so Helm aborts with a template type error instead of the intended admin-mapping validation message.

Check that the mapping is a map before calling `values`, and fail with a clear validation message otherwise.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and setting mongodb.enabled: false removes the bundled MongoDB and its PVC, so an upgrade without first migrating or retaining the volume can permanently delete the database contents; reverting the chart cannot restore them. The library also changes how MongoDB resources and app-user database roles are rendered, so those production behaviors need careful verification.

Blocking findings: tests/test_chart.py:269, deployment/templates/_helpers.tpl:85, deployment/templates/_helpers.tpl:23, deployment/templates/_helpers.tpl:19, deployment/templates/_helpers.tpl:85


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

Comment thread tests/test_chart.py Resolved
Comment thread deployment/templates/_helpers.tpl Resolved
Comment thread deployment/templates/_helpers.tpl Resolved
Comment thread deployment/templates/_helpers.tpl Resolved
Comment thread deployment/templates/_helpers.tpl Resolved
Comment thread deployment/templates/_helpers.tpl Resolved
uniqueg and others added 2 commits October 23, 2026 00:20
Parse config.custom.access_control.require_admin as pydantic parses
booleans, as the app does (e.g., "false"), and fail on other values,
such as null. Reject group mappings that aren't maps with a clear
error. Document the readWrite role that the app user needs on a changed
access-control database, for installed releases and external MongoDB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 7c2ef8a into dev Oct 22, 2026
13 checks passed
@uniqueg
uniqueg deleted the build/chart-foca-common branch October 22, 2026 22:32
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.

build(chart): use the FOCA library chart

1 participant