Skip to content

Commit 8ba8aa7

Browse files
feat(helm): improve admission configurations (#1607)
Signed-off-by: Oliver Bähler <[email protected]>
1 parent 508550b commit 8ba8aa7

File tree

6 files changed

+1034
-426
lines changed

6 files changed

+1034
-426
lines changed

charts/capsule/README.md

Lines changed: 94 additions & 80 deletions
Large diffs are not rendered by default.

charts/capsule/README.md.gotmpl

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Here the values you can override:
137137
{{- end }}
138138
{{- end }}
139139

140-
### Webhooks Parameters
140+
### Admission Webhook Parameters
141141

142142
| Key | Type | Default | Description |
143143
|-----|------|---------|-------------|
@@ -147,30 +147,6 @@ Here the values you can override:
147147
{{- end }}
148148
{{- end }}
149149

150-
## Created resources
151-
152-
This Helm Chart creates the following Kubernetes resources in the release namespace:
153-
154-
* Capsule Namespace
155-
* Capsule Operator Deployment
156-
* Capsule Service
157-
* CA Secret
158-
* Certificate Secret
159-
* Tenant Custom Resource Definition
160-
* CapsuleConfiguration Custom Resource Definition
161-
* MutatingWebHookConfiguration
162-
* ValidatingWebHookConfiguration
163-
* RBAC Cluster Roles
164-
* Metrics Service
165-
166-
And optionally, depending on the values set:
167-
168-
* Capsule ServiceAccount
169-
* Capsule Service Monitor
170-
* PodSecurityPolicy
171-
* RBAC ClusterRole and RoleBinding for pod security policy
172-
* RBAC Role and Rolebinding for metrics scrape
173-
174150
## Notes on installing Custom Resource Definitions with Helm3
175151

176152
Capsule, as many other add-ons, defines its own set of Custom Resource Definitions (CRDs). Helm3 removed the old CRDs installation method for a more simple methodology. In the Helm Chart, there is now a special directory called `crds` to hold the CRDs. These CRDs are not templated, but will be installed by default when running a `helm install` for the chart. If the CRDs already exist (for example, you already executed `helm install`), it will be skipped with a warning. When you wish to skip the CRDs installation, and do not see the warning, you can pass the `--skip-crds` flag to the `helm install` command.

charts/capsule/templates/mutatingwebhookconfiguration.yaml

Lines changed: 120 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,28 @@ metadata:
1313
{{- toYaml . | nindent 4 }}
1414
{{- end }}
1515
webhooks:
16-
{{- with .Values.webhooks.hooks.defaults.pods }}
17-
- admissionReviewVersions:
16+
{{- with (mergeOverwrite .Values.webhooks.hooks.pods .Values.webhooks.hooks.defaults.pods) }}
17+
{{- if .enabled }}
18+
- name: pod.defaults.projectcapsule.dev
19+
admissionReviewVersions:
1820
- v1
1921
clientConfig:
2022
{{- include "capsule.webhooks.service" (dict "path" "/defaults" "ctx" $) | nindent 4 }}
2123
failurePolicy: {{ .failurePolicy }}
22-
name: pod.defaults.projectcapsule.dev
24+
matchPolicy: {{ .matchPolicy }}
25+
reinvocationPolicy: {{ .reinvocationPolicy }}
26+
{{- with .namespaceSelector }}
27+
namespaceSelector:
28+
{{- toYaml . | nindent 4 }}
29+
{{- end }}
30+
{{- with .objectSelector }}
31+
objectSelector:
32+
{{- toYaml . | nindent 4 }}
33+
{{- end }}
34+
{{- with .matchConditions }}
35+
matchConditions:
36+
{{- toYaml . | nindent 4 }}
37+
{{- end }}
2338
rules:
2439
- apiGroups:
2540
- ""
@@ -30,18 +45,32 @@ webhooks:
3045
resources:
3146
- pods
3247
scope: "Namespaced"
33-
namespaceSelector:
34-
{{- toYaml .namespaceSelector | nindent 4}}
3548
sideEffects: None
3649
timeoutSeconds: {{ $.Values.webhooks.mutatingWebhooksTimeoutSeconds }}
50+
{{- end }}
3751
{{- end }}
38-
{{- with .Values.webhooks.hooks.defaults.pvc }}
39-
- admissionReviewVersions:
52+
{{- with (mergeOverwrite .Values.webhooks.hooks.persistentvolumeclaims .Values.webhooks.hooks.defaults.pvc) }}
53+
{{- if .enabled }}
54+
- name: storage.defaults.projectcapsule.dev
55+
admissionReviewVersions:
4056
- v1
4157
clientConfig:
4258
{{- include "capsule.webhooks.service" (dict "path" "/defaults" "ctx" $) | nindent 4 }}
4359
failurePolicy: {{ .failurePolicy }}
44-
name: storage.defaults.projectcapsule.dev
60+
matchPolicy: {{ .matchPolicy }}
61+
reinvocationPolicy: {{ .reinvocationPolicy }}
62+
{{- with .namespaceSelector }}
63+
namespaceSelector:
64+
{{- toYaml . | nindent 4 }}
65+
{{- end }}
66+
{{- with .objectSelector }}
67+
objectSelector:
68+
{{- toYaml . | nindent 4 }}
69+
{{- end }}
70+
{{- with .matchConditions }}
71+
matchConditions:
72+
{{- toYaml . | nindent 4 }}
73+
{{- end }}
4574
rules:
4675
- apiGroups:
4776
- ""
@@ -52,18 +81,32 @@ webhooks:
5281
resources:
5382
- persistentvolumeclaims
5483
scope: "Namespaced"
55-
namespaceSelector:
56-
{{- toYaml .namespaceSelector | nindent 4}}
5784
sideEffects: None
5885
timeoutSeconds: {{ $.Values.webhooks.mutatingWebhooksTimeoutSeconds }}
86+
{{- end }}
5987
{{- end }}
60-
{{- with .Values.webhooks.hooks.defaults.ingress }}
61-
- admissionReviewVersions:
88+
{{- with (mergeOverwrite .Values.webhooks.hooks.ingresses .Values.webhooks.hooks.defaults.ingress) }}
89+
{{- if .enabled }}
90+
- name: ingress.defaults.projectcapsule.dev
91+
admissionReviewVersions:
6292
- v1
6393
clientConfig:
6494
{{- include "capsule.webhooks.service" (dict "path" "/defaults" "ctx" $) | nindent 4 }}
6595
failurePolicy: {{ .failurePolicy }}
66-
name: ingress.defaults.projectcapsule.dev
96+
matchPolicy: {{ .matchPolicy }}
97+
reinvocationPolicy: {{ .reinvocationPolicy }}
98+
{{- with .namespaceSelector }}
99+
namespaceSelector:
100+
{{- toYaml . | nindent 4 }}
101+
{{- end }}
102+
{{- with .objectSelector }}
103+
objectSelector:
104+
{{- toYaml . | nindent 4 }}
105+
{{- end }}
106+
{{- with .matchConditions }}
107+
matchConditions:
108+
{{- toYaml . | nindent 4 }}
109+
{{- end }}
67110
rules:
68111
- apiGroups:
69112
- networking.k8s.io
@@ -76,18 +119,32 @@ webhooks:
76119
resources:
77120
- ingresses
78121
scope: "Namespaced"
79-
namespaceSelector:
80-
{{- toYaml .namespaceSelector | nindent 4}}
81122
sideEffects: None
82123
timeoutSeconds: {{ $.Values.webhooks.mutatingWebhooksTimeoutSeconds }}
124+
{{- end }}
83125
{{- end }}
84126
{{- with .Values.webhooks.hooks.gateways }}
85-
- admissionReviewVersions:
127+
{{- if .enabled }}
128+
- name: gateway.defaults.projectcapsule.dev
129+
admissionReviewVersions:
86130
- v1
87131
clientConfig:
88132
{{- include "capsule.webhooks.service" (dict "path" "/defaults" "ctx" $) | nindent 4 }}
89133
failurePolicy: {{ .failurePolicy }}
90-
name: gateway.defaults.projectcapsule.dev
134+
matchPolicy: {{ .matchPolicy }}
135+
reinvocationPolicy: {{ .reinvocationPolicy }}
136+
{{- with .namespaceSelector }}
137+
namespaceSelector:
138+
{{- toYaml . | nindent 4 }}
139+
{{- end }}
140+
{{- with .objectSelector }}
141+
objectSelector:
142+
{{- toYaml . | nindent 4 }}
143+
{{- end }}
144+
{{- with .matchConditions }}
145+
matchConditions:
146+
{{- toYaml . | nindent 4 }}
147+
{{- end }}
91148
rules:
92149
- apiGroups:
93150
- gateway.networking.k8s.io
@@ -99,20 +156,21 @@ webhooks:
99156
resources:
100157
- gateways
101158
scope: "Namespaced"
102-
namespaceSelector:
103-
{{- toYaml .namespaceSelector | nindent 4}}
104159
sideEffects: None
105160
timeoutSeconds: {{ $.Values.webhooks.mutatingWebhooksTimeoutSeconds }}
161+
{{- end }}
106162
{{- end }}
107-
{{- with (mergeOverwrite .Values.webhooks.hooks.namespace.mutation .Values.webhooks.hooks.namespaceOwnerReference) }}
108-
- admissionReviewVersions:
163+
{{- with (mergeOverwrite .Values.webhooks.hooks.namespaces .Values.webhooks.hooks.namespaceOwnerReference) }}
164+
{{- if .enabled }}
165+
- name: namespaces.tenants.projectcapsule.dev
166+
admissionReviewVersions:
109167
- v1
110168
- v1beta1
111169
clientConfig:
112170
{{- include "capsule.webhooks.service" (dict "path" "/namespace-patch" "ctx" $) | nindent 4 }}
113171
failurePolicy: {{ .failurePolicy }}
114-
matchPolicy: Equivalent
115-
name: namespace-patching.tenants.projectcapsule.dev
172+
matchPolicy: {{ .matchPolicy }}
173+
reinvocationPolicy: {{ .reinvocationPolicy }}
116174
{{- with .namespaceSelector }}
117175
namespaceSelector:
118176
{{- toYaml . | nindent 4 }}
@@ -121,7 +179,10 @@ webhooks:
121179
objectSelector:
122180
{{- toYaml . | nindent 4 }}
123181
{{- end }}
124-
reinvocationPolicy: Never
182+
{{- with .matchConditions }}
183+
matchConditions:
184+
{{- toYaml . | nindent 4 }}
185+
{{- end }}
125186
rules:
126187
- apiGroups:
127188
- ""
@@ -136,18 +197,30 @@ webhooks:
136197
sideEffects: NoneOnDryRun
137198
timeoutSeconds: {{ $.Values.webhooks.mutatingWebhooksTimeoutSeconds }}
138199
{{- end }}
139-
{{- with .Values.webhooks.hooks.resourcepools.pools }}
140-
- admissionReviewVersions:
200+
{{- end }}
201+
{{- with .Values.webhooks.hooks.resourcepools.pools }}
202+
{{- if .enabled }}
203+
- name: resourcepools.projectcapsule.dev
204+
admissionReviewVersions:
141205
- v1
142206
- v1beta1
143207
clientConfig:
144208
{{- include "capsule.webhooks.service" (dict "path" "/resourcepool/mutating" "ctx" $) | nindent 4 }}
145209
failurePolicy: {{ .failurePolicy }}
146210
matchPolicy: {{ .matchPolicy }}
147-
name: resourcepools.projectcapsule.dev
148-
namespaceSelector: {{ toYaml .namespaceSelector | nindent 4 }}
149-
objectSelector: {{ toYaml .objectSelector | nindent 4 }}
150211
reinvocationPolicy: {{ .reinvocationPolicy }}
212+
{{- with .namespaceSelector }}
213+
namespaceSelector:
214+
{{- toYaml . | nindent 4 }}
215+
{{- end }}
216+
{{- with .objectSelector }}
217+
objectSelector:
218+
{{- toYaml . | nindent 4 }}
219+
{{- end }}
220+
{{- with .matchConditions }}
221+
matchConditions:
222+
{{- toYaml . | nindent 4 }}
223+
{{- end }}
151224
rules:
152225
- apiGroups:
153226
- "capsule.clastix.io"
@@ -162,18 +235,30 @@ webhooks:
162235
sideEffects: None
163236
timeoutSeconds: {{ $.Values.webhooks.mutatingWebhooksTimeoutSeconds }}
164237
{{- end }}
165-
{{- with .Values.webhooks.hooks.resourcepools.claims }}
166-
- admissionReviewVersions:
238+
{{- end }}
239+
{{- with .Values.webhooks.hooks.resourcepools.claims }}
240+
{{- if .enabled }}
241+
- name: resourcepoolclaims.projectcapsule.dev
242+
admissionReviewVersions:
167243
- v1
168244
- v1beta1
169245
clientConfig:
170246
{{- include "capsule.webhooks.service" (dict "path" "/resourcepool/claim/mutating" "ctx" $) | nindent 4 }}
171247
failurePolicy: {{ .failurePolicy }}
172248
matchPolicy: {{ .matchPolicy }}
173-
name: resourcepoolclaims.projectcapsule.dev
174-
namespaceSelector: {{ toYaml .namespaceSelector | nindent 4 }}
175-
objectSelector: {{ toYaml .objectSelector | nindent 4 }}
176249
reinvocationPolicy: {{ .reinvocationPolicy }}
250+
{{- with .namespaceSelector }}
251+
namespaceSelector:
252+
{{- toYaml . | nindent 4 }}
253+
{{- end }}
254+
{{- with .objectSelector }}
255+
objectSelector:
256+
{{- toYaml . | nindent 4 }}
257+
{{- end }}
258+
{{- with .matchConditions }}
259+
matchConditions:
260+
{{- toYaml . | nindent 4 }}
261+
{{- end }}
177262
rules:
178263
- apiGroups:
179264
- "capsule.clastix.io"
@@ -189,3 +274,4 @@ webhooks:
189274
timeoutSeconds: {{ $.Values.webhooks.mutatingWebhooksTimeoutSeconds }}
190275
{{- end }}
191276
{{- end }}
277+
{{- end }}

0 commit comments

Comments
 (0)