Skip to content

Commit a822ad1

Browse files
committed
fix(gateway-api-crds): keep the CRDs when the release is uninstalled
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 Gateway, HTTPRoute and ReferenceGrant in the tenant cluster with it. Stamp helm.sh/resource-policy: keep on each CustomResourceDefinition and teach `make update` to reapply it, since that target rebuilds templates/ from upstream and would otherwise drop the annotation silently. The ValidatingAdmissionPolicy pair the experimental kustomization also emits holds no user data and stays unannotated. 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 c6eb584 commit a822ad1

3 files changed

Lines changed: 167 additions & 0 deletions

File tree

‎packages/system/gateway-api-crds/Makefile‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@ 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 Gateway,
11+
# HTTPRoute, GRPCRoute and ReferenceGrant in the cluster. The experimental
12+
# kustomization also emits a ValidatingAdmissionPolicy and its binding, which
13+
# hold no user data and are left unannotated.
14+
# The stamp goes into the CRD's existing metadata.annotations block; a CRD that
15+
# arrives without one is skipped, and the chart's helm-unittest suite is what
16+
# catches that.
617
update:
718
rm -rf templates
819
mkdir templates
920
kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=v1.5.1" > templates/crds-experimental.yaml
21+
@set -e; f=templates/crds-experimental.yaml; tmp=$$(mktemp); \
22+
awk '/^ helm.sh\/resource-policy: keep$$/{next} /^kind: /{kind=$$2} /^ annotations:$$/ && kind=="CustomResourceDefinition"{print; print " helm.sh/resource-policy: keep"; next} {print}' "$$f" > "$$tmp"; \
23+
cat "$$tmp" > "$$f"; rm -f "$$tmp"

‎packages/system/gateway-api-crds/templates/crds-experimental.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
22
kind: CustomResourceDefinition
33
metadata:
44
annotations:
5+
helm.sh/resource-policy: keep
56
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
67
gateway.networking.k8s.io/bundle-version: v1.5.1
78
gateway.networking.k8s.io/channel: experimental
@@ -1421,6 +1422,7 @@ apiVersion: apiextensions.k8s.io/v1
14211422
kind: CustomResourceDefinition
14221423
metadata:
14231424
annotations:
1425+
helm.sh/resource-policy: keep
14241426
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
14251427
gateway.networking.k8s.io/bundle-version: v1.5.1
14261428
gateway.networking.k8s.io/channel: experimental
@@ -1937,6 +1939,7 @@ apiVersion: apiextensions.k8s.io/v1
19371939
kind: CustomResourceDefinition
19381940
metadata:
19391941
annotations:
1942+
helm.sh/resource-policy: keep
19401943
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
19411944
gateway.networking.k8s.io/bundle-version: v1.5.1
19421945
gateway.networking.k8s.io/channel: experimental
@@ -5267,6 +5270,7 @@ apiVersion: apiextensions.k8s.io/v1
52675270
kind: CustomResourceDefinition
52685271
metadata:
52695272
annotations:
5273+
helm.sh/resource-policy: keep
52705274
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
52715275
gateway.networking.k8s.io/bundle-version: v1.5.1
52725276
gateway.networking.k8s.io/channel: experimental
@@ -7547,6 +7551,7 @@ apiVersion: apiextensions.k8s.io/v1
75477551
kind: CustomResourceDefinition
75487552
metadata:
75497553
annotations:
7554+
helm.sh/resource-policy: keep
75507555
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
75517556
gateway.networking.k8s.io/bundle-version: v1.5.1
75527557
gateway.networking.k8s.io/channel: experimental
@@ -16103,6 +16108,7 @@ apiVersion: apiextensions.k8s.io/v1
1610316108
kind: CustomResourceDefinition
1610416109
metadata:
1610516110
annotations:
16111+
helm.sh/resource-policy: keep
1610616112
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
1610716113
gateway.networking.k8s.io/bundle-version: v1.5.1
1610816114
gateway.networking.k8s.io/channel: experimental
@@ -16884,6 +16890,7 @@ apiVersion: apiextensions.k8s.io/v1
1688416890
kind: CustomResourceDefinition
1688516891
metadata:
1688616892
annotations:
16893+
helm.sh/resource-policy: keep
1688716894
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
1688816895
gateway.networking.k8s.io/bundle-version: v1.5.1
1688916896
gateway.networking.k8s.io/channel: experimental
@@ -17238,6 +17245,7 @@ apiVersion: apiextensions.k8s.io/v1
1723817245
kind: CustomResourceDefinition
1723917246
metadata:
1724017247
annotations:
17248+
helm.sh/resource-policy: keep
1724117249
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
1724217250
gateway.networking.k8s.io/bundle-version: v1.5.1
1724317251
gateway.networking.k8s.io/channel: experimental
@@ -17995,6 +18003,7 @@ apiVersion: apiextensions.k8s.io/v1
1799518003
kind: CustomResourceDefinition
1799618004
metadata:
1799718005
annotations:
18006+
helm.sh/resource-policy: keep
1799818007
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
1799918008
gateway.networking.k8s.io/bundle-version: v1.5.1
1800018009
gateway.networking.k8s.io/channel: experimental
@@ -20366,6 +20375,7 @@ apiVersion: apiextensions.k8s.io/v1
2036620375
kind: CustomResourceDefinition
2036720376
metadata:
2036820377
annotations:
20378+
helm.sh/resource-policy: keep
2036920379
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
2037020380
gateway.networking.k8s.io/bundle-version: v1.5.1
2037120381
gateway.networking.k8s.io/channel: experimental
@@ -21123,6 +21133,7 @@ apiVersion: apiextensions.k8s.io/v1
2112321133
kind: CustomResourceDefinition
2112421134
metadata:
2112521135
annotations:
21136+
helm.sh/resource-policy: keep
2112621137
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
2112721138
gateway.networking.k8s.io/bundle-version: v1.5.1
2112821139
gateway.networking.k8s.io/channel: experimental
@@ -21732,6 +21743,7 @@ apiVersion: apiextensions.k8s.io/v1
2173221743
kind: CustomResourceDefinition
2173321744
metadata:
2173421745
annotations:
21746+
helm.sh/resource-policy: keep
2173521747
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/4530
2173621748
gateway.networking.k8s.io/bundle-version: v1.5.1
2173721749
gateway.networking.k8s.io/channel: experimental
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 Gateway, HTTPRoute and ReferenceGrant it holds.
6+
#
7+
# The first case selects every CustomResourceDefinition at once, so a CRD that
8+
# `make update` starts rendering is covered without being listed here. The
9+
# ValidatingAdmissionPolicy pair the experimental kustomization also emits
10+
# holds no user data and is deliberately left out of that selection. The named
11+
# cases below pin each CRD individually, so a failure says which one lost the
12+
# annotation. A selector that matches nothing fails with "document not found"
13+
# rather than passing on an empty document set.
14+
suite: Gateway API CRDs survive a release uninstall
15+
templates:
16+
- templates/crds-experimental.yaml
17+
tests:
18+
- it: annotates every CustomResourceDefinition the chart renders
19+
documentSelector:
20+
path: kind
21+
value: CustomResourceDefinition
22+
matchMany: true
23+
asserts:
24+
- equal:
25+
path: metadata.annotations["helm.sh/resource-policy"]
26+
value: keep
27+
28+
# Pins the rendered document count, so a change in what the kustomization
29+
# emits is visible here rather than only in whichever case happens to break.
30+
- it: renders twelve CRDs and the admission policy pair
31+
asserts:
32+
- hasDocuments:
33+
count: 14
34+
35+
- it: keeps the backendtlspolicies CRD
36+
documentSelector:
37+
path: metadata.name
38+
value: backendtlspolicies.gateway.networking.k8s.io
39+
asserts:
40+
- equal:
41+
path: metadata.annotations["helm.sh/resource-policy"]
42+
value: keep
43+
44+
- it: keeps the gatewayclasses CRD
45+
documentSelector:
46+
path: metadata.name
47+
value: gatewayclasses.gateway.networking.k8s.io
48+
asserts:
49+
- equal:
50+
path: metadata.annotations["helm.sh/resource-policy"]
51+
value: keep
52+
53+
- it: keeps the gateways CRD
54+
documentSelector:
55+
path: metadata.name
56+
value: gateways.gateway.networking.k8s.io
57+
asserts:
58+
- equal:
59+
path: metadata.annotations["helm.sh/resource-policy"]
60+
value: keep
61+
62+
- it: keeps the grpcroutes CRD
63+
documentSelector:
64+
path: metadata.name
65+
value: grpcroutes.gateway.networking.k8s.io
66+
asserts:
67+
- equal:
68+
path: metadata.annotations["helm.sh/resource-policy"]
69+
value: keep
70+
71+
- it: keeps the httproutes CRD
72+
documentSelector:
73+
path: metadata.name
74+
value: httproutes.gateway.networking.k8s.io
75+
asserts:
76+
- equal:
77+
path: metadata.annotations["helm.sh/resource-policy"]
78+
value: keep
79+
80+
- it: keeps the listenersets CRD
81+
documentSelector:
82+
path: metadata.name
83+
value: listenersets.gateway.networking.k8s.io
84+
asserts:
85+
- equal:
86+
path: metadata.annotations["helm.sh/resource-policy"]
87+
value: keep
88+
89+
- it: keeps the referencegrants CRD
90+
documentSelector:
91+
path: metadata.name
92+
value: referencegrants.gateway.networking.k8s.io
93+
asserts:
94+
- equal:
95+
path: metadata.annotations["helm.sh/resource-policy"]
96+
value: keep
97+
98+
- it: keeps the tcproutes CRD
99+
documentSelector:
100+
path: metadata.name
101+
value: tcproutes.gateway.networking.k8s.io
102+
asserts:
103+
- equal:
104+
path: metadata.annotations["helm.sh/resource-policy"]
105+
value: keep
106+
107+
- it: keeps the tlsroutes CRD
108+
documentSelector:
109+
path: metadata.name
110+
value: tlsroutes.gateway.networking.k8s.io
111+
asserts:
112+
- equal:
113+
path: metadata.annotations["helm.sh/resource-policy"]
114+
value: keep
115+
116+
- it: keeps the udproutes CRD
117+
documentSelector:
118+
path: metadata.name
119+
value: udproutes.gateway.networking.k8s.io
120+
asserts:
121+
- equal:
122+
path: metadata.annotations["helm.sh/resource-policy"]
123+
value: keep
124+
125+
- it: keeps the xbackendtrafficpolicies CRD
126+
documentSelector:
127+
path: metadata.name
128+
value: xbackendtrafficpolicies.gateway.networking.x-k8s.io
129+
asserts:
130+
- equal:
131+
path: metadata.annotations["helm.sh/resource-policy"]
132+
value: keep
133+
134+
- it: keeps the xmeshes CRD
135+
documentSelector:
136+
path: metadata.name
137+
value: xmeshes.gateway.networking.x-k8s.io
138+
asserts:
139+
- equal:
140+
path: metadata.annotations["helm.sh/resource-policy"]
141+
value: keep

0 commit comments

Comments
 (0)