|
| 1 | +#!/usr/bin/env bats |
| 2 | +# Helm keeps every release revision in one Secret, and the apiserver refuses a |
| 3 | +# Secret over 1 MiB. A chart past that budget installs and then fails the one |
| 4 | +# upgrade whose manifest is large enough ("Secret sh.helm.release.v1.<name>.vN |
| 5 | +# is invalid: data: Too long"), and that release stays failed. The stored |
| 6 | +# release carries the whole chart directory as it reaches helm-controller: |
| 7 | +# the packages artifact applies no .helmignore, so tests/, images/ and the |
| 8 | +# Makefile count too. hack/helm-release-size.py reproduces the encoding. |
| 9 | +# |
| 10 | +# The budget is 90 percent of the limit: the estimate runs about 1 percent |
| 11 | +# above real Secrets, and the rest is room for a chart to grow by more than |
| 12 | +# one change before anyone has to act. |
| 13 | +# |
| 14 | +# Harness compatibility note: CI runs this file under Bats through |
| 15 | +# `make bats-unit-tests`. It also remains compatible with the narrower legacy |
| 16 | +# `hack/cozytest.sh` translator, so it avoids `run`, `$status`, `$output`, |
| 17 | +# `skip`, and setup()/teardown(). Paths stay repo-root-relative for both |
| 18 | +# runners. |
| 19 | +# |
| 20 | +# Run with: bats hack/helm-release-size.bats |
| 21 | + |
| 22 | +load test_helper |
| 23 | + |
| 24 | +LIMIT=1048576 |
| 25 | +BUDGET=943718 |
| 26 | + |
| 27 | +# Charts that do not render offline with default values (required values, |
| 28 | +# cluster lookups). They are measured on their stored files and templates |
| 29 | +# alone, a lower bound. Any other chart must render: a render failure there |
| 30 | +# would quietly shrink the measurement to the same lower bound. A chart that |
| 31 | +# stops rendering offline on purpose goes here; one that starts rendering |
| 32 | +# must come off, so the list never hides a renderable chart. |
| 33 | +NO_OFFLINE_RENDER=" |
| 34 | +packages/apps/bucket |
| 35 | +packages/apps/clickhouse |
| 36 | +packages/apps/foundationdb |
| 37 | +packages/apps/harbor |
| 38 | +packages/apps/kafka |
| 39 | +packages/apps/kubernetes |
| 40 | +packages/apps/kubernetes-nodes |
| 41 | +packages/apps/mariadb |
| 42 | +packages/apps/mongodb |
| 43 | +packages/apps/nats |
| 44 | +packages/apps/openbao |
| 45 | +packages/apps/opensearch |
| 46 | +packages/apps/postgres |
| 47 | +packages/apps/qdrant |
| 48 | +packages/apps/rabbitmq |
| 49 | +packages/apps/redis |
| 50 | +packages/apps/tenant |
| 51 | +packages/apps/valkey |
| 52 | +packages/apps/vm-disk |
| 53 | +packages/apps/vm-instance |
| 54 | +packages/apps/vpc |
| 55 | +packages/apps/vpn |
| 56 | +packages/core/platform |
| 57 | +packages/extra/bootbox |
| 58 | +packages/extra/computeplane |
| 59 | +packages/extra/etcd |
| 60 | +packages/extra/external-dns |
| 61 | +packages/extra/gateway |
| 62 | +packages/extra/info |
| 63 | +packages/extra/ingress |
| 64 | +packages/extra/monitoring |
| 65 | +packages/extra/seaweedfs |
| 66 | +packages/library/cozy-lib |
| 67 | +packages/system/kuberture |
| 68 | +packages/system/telepresence |
| 69 | +packages/tests/cozy-lib-tests |
| 70 | +" |
| 71 | + |
| 72 | +@test "the estimator counts chart files the way Helm stores them" { |
| 73 | + tmp=$(mktemp -d) |
| 74 | + mkdir -p "$tmp/chart/templates" "$tmp/chart/tests" |
| 75 | + printf 'apiVersion: v2\nname: probe\nversion: 0.0.0\n' > "$tmp/chart/Chart.yaml" |
| 76 | + # Incompressible, so the stored size cannot be smaller than its base64. |
| 77 | + head -c 300000 /dev/urandom > "$tmp/chart/tests/blob" |
| 78 | + size=$(printf '' | python3 -I hack/helm-release-size.py "$tmp/chart") |
| 79 | + if [ "$size" -lt 400000 ]; then |
| 80 | + echo "estimate $size for a chart carrying 300000 random bytes; files are not counted" >&2 |
| 81 | + false |
| 82 | + fi |
| 83 | + rm -rf "$tmp" |
| 84 | +} |
| 85 | + |
| 86 | +@test "every chart's stored release fits the budget with its default render" { |
| 87 | + tmp=$(mktemp -d) |
| 88 | + : > "$tmp/over" |
| 89 | + : > "$tmp/render" |
| 90 | + n=0 |
| 91 | + for c in packages/*/*/; do |
| 92 | + c=${c%/} |
| 93 | + [ -f "$c/Chart.yaml" ] || continue |
| 94 | + n=$((n + 1)) |
| 95 | + listed=no |
| 96 | + case "$NO_OFFLINE_RENDER" in *" |
| 97 | +$c |
| 98 | +"*) listed=yes ;; esac |
| 99 | + if helm template release "$c" -n default > "$tmp/manifest" 2> "$tmp/err"; then |
| 100 | + if [ "$listed" = yes ]; then |
| 101 | + echo "$c renders offline now; remove it from NO_OFFLINE_RENDER in hack/helm-release-size.bats" >> "$tmp/render" |
| 102 | + fi |
| 103 | + elif [ "$listed" = yes ]; then |
| 104 | + : > "$tmp/manifest" |
| 105 | + else |
| 106 | + echo "$c failed to render offline; fix the render, or add it to NO_OFFLINE_RENDER in hack/helm-release-size.bats if it needs cluster state: $(grep -m 1 '^Error' "$tmp/err" | cut -c1-300)" >> "$tmp/render" |
| 107 | + continue |
| 108 | + fi |
| 109 | + size=$(python3 -I hack/helm-release-size.py "$c" < "$tmp/manifest") |
| 110 | + if [ "$size" -gt "$BUDGET" ]; then |
| 111 | + echo "$c: $size bytes (budget $BUDGET, limit $LIMIT)" >> "$tmp/over" |
| 112 | + fi |
| 113 | + done |
| 114 | + if [ "$n" -lt 50 ]; then |
| 115 | + echo "only $n charts found under packages/; the sweep checked almost nothing" >&2 |
| 116 | + false |
| 117 | + fi |
| 118 | + if [ -s "$tmp/render" ]; then |
| 119 | + cat "$tmp/render" >&2 |
| 120 | + false |
| 121 | + fi |
| 122 | + if [ -s "$tmp/over" ]; then |
| 123 | + echo "charts whose stored Helm release is over budget:" >&2 |
| 124 | + cat "$tmp/over" >&2 |
| 125 | + false |
| 126 | + fi |
| 127 | + rm -rf "$tmp" |
| 128 | +} |
| 129 | + |
| 130 | +@test "backupstrategy-controller fits the budget on its largest revision" { |
| 131 | + # The default render gates every Strategy CR off. The revision that renders |
| 132 | + # all of them, with the Velero location on as in production, is the one |
| 133 | + # that grew past the limit once. |
| 134 | + c=packages/system/backupstrategy-controller |
| 135 | + tmp=$(mktemp -d) |
| 136 | + # Rendered to a file rather than piped: in a pipe the estimator's status |
| 137 | + # would stand for the render's, and a failed render would be measured as an |
| 138 | + # empty manifest and pass. |
| 139 | + if ! helm template backupstrategy-controller "$c" -n cozy-backup-controller \ |
| 140 | + --set backupStorage.bucketNameOverride=cozy-backups-0123 \ |
| 141 | + --set velero.bslEnabled=true > "$tmp/manifest"; then |
| 142 | + echo "$c failed to render its largest revision; nothing was measured" >&2 |
| 143 | + false |
| 144 | + fi |
| 145 | + if ! grep -q '^kind: Kafka$' "$tmp/manifest"; then |
| 146 | + echo "$c rendered without the default Strategy CRs; this is not its largest revision" >&2 |
| 147 | + false |
| 148 | + fi |
| 149 | + size=$(python3 -I hack/helm-release-size.py "$c" < "$tmp/manifest") |
| 150 | + rm -rf "$tmp" |
| 151 | + if [ "$size" -gt "$BUDGET" ]; then |
| 152 | + echo "$c: $size bytes with every default Strategy rendered (budget $BUDGET, limit $LIMIT)" >&2 |
| 153 | + false |
| 154 | + fi |
| 155 | +} |
0 commit comments