Repository navigation
feat(chart): add app replicas and a PDB - #585
Conversation
The library chart foca-common rendered the app's Deployment with a fixed single replica. `<valuesKey>.replicas` (1 if not set, named like `worker.replicas`) now sets the number of pods, and the new template `foca-common.podDisruptionBudget` renders a PodDisruptionBudget with more than one replica (`<valuesKey>.podDisruptionBudget`: `enabled`, true if not set, and `minAvailable` or `maxUnavailable`, 1 if neither is set). Adds the values to the schema and the petstore example, template and snapshot tests, documents several replicas and their caveats, and raises the chart's version to 0.3.0. Closes #584 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The kind installation of ci/access-control-values.yaml now runs two replicas, which store the configured policies of access control at the same time on startup, and gets a PodDisruptionBudget. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Validate replicas and podDisruptionBudget.enabled also without the schema, limit percentages to 100%, move the replicas helper to _helpers.tpl, correct why one replica gets no budget, name caches per worker process, add upgrade steps for app charts and a pointer in docs/deployment.md, and split the tests of missing values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fail with the chart's message if podDisruptionBudget is not a map, and treat a null podDisruptionBudget.enabled as not set (true). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR upgrades foca-common to 0.3.0 with configurable application replicas and a validated, multi-replica-only PodDisruptionBudget, while preserving backward-compatible single-pod behavior. It wires the feature through library and petstore schemas/templates, adds extensive rendering and legacy-schema tests plus a two-replica kind scenario, and documents operational caveats and upgrade guidance. Flow diagram for replica-aware chart renderingflowchart TD
V[App values] --> R[foca-common.replicas]
R --> D[Deployment replicas]
V --> P[foca-common.podDisruptionBudget]
R --> P
P -->|replicas greater than 1 and enabled| B[PodDisruptionBudget]
P -->|one replica or disabled| N[No PodDisruptionBudget]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Name the release as "before foca-common 0.3.0", which the guard of hard-coded versions allows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #585 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 56 56
Lines 7068 7068
=========================================
Hits 7068 7068
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charts/foca-common/templates/_poddisruptionbudget.tpl" line_range="32" />
<code_context>
+{{- if and $hasMin $hasMax -}}
+{{- fail (printf "%s.podDisruptionBudget: set either minAvailable or maxUnavailable, not both" $key) -}}
+{{- end }}
+apiVersion: policy/v1
+kind: PodDisruptionBudget
+metadata:
</code_context>
<issue_to_address>
**Older clusters reject the budget**
When a release with more than one replica is installed or upgraded on Kubernetes earlier than 1.21, the template emits `policy/v1`, which the API server does not serve on those clusters, so it rejects the PodDisruptionBudget and the Helm install or upgrade fails.
Render a PodDisruptionBudget API version supported by the cluster, or omit the resource when none is supported.
</issue_to_address>
### Comment 2
<location path="charts/foca-common/templates/_poddisruptionbudget.tpl" line_range="41-42" />
<code_context>
+spec:
+ {{- if $hasMin }}
+ minAvailable: {{ toJson $budget.minAvailable }}
+ {{- else if $hasMax }}
+ maxUnavailable: {{ toJson $budget.maxUnavailable }}
+ {{- else }}
+ maxUnavailable: 1
</code_context>
<issue_to_address>
**Invalid budget bounds reach Kubernetes**
When a schema-less app chart sets a bound to an invalid value such as `maxUnavailable=half`, the template checks that only one bound is set but does not validate its type or percentage format; `toJson` emits an invalid bound into the PDB, so Kubernetes rejects the resource and the install or upgrade fails.
Validate each present bound’s type, non-negative numeric value, or percentage format in the template when schema validation is absent.
</issue_to_address>
### Comment 3
<location path="charts/foca-common/templates/_poddisruptionbudget.tpl" line_range="20" />
<code_context>
+{{- end -}}
+{{- $enabled := $budget.enabled -}}
+{{- if kindIs "invalid" $enabled -}}
+{{- $enabled = true -}}
+{{- end -}}
+{{- if not (kindIs "bool" $enabled) -}}
</code_context>
<issue_to_address>
**Null setting fails schema validation**
When `podDisruptionBudget.enabled` is explicitly null and Helm coalescing preserves that value, the values schema requires `podDisruptionBudget.enabled` to be a boolean, so Helm rejects the null before this defaulting runs; rendering or upgrade fails instead of treating null as unset.
Allow null in the schema for `enabled`, or remove the template's null-as-unset behavior and document null as invalid.
</issue_to_address>
### Comment 4
<location path="charts/foca-common/templates/_poddisruptionbudget.tpl" line_range="14" />
<code_context>
+{{- include "foca-common.checkSettings" . -}}
+{{- $root := .root -}}
+{{- $key := .settings.valuesKey -}}
+{{- $budget := (index $root.Values $key).podDisruptionBudget | default dict -}}
+{{- if not (kindIs "map" $budget) -}}
+{{- fail (printf "%s.podDisruptionBudget must be a map" $key) -}}
</code_context>
<issue_to_address>
**Invalid budgets render as enabled**
When a schema-less or permissive chart passes a falsey non-map `podDisruptionBudget` value to the template, `default dict` replaces the value with an empty map before the `kindIs` check, so `$enabled` defaults to true and the template renders a default PodDisruptionBudget instead of rejecting the invalid setting.
Check the original `podDisruptionBudget` value is a map before applying defaults.
</issue_to_address>
### Comment 5
<location path="docs/helm-chart.md" line_range="770-771" />
<code_context>
+(1 if neither it nor `minAvailable` is set), or keep at least
+`minAvailable` (a number or a percentage, e.g., `50%`; set at most one of
+them). Set `podDisruptionBudget.enabled: false` to render none. With one
+replica, no budget is rendered: no budget keeps a single pod available
+during a drain, and one with `minAvailable` would block the drain; for the
+same reason, avoid `maxUnavailable: 0` or a `minAvailable` of all replicas.
+Kubernetes' scheduler spreads the pods of a Deployment across nodes and
</code_context>
<issue_to_address>
**Single pod is evicted during drains**
When the app has one replica and a node drain or other voluntary disruption evicts it, the single-replica branch renders no PodDisruptionBudget, so Kubernetes can evict the only app pod during a voluntary drain and leave the app unavailable. The docs and template comment say that omitting the budget keeps the pod available, giving operators the opposite expectation.
Clarify that without a budget the pod can be evicted and the app can become unavailable; explain that a budget requiring one available pod instead blocks the voluntary eviction.
Also at `charts/foca-common/templates/_poddisruptionbudget.tpl:6-7`.
</issue_to_address>Linked issues
#584 feat(chart): configurable app replicas and a PodDisruptionBudget · 6 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Add <valuesKey>.replicas (integer >= 1, default 1) to set the number of app pods. |
✅ Met | The Deployment uses the shared replicas helper, which defaults to 1 and rejects non-whole numbers below 1. |
| 2 | Add <valuesKey>.podDisruptionBudget with enabled defaulting to true and either minAvailable or maxUnavailable; default maxUnavailable to 1 when neither is set. |
✅ Met | The schema and PDB template implement these settings and reject setting both bounds. |
| 3 | Render a PodDisruptionBudget only when enabled and replicas exceed 1. | ✅ Met | The template gates the PDB on both conditions and selects the app pods. |
| 4 | Add the values to the library schema and petstore chart, with template tests. | ✅ Met | Both schemas include the new values; the petstore chart adds values and a PDB template, and the library tests cover defaults, settings, and invalid values. |
| 5 | Document several replicas and their caveats in the Helm chart docs. | ✅ Met | The docs cover rolling updates, budget behavior, older app-chart upgrades, access-control changes, per-process caches, startup tasks, bundled dependencies, and upgrades requiring the app to stop. |
| 6 | Bump the library chart version to 0.3.0. | ✅ Met | The chart version is 0.3.0, and the petstore dependency uses that version. |
Sourcery assessment
Needs a human reviewer. 5 findings to address first, and a mistaken replica count can overcommit the cluster, and a mistaken disruption budget can block node drains or allow too many pods to be evicted, affecting service availability. Reverting restores the prior Deployment and budget settings, but any outage or disruption that already occurred cannot be undone.
Blocking findings: charts/foca-common/templates/_poddisruptionbudget.tpl:32, charts/foca-common/templates/_poddisruptionbudget.tpl:42, charts/foca-common/templates/_poddisruptionbudget.tpl:20, charts/foca-common/templates/_poddisruptionbudget.tpl:14, docs/helm-chart.md:771
Check minAvailable and maxUnavailable in the template too (whole numbers of at least 0 or percentages up to 100%), reject non-map budgets before applying defaults (e.g., false), allow a null podDisruptionBudget.enabled in the schema (true, as in the template), and say plainly that a single pod is evicted on drains. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Set unhealthyPodEvictionPolicy: AlwaysAllow on the app's PodDisruptionBudget, so that pods that are not ready (e.g., crash- looping after a failed upgrade) don't block node drains. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The library chart
foca-commonrendered the app's Deployment with a fixedreplicas: 1. This adds:<valuesKey>.replicas(integer >= 1, 1 if not set; named like the existingworker.replicas, the chart's convention, rather than Helm's scaffoldreplicaCount);<valuesKey>.podDisruptionBudget(enabled, true if not set;minAvailableormaxUnavailable, at most one, a number or a percentage up to 100%;maxUnavailable: 1if neither) and a new templatefoca-common.podDisruptionBudget, rendered only with more than one replica;enabled, the budget map, both bounds set);app-values.schema.jsonand the petstore copy), petstore values and template file, template tests, areplicassnapshot case, and the kind installation ofci/access-control-values.yamlwith 2 replicas (two instances storing the configured policies at the same time on startup);docs/helm-chart.md("Several replicas": rolling updates, budget semantics, upgrade steps for app charts moving to 0.3.0, caveats: rules changed in the database directly, per-process caches and memory, app startup tasks, single-pod MongoDB/broker, scaling to 0), and a pointer indocs/deployment.md;Multi-replica safety
FOCA apps already run as several instances (one per Gunicorn worker, two pods during rolling updates). Access control checks the change record before each use of the enforcer and applies changed rules (
foca/security/access_control/enforcer_cache.py,docs/access-control.md"Scaling"), and configured policies are replaced in generations, safe for instances starting at once (FocaCasbinAdapter.set_configured_policies()).Closes #584
Verification
pytest charts/foca-common/tests: 229 passed (Helm 3.18.5 locally; CI uses 3.22.1)helm lint --strict charts/foca-commonand the petstore chart with eachci/*-values.yaml: passedruff check,ruff format --check,mypy,ast-grep scan,mkdocs build --strict: passedChartandChart install(kind, with 2 replicas inci/access-control-values.yaml);CI passedgreen.Review
Two rounds of adversarial and quality review; all high/medium findings fixed (none were high; the medium ones were docs placement and structure), plus the low ones affecting behaviour (template-side validation, percentages up to 100%, budget map, null enabled).
Unrelated fixes
None.
Declined review findings
replicassnapshot (low): kept, as every other snapshot case is a full render too, and it pins the rendered budget.access-control.md#scalingandconfiguration/plugins.md#plugin-store; operators read the chart docs, so the caveats stay listed there.Release
After merge, the maintainer tags
chart-v0.3.0on the merge commit (see docs/helm-chart.md, Releases). Cloud Registry's chart then pins it (elixir-cloud-aai/cloud-registry#307).🤖 Generated with Claude Code
Summary by Sourcery
Support safely scaling FOCA application deployments beyond one replica with configurable disruption protection and operator guidance.
New Features:
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests: