Files
AudioManager/scripts/check-chart.sh
T
TapTap de1e95bfc6
CI / chart (push) Successful in 2s
CI / test (push) Successful in 1m59s
CI / chart-push (push) Successful in 5s
CI / image (push) Successful in 3m35s
feat(chart): set the Deezer ARL from values
- new deezer.arl value rendered as DEEZER_ARL
- existingSecret and arl are mutually exclusive
- values.local.yaml is gitignored; README documents both options
- chart 0.4.1 and a chart check for the new value
2026-11-17 16:10:56 +00:00

98 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Render and verify the Helm chart. Every namespaced resource must be rendered
# into the namespace that was passed to Helm, and rendering must fail when no
# namespace is passed instead of silently falling back to "default".
#
# Requires helm on PATH (`nix-shell` provides it).
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CHART_DIR="${CHART_DIR:-$ROOT/charts/audiomanager}"
RELEASE="${RELEASE:-audiomanager}"
NAMESPACE="${NAMESPACE:-audiomanager}"
workdir="$(mktemp -d "${TMPDIR:-/tmp}/chart-check.XXXXXX")"
trap 'rm -rf "$workdir"' EXIT
# An empty kubeconfig makes the implicit namespace deterministic ("default"),
# independent of whatever context the developer or runner has configured.
(umask 077 && : > "$workdir/kubeconfig")
echo "helm lint ($NAMESPACE)"
helm lint "$CHART_DIR" --namespace "$NAMESPACE" >/dev/null
echo "render ($NAMESPACE)"
helm template "$RELEASE" "$CHART_DIR" \
--namespace "$NAMESPACE" \
--set users.existingSecret=test \
> "$workdir/rendered.yaml"
# A namespace per document: fail if a namespaced kind has no metadata.namespace
# or carries a different one. Cluster-scoped kinds are listed explicitly so a
# new template cannot quietly skip the namespace.
NAMESPACE="$NAMESPACE" awk '
function cluster_scoped(kind) {
return kind == "Namespace" \
|| kind ~ /^Cluster/ \
|| kind ~ /^(PersistentVolume|StorageClass|IngressClass|Node|PriorityClass)$/ \
|| kind ~ /^(CustomResourceDefinition|APIService|RuntimeClass|CSIDriver|CSINode|VolumeAttachment)$/ \
|| kind ~ /(WebhookConfiguration)$/
}
function check_document() {
if (kind == "") return
if (cluster_scoped(kind)) return
if (namespace == "") {
printf "FAIL: %s has no metadata.namespace\n", kind
failed = 1
} else if (namespace != ENVIRON["NAMESPACE"]) {
printf "FAIL: %s is in namespace %s, want %s\n", kind, namespace, ENVIRON["NAMESPACE"]
failed = 1
}
kind = ""
namespace = ""
}
/^---[[:space:]]*$/ { check_document(); next }
/^kind:[[:space:]]/ { kind = $2 }
/^metadata:[[:space:]]*$/ { in_metadata = 1; next }
/^[^[:space:]]/ { in_metadata = 0 }
in_metadata && /^ namespace:[[:space:]]/ { namespace = $2; in_metadata = 0 }
END { check_document(); exit failed }
' "$workdir/rendered.yaml"
echo "render without a namespace must fail"
if helm template "$RELEASE" "$CHART_DIR" \
--kubeconfig "$workdir/kubeconfig" \
--set users.existingSecret=test \
> "$workdir/without-namespace.yaml" 2>/dev/null; then
echo "FAIL: the chart rendered without --namespace" >&2
exit 1
fi
echo "render with allowDefaultNamespace=true"
helm template "$RELEASE" "$CHART_DIR" \
--kubeconfig "$workdir/kubeconfig" \
--set users.existingSecret=test \
--set allowDefaultNamespace=true >/dev/null
echo "render with deezer.arl"
helm template "$RELEASE" "$CHART_DIR" \
--namespace "$NAMESPACE" \
--set users.existingSecret=test \
--set deezer.arl=test-arl > "$workdir/arl.yaml"
grep -A1 'name: DEEZER_ARL' "$workdir/arl.yaml" | grep -q 'value: "test-arl"'
echo "deezer.arl and deezer.existingSecret are mutually exclusive"
if helm template "$RELEASE" "$CHART_DIR" \
--namespace "$NAMESPACE" \
--set users.existingSecret=test \
--set deezer.arl=test-arl \
--set deezer.existingSecret=test-secret >/dev/null 2>&1; then
echo "FAIL: the chart accepted both deezer.arl and deezer.existingSecret" >&2
exit 1
fi
echo "chart check passed"