diff --git a/.github/workflows/helm-chart.yml b/.github/workflows/helm-chart.yml index 33b9d91..2ab3c30 100644 --- a/.github/workflows/helm-chart.yml +++ b/.github/workflows/helm-chart.yml @@ -28,6 +28,16 @@ on: required: false type: string default: charts + setup-script: + description: Script run against the kind cluster before installing, for example to install CRDs the chart depends on. Skipped when the file does not exist. + required: false + type: string + default: ci/setup.sh + wait: + description: Helm wait strategy for the test install, watcher or legacy. Use legacy when the chart creates custom resources that only become ready with a real backend. + required: false + type: string + default: watcher permissions: {} @@ -57,9 +67,13 @@ jobs: [ -n "$file" ] && args=(--values "$file") echo "::group::${file:-default values}" helm lint --strict "$CHART" "${args[@]}" + # Custom resources are checked against the CRDs catalog, Kubernetes ones against the default schemas. helm template ci "$CHART" "${args[@]}" --kube-version "$KUBE_VERSION" \ | docker run --rm -i ghcr.io/yannh/kubeconform:v0.8.0@sha256:faffaf43f95aa6425306e1ab8d6fcad72acb9049158f38e574c085ea1ec0f64e \ - -strict -summary -kubernetes-version "$KUBE_VERSION" - + -strict -summary -kubernetes-version "$KUBE_VERSION" \ + -schema-location default \ + -schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' \ + - echo "::endgroup::" done @@ -78,9 +92,19 @@ jobs: - uses: helm/kind-action@ea822c7bf1874f08e5a491df991c228edffc3376 # v1.15.2 with: node_image: ${{ inputs.kind-node-image }} + - name: Prepare the cluster + env: + SETUP_SCRIPT: ${{ inputs.setup-script }} + run: | + if [ -f "$SETUP_SCRIPT" ]; then + bash "$SETUP_SCRIPT" + else + echo "No $SETUP_SCRIPT; nothing to prepare" + fi - name: Install and run helm test env: CHART: ${{ inputs.chart-path }} + WAIT: ${{ inputs.wait }} run: | shopt -s nullglob values=("$CHART"/ci/*-values.yaml) @@ -93,7 +117,7 @@ jobs: [ -n "$file" ] && args=(--values "$file") echo "::group::Install with ${file:-default values}" if ! helm install "$release" "$CHART" "${args[@]}" \ - --namespace "$release" --create-namespace --wait --timeout 10m; then + --namespace "$release" --create-namespace --wait="$WAIT" --timeout 10m; then kubectl --namespace "$release" get all,pvc kubectl --namespace "$release" describe pods kubectl --namespace "$release" logs --all-containers --tail 100 \ diff --git a/README.md b/README.md index eac7f1b..f734ede 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,12 @@ cosign verify ghcr.io/think-cube/: \ ## helm-chart -Every run lints the chart with `helm lint --strict` and validates the rendered manifests with kubeconform. It then installs the chart into a kind cluster, waits for it to become ready and runs `helm test`. +Every run lints the chart with `helm lint --strict` and validates the rendered manifests with kubeconform: Kubernetes resources against the official schemas, custom resources such as KEDA's against the [CRDs catalog](https://github.com/datreeio/CRDs-catalog). It then installs the chart into a kind cluster, waits for it to become ready and runs `helm test`. When the chart has `ci/*-values.yaml` files, each check runs once per file instead of with the default values. Use them to cover the configurations that matter, such as an optional component switched on. +When the chart has `ci/setup.sh`, it runs against the kind cluster before the installs. Use it to install what the chart depends on, such as an operator and its CRDs. + On `v*` tags it also packages the chart, pushes it to GitHub Container Registry as an OCI artifact and signs it with keyless Cosign. The tag must match `version` in `Chart.yaml`, and a release fails instead of overwriting a version that already exists. If the chart directory contains `artifacthub-repo.yml`, it is pushed as Artifact Hub repository metadata. ### Usage @@ -117,7 +119,7 @@ jobs: contents: read id-token: write packages: write - uses: Think-Cube/workflows/.github/workflows/helm-chart.yml@v1.1.0 + uses: Think-Cube/workflows/.github/workflows/helm-chart.yml@v1.2.0 ``` ### Inputs @@ -129,6 +131,8 @@ jobs: | `kubernetes-version` | `1.34.12` | Kubernetes version the rendered manifests are validated against | | `kind-node-image` | `kindest/node:v1.35.8@sha256:...` | kind node image the chart is installed into | | `registry-path` | `charts` | Path under `ghcr.io/` the chart is pushed to | +| `setup-script` | `ci/setup.sh` | Script run against the kind cluster before installing; skipped when missing | +| `wait` | `watcher` | Helm wait strategy for the test install. Use `legacy` when the chart creates custom resources that only become ready with a real backend. | ### Verify a published chart