Skip to content

Commit 5d5d8f5

Browse files
committed
fix(vertical-pod-autoscaler-crds): keep the CRDs on uninstall
The tenant addon HelmRelease remediates a failed install by uninstalling the release, and an uninstall deletes whatever the chart rendered. Deleting a CRD makes the API server garbage-collect every custom resource of that kind, so a failed reinstall takes every VerticalPodAutoscaler in the tenant cluster with it, along with the recommendation history held in the checkpoints. Stamp helm.sh/resource-policy: keep on each CustomResourceDefinition and teach `make update` to reapply it, since that target refetches the manifest from upstream and would otherwise drop the annotation silently. Removing the release on purpose now leaves the definitions behind to be deleted by hand. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent a822ad1 commit 5d5d8f5

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎packages/system/vertical-pod-autoscaler-crds/Makefile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,17 @@ export NAMESPACE=cozy-$(NAME)
33

44
include ../../../hack/package.mk
55

6+
test:
7+
helm unittest .
8+
9+
# Stamp helm.sh/resource-policy: keep on every CustomResourceDefinition so a
10+
# chart uninstall never garbage-collects the CRDs and, with them, every
11+
# VerticalPodAutoscaler and VerticalPodAutoscalerCheckpoint in the cluster.
12+
# The stamp goes into the CRD's existing metadata.annotations block; a CRD that
13+
# arrives without one is skipped, and the chart's helm-unittest suite is what
14+
# catches that.
615
update:
716
curl -o ./templates/vpa-v1-crd-gen.yaml https://raw.githubusercontent.com/kubernetes/autoscaler/refs/heads/master/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml
17+
@set -e; f=./templates/vpa-v1-crd-gen.yaml; tmp=$$(mktemp); \
18+
awk '/^ helm.sh\/resource-policy: keep$$/{next} /^kind: /{kind=$$2} /^ annotations:$$/ && kind=="CustomResourceDefinition"{print; print " helm.sh/resource-policy: keep"; next} {print}' "$$f" > "$$tmp"; \
19+
cat "$$tmp" > "$$f"; rm -f "$$tmp"

‎packages/system/vertical-pod-autoscaler-crds/templates/vpa-v1-crd-gen.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6+
helm.sh/resource-policy: keep
67
api-approved.kubernetes.io: https://github.com/kubernetes/kubernetes/pull/63797
78
controller-gen.kubebuilder.io/version: v0.16.5
89
name: verticalpodautoscalercheckpoints.autoscaling.k8s.io
@@ -224,6 +225,7 @@ apiVersion: apiextensions.k8s.io/v1
224225
kind: CustomResourceDefinition
225226
metadata:
226227
annotations:
228+
helm.sh/resource-policy: keep
227229
api-approved.kubernetes.io: https://github.com/kubernetes/kubernetes/pull/63797
228230
controller-gen.kubebuilder.io/version: v0.16.5
229231
name: verticalpodautoscalers.autoscaling.k8s.io
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# The tenant addon HelmRelease that ships this chart remediates a failed
2+
# install by uninstalling the release, and an uninstall deletes whatever the
3+
# chart rendered. Deleting a CRD makes the API server garbage-collect every
4+
# custom resource of that kind, so an unannotated CRD here costs the cluster
5+
# every VerticalPodAutoscaler it holds, along with the recommendation history
6+
# in the checkpoints.
7+
#
8+
# The first case scopes to no template at all, so it holds every document the
9+
# chart renders. The named cases pin each CRD by name: a selector that matches
10+
# nothing fails with "document not found" rather than passing on an empty
11+
# document set.
12+
suite: VerticalPodAutoscaler CRDs survive a release uninstall
13+
tests:
14+
- it: annotates every CustomResourceDefinition the chart renders
15+
asserts:
16+
- equal:
17+
path: kind
18+
value: CustomResourceDefinition
19+
- equal:
20+
path: metadata.annotations["helm.sh/resource-policy"]
21+
value: keep
22+
23+
# Pins the rendered document count so a CRD added upstream by `make update`
24+
# turns this red instead of arriving untested.
25+
- it: renders both CRDs
26+
template: templates/vpa-v1-crd-gen.yaml
27+
asserts:
28+
- hasDocuments:
29+
count: 2
30+
31+
- it: keeps the VerticalPodAutoscaler CRD
32+
documentSelector:
33+
path: metadata.name
34+
value: verticalpodautoscalers.autoscaling.k8s.io
35+
asserts:
36+
- equal:
37+
path: metadata.annotations["helm.sh/resource-policy"]
38+
value: keep
39+
40+
- it: keeps the VerticalPodAutoscalerCheckpoint CRD
41+
documentSelector:
42+
path: metadata.name
43+
value: verticalpodautoscalercheckpoints.autoscaling.k8s.io
44+
asserts:
45+
- equal:
46+
path: metadata.annotations["helm.sh/resource-policy"]
47+
value: keep

0 commit comments

Comments
 (0)