G7: helm lint per values set, render-defaults input, fail on empty render
- reusable-helm-lint: new `render-defaults` input (default true) for charts whose templates require values the defaults leave empty. - Lint each values set, not only the defaults. - Render to a named .yaml file and fail if nothing rendered; kubeconform passes on empty input and skips files without a .yaml extension. - docs/ci-cd/adding-ci.md: placeholder-values convention, G7 rollout table, test results. Refs DevOps/software-infrastructure#55 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,16 @@ on:
|
||||
type: string
|
||||
default: "1.31.2"
|
||||
values-files:
|
||||
description: Space-separated values files, relative to the chart, rendered in addition to the defaults.
|
||||
description: Space-separated values files, relative to the chart. Each is linted and rendered on its own.
|
||||
type: string
|
||||
default: ""
|
||||
render-defaults:
|
||||
description: >-
|
||||
Also lint and render with the chart's defaults alone. Set false for charts
|
||||
whose templates `required` values the defaults leave empty, and pass
|
||||
values-files instead.
|
||||
type: boolean
|
||||
default: true
|
||||
strict:
|
||||
description: Run helm lint with --strict (warnings fail).
|
||||
type: boolean
|
||||
@@ -48,6 +55,7 @@ jobs:
|
||||
KUBE_VERSION: ${{ inputs.kube-version }}
|
||||
VALUES_FILES: ${{ inputs.values-files }}
|
||||
STRICT: ${{ inputs.strict }}
|
||||
RENDER_DEFAULTS: ${{ inputs.render-defaults }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd "$CHART"
|
||||
@@ -55,18 +63,33 @@ jobs:
|
||||
helm dependency build --skip-refresh . || helm dependency build .
|
||||
fi
|
||||
|
||||
lint=(helm lint . --kube-version "$KUBE_VERSION")
|
||||
if [ "$STRICT" = "true" ]; then lint+=(--strict); fi
|
||||
"${lint[@]}"
|
||||
|
||||
sets=("")
|
||||
sets=()
|
||||
if [ "$RENDER_DEFAULTS" = "true" ]; then sets+=(""); fi
|
||||
for f in $VALUES_FILES; do sets+=("$f"); done
|
||||
if [ "${#sets[@]}" -eq 0 ]; then
|
||||
echo "::error::Nothing to check: render-defaults is false and values-files is empty."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# kubeconform skips files without a .yaml extension, so name it.
|
||||
rendered="$(mktemp -d)/rendered.yaml"
|
||||
for f in "${sets[@]}"; do
|
||||
extra=()
|
||||
label="default values"
|
||||
if [ -n "$f" ]; then extra=(-f "$f"); label="$f"; fi
|
||||
|
||||
echo "== lint: ${label}"
|
||||
lint=(helm lint . --kube-version "$KUBE_VERSION" "${extra[@]}")
|
||||
if [ "$STRICT" = "true" ]; then lint+=(--strict); fi
|
||||
"${lint[@]}"
|
||||
|
||||
echo "== render and validate: ${label}"
|
||||
helm template ci-render . --kube-version "$KUBE_VERSION" "${extra[@]}" \
|
||||
| kubeconform -strict -summary -ignore-missing-schemas \
|
||||
-kubernetes-version "${KUBE_VERSION#v}" -
|
||||
helm template ci-render . --kube-version "$KUBE_VERSION" "${extra[@]}" > "$rendered"
|
||||
# kubeconform passes on empty input, so make sure something rendered.
|
||||
if ! grep -q '^kind:' "$rendered"; then
|
||||
echo "::error::${label}: the chart rendered no resources."
|
||||
exit 1
|
||||
fi
|
||||
kubeconform -strict -summary -ignore-missing-schemas \
|
||||
-kubernetes-version "${KUBE_VERSION#v}" "$rendered"
|
||||
done
|
||||
|
||||
+24
-3
@@ -17,7 +17,7 @@ nothing is installed at run time and versions are the same everywhere.
|
||||
| Workflow | For | Runs |
|
||||
|---|---|---|
|
||||
| `reusable-ansible-role-lint.yaml` | `ansible-role-*` repos | `ansible-lint`, which also applies yamllint's rules |
|
||||
| `reusable-helm-lint.yaml` | Helm chart repos | `helm lint`, then `helm template` piped to `kubeconform` |
|
||||
| `reusable-helm-lint.yaml` | Helm chart repos | `helm lint`, then `helm template` checked by `kubeconform` |
|
||||
| `reusable-dockerfile-lint.yaml` | Repos with a Dockerfile | `hadolint` |
|
||||
| `reusable-secret-scan.yaml` | Every repo | `gitleaks`, see [secret-scanning.md](secret-scanning.md) |
|
||||
|
||||
@@ -101,12 +101,28 @@ jobs:
|
||||
| `tools-image` | `gitea.eom.dev/devops/ci-tools:1.0.0` | |
|
||||
| `chart-path` | `.` | Directory with `Chart.yaml`. |
|
||||
| `kube-version` | `1.31.2` | The cluster's version on 2026-11-14. Bump it when the cluster is upgraded. |
|
||||
| `values-files` | empty | Extra values files to render as well, space-separated. The defaults are always rendered. |
|
||||
| `values-files` | empty | Values files relative to the chart, space-separated. Each one is linted and rendered on its own. |
|
||||
| `render-defaults` | `true` | Also check the chart's defaults alone. Set `false` when templates `required` values the defaults leave empty. |
|
||||
| `strict` | `false` | `helm lint --strict`. |
|
||||
|
||||
Chart dependencies are built if `Chart.yaml` has any. kubeconform skips kinds
|
||||
it has no schema for (CRDs) rather than failing on them. Schemas are fetched
|
||||
from GitHub at run time.
|
||||
from GitHub at run time. The job fails if a values set renders no resources,
|
||||
because kubeconform alone would pass an empty render.
|
||||
|
||||
**Charts that need values to render.** Put CI-only placeholder values in the
|
||||
chart's `ci/` directory (the chart-testing convention), for example
|
||||
`ci/minimal-values.yaml`, set `render-defaults: false`, and list the files in
|
||||
`values-files`. Use obvious placeholders (`example.com`,
|
||||
`ci-placeholder-not-a-secret`), never real settings.
|
||||
|
||||
**Rolled out (G7, #55), manual-only until S8 and G1:**
|
||||
|
||||
| Repo | Values checked |
|
||||
|---|---|
|
||||
| DevOps/helm-jamulus | defaults |
|
||||
| DevOps/helm-mailman3 | `ci/minimal-values.yaml` (SQLite, postfix sidecar), `ci/postgresql-values.yaml` (the deployed shape) |
|
||||
| DevOps/helm-pixelfed | upstream's `test-values/postgresql-plain.yaml`. Prepared on branch `ci/helm-lint`, not `main`: adding `.gitea/workflows/` there stops Gitea running upstream's `.github/workflows`, which is Eric's call (#46). |
|
||||
|
||||
### Dockerfile
|
||||
|
||||
@@ -145,6 +161,11 @@ a local build of the tools image (1.0.0), against:
|
||||
| helm-lint | DevOps/helm-jamulus | passes |
|
||||
| | a template referencing a missing value | fails in `helm lint` |
|
||||
| | a Service with a string port | fails in kubeconform |
|
||||
| helm-lint (2026-11-15, G7) | helm-mailman3 with `ci/` values, helm-pixelfed with its test values | pass (7 + 15, and 27 resources valid) |
|
||||
| | helm-mailman3 with defaults only | fails in `helm lint` (missing `admin`) |
|
||||
| | helm-mailman3 at 5facaf7 (before the G7 fix) | fails in `helm lint` (template parse error) |
|
||||
| | a chart with no templates | fails: rendered no resources |
|
||||
| | `render-defaults: false` with no values files | fails with a clear message |
|
||||
| dockerfile-lint | `images/ci-tools/Dockerfile` | passes |
|
||||
| | `FROM debian:latest` with unpinned apt | fails (DL3007, DL3008) |
|
||||
| | repo with no Dockerfile | fails with a clear message |
|
||||
|
||||
Reference in New Issue
Block a user