- 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>
96 lines
3.4 KiB
YAML
96 lines
3.4 KiB
YAML
# Reusable lint and render check for a Helm chart. DevOps/software-infrastructure#50 (G2).
|
|
# Usage: docs/ci-cd/adding-ci.md.
|
|
#
|
|
# helm lint, then helm template | kubeconform against the cluster's Kubernetes
|
|
# version, in the shared CI tools image (G1, #49).
|
|
|
|
name: reusable-helm-lint
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
tools-image:
|
|
description: CI tools image, pinned by version.
|
|
type: string
|
|
default: gitea.eom.dev/devops/ci-tools:1.0.0
|
|
chart-path:
|
|
description: Path to the chart directory (the one with Chart.yaml).
|
|
type: string
|
|
default: "."
|
|
kube-version:
|
|
description: Kubernetes version to render and validate for. Keep it at the cluster's.
|
|
type: string
|
|
default: "1.31.2"
|
|
values-files:
|
|
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
|
|
default: false
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
container:
|
|
image: ${{ inputs.tools-image }}
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
|
|
- name: helm lint and kubeconform
|
|
env:
|
|
CHART: ${{ inputs.chart-path }}
|
|
KUBE_VERSION: ${{ inputs.kube-version }}
|
|
VALUES_FILES: ${{ inputs.values-files }}
|
|
STRICT: ${{ inputs.strict }}
|
|
RENDER_DEFAULTS: ${{ inputs.render-defaults }}
|
|
run: |
|
|
set -euo pipefail
|
|
cd "$CHART"
|
|
if grep -q '^dependencies:' Chart.yaml; then
|
|
helm dependency build --skip-refresh . || helm dependency build .
|
|
fi
|
|
|
|
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[@]}" > "$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
|