Skip to content

Commit ed6135d

Browse files
committed
fix(etcd): fail the CRD vendoring when the keep stamp misses
`make update` stamps helm.sh/resource-policy: keep onto each vendored CRD with an awk step anchored on the controller-gen version line, which upstream owns. If upstream stops emitting that line the step matches nothing, writes the CRD out unstamped and exits zero, so the release quietly loses the protection that keeps a chart uninstall from deleting the CRDs and every EtcdCluster, EtcdMember and EtcdSnapshot under them. Count the annotations the step produced and require exactly one per CRD. Zero means the anchor is gone; more than one means it matched somewhere unintended. Stage every CRD in a temporary directory and replace templates/ only once all of them are counted, so a failure on any one leaves the vendored files exactly as they were instead of wiping the directory and refilling part of the set. Verified by substituting the upstream response: a CRD with no controller-gen line fails with "stamped 0 keep annotations, expected 1", one carrying the line twice fails with 2, a failure on the second CRD leaves all three committed files untouched, and the unmodified upstream still vendors byte-identical output. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent b4e2031 commit ed6135d

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

  • packages/system/etcd-operator-crds

‎packages/system/etcd-operator-crds/Makefile‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ ETCD_OPERATOR_REF ?= v0.5.4
1010
# is no config/crd kustomization). Vendor each verbatim and stamp
1111
# helm.sh/resource-policy: keep so a chart uninstall never garbage-collects the
1212
# CRDs and, with them, every EtcdCluster/EtcdMember/EtcdSnapshot in the cluster.
13+
# The stamp is anchored on a line upstream controls, so count the result: one
14+
# annotation per CRD, or the update fails. templates/ is replaced only after
15+
# every CRD has been counted, so a failure leaves the vendored files as they
16+
# were.
1317
CRDS = etcdclusters etcdmembers etcdsnapshots
1418
update:
15-
rm -rf templates
16-
mkdir templates
17-
@set -e; for c in $(CRDS); do \
18-
src=$$(mktemp); \
19-
curl -fsSL "https://raw.githubusercontent.com/cozystack/etcd-operator/$(ETCD_OPERATOR_REF)/charts/etcd-operator/crd-bases/etcd-operator.cozystack.io_$$c.yaml" -o "$$src"; \
20-
awk '/^ controller-gen.kubebuilder.io\/version:/{print; print " helm.sh/resource-policy: keep"; next} {print}' "$$src" > templates/$$c.yaml; \
21-
rm -f "$$src"; \
22-
done
19+
@set -e; tmp=$$(mktemp -d); trap 'rm -rf "$$tmp"' EXIT; \
20+
for c in $(CRDS); do \
21+
curl -fsSL "https://raw.githubusercontent.com/cozystack/etcd-operator/$(ETCD_OPERATOR_REF)/charts/etcd-operator/crd-bases/etcd-operator.cozystack.io_$$c.yaml" -o "$$tmp/$$c.src"; \
22+
awk '/^ controller-gen.kubebuilder.io\/version:/{print; print " helm.sh/resource-policy: keep"; next} {print}' "$$tmp/$$c.src" > "$$tmp/$$c.yaml"; \
23+
n=$$(grep -c '^ helm.sh/resource-policy: keep$$' "$$tmp/$$c.yaml" || true); \
24+
[ "$$n" -eq 1 ] || { echo "$$c: stamped $$n keep annotations, expected 1" >&2; exit 1; }; \
25+
done; \
26+
rm -rf templates; mkdir templates; \
27+
for c in $(CRDS); do mv "$$tmp/$$c.yaml" templates/$$c.yaml; done

0 commit comments

Comments
 (0)