Repository navigation
build(chart): use the FOCA library chart - #176
Conversation
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]>
Reviewer's GuideThis PR converts the deployment chart into a thin, pinned wrapper over FOCA’s Sequence diagram for external MongoDB renderingsequenceDiagram
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
Sequence diagram for release packaging of the library chartsequenceDiagram
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
Flow diagram for chart rendering and dependency verificationflowchart 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
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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]>
Summary
The Helm chart in
deployment/is now a thin chart over FOCA's library chartfoca-common0.1.0 (oci://ghcr.io/elixir-cloud-aai/charts, pinned inChart.yaml, locked inChart.lock). This way all FOCA apps share one chart implementation.includeof a library template, using the app's settings incloud-registry.settings:valuesKey: cloudRegistrymaxContentLength: 1048576requireAudience: truemongodb.databases: [serviceStore]mongodb.accessControlDatabase: serviceStorecustom.endpoints.service, generated fromhostName(HTTPS, port 443)configmap.yaml,deployment.yaml,mongodb-*.yaml, ...).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 requiredhostName. 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_namewithouthostName. The legacy-release check, which looks up resources in the cluster, runs once, in the ConfigMap template.checksum/configannotation is unchanged, so upgrades don't roll the pods.mongodb.enabled: an external MongoDB. Rendering fails withoutconfig.db.host.cloudRegistry.imagePullPolicyandmongodb.imagePullPolicy: defaultAlways, as before.mongodb.image.values.schema.jsonis the library'sapp-values.schema.jsonwith thecloudRegistrykey (which also requiresgunicornandpreStopSleepSeconds, as before), the minor-version MongoDB pin, and no Celery worker or broker. A test compares the schema against the library's.helm dependency build deployment(the test jobs use the runners' preinstalled Helm).deployment/charts.sha256, because OCI tags can be pushed again.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.mddescribes 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: updateChart.yaml,Chart.lock,charts.sha256, the schema, the values and the README links.Closes #158
Verification
pytestwith 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.hostNameconfig.security: nullpre-commit run --all-files(ruff, mypy, semgrep, gitleaks, actionlint, ast-grep) and the gitleaks-all hook: passed.mkdocs build --strict: passed.0.3.0rc1): it packages the library (0.1.0), the README check passes, and the package renders.require_adminis parsed as the app parses booleans, and null fails; group mappings that aren't maps fail; the docs cover thereadWriterole on a changed access-control database). 2 threads were answered as not applicable: the packaged dependency is expanded byhelm package, and the body limit followsconfig.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
includein every template (quality, low). This is the library's documented call pattern, the same as in its petstore example.requireAdminsetting in foca-common could be a later FOCA change, if other apps need it.yq '.dependencies[0].version'assumes a single dependency (quality, low). The tests make the same assumption, so a second dependency fails loudly.helm dependency build;docs/development.mddocuments the bump.require_adminaccepts (quality, low). The error message names the valid values, and feat!: make auth and group config generic #166 rewrites that README paragraph.require_admintests (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:
Bug Fixes:
Enhancements:
Build:
CI:
Documentation:
Tests: