You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/book/src/developer/providers/v1alpha2-to-v1alpha3.md
+184Lines changed: 184 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,3 +154,187 @@ unique keys to `failureDomainSpec`s as well as respecting a set `Machine.Spec.Fa
154
154
instances.
155
155
156
156
Please see the cluster and machine infrastructure provider specifications for more detail.
157
+
158
+
## Refactor kustomize `config/` folder to support multi-tenancy when using webhooks.
159
+
160
+
> Pre-Requisites: Upgrade to CRD v1.
161
+
162
+
More details and background can be found in [Issue #2275](https://github.com/kubernetes-sigs/cluster-api/issues/2275) and [PR #2279](https://github.com/kubernetes-sigs/cluster-api/pull/2279).
163
+
164
+
Goals:
165
+
- Have all webhook related components in the `capi-webhook-system` namespace.
166
+
- Achieves multi-tenancy and guarantees that both CRD and webhook resources can live globally and can be patched in future iterations.
167
+
- Run a new manager instance that ONLY runs webhooks and doesn't install any reconcilers.
168
+
169
+
Steps:
170
+
- In `config/certmanager/`
171
+
-**Patch**
172
+
-**certificate.yaml**: The `secretName` value MUST be set to `$(SERVICE_NAME)-cert`.
173
+
-**kustomization.yaml**: Add the following to `varReference`
174
+
```yaml
175
+
- kind: Certificate
176
+
group: cert-manager.io
177
+
path: spec/secretName
178
+
```
179
+
180
+
- In `config/`
181
+
- **Create**
182
+
- **kustomization.yaml**: This file is going to function as the new entrypoint to run `kustomize build`.
183
+
`PROVIDER_NAME`is the name of your provider, e.g. `aws`.
184
+
`PROVIDER_TYPE`is the type of your provider, e.g. `control-plane`, `bootstrap`, `infrastructure`.
- Add `namespace: capi-webhook-system` at the top of the file.
284
+
- Under `resources`, add `../certmanager` and `../manager`.
285
+
- Add at the bottom of the file:
286
+
```yaml
287
+
patchesStrategicMerge:
288
+
- manager_webhook_patch.yaml
289
+
- webhookcainjection_patch.yaml # Disable this value if you don't have any defaulting or validation webhook. If you don't know, you can check if the manifests.yaml file in the same directory has any contents.
290
+
291
+
vars:
292
+
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
293
+
objref:
294
+
kind: Certificate
295
+
group: cert-manager.io
296
+
version: v1alpha2
297
+
name: serving-cert # this name should match the one in certificate.yaml
298
+
fieldref:
299
+
fieldpath: metadata.namespace
300
+
- name: CERTIFICATE_NAME
301
+
objref:
302
+
kind: Certificate
303
+
group: cert-manager.io
304
+
version: v1alpha2
305
+
name: serving-cert # this name should match the one in certificate.yaml
306
+
- name: SERVICE_NAMESPACE # namespace of the service
307
+
objref:
308
+
kind: Service
309
+
version: v1
310
+
name: webhook-service
311
+
fieldref:
312
+
fieldpath: metadata.namespace
313
+
- name: SERVICE_NAME
314
+
objref:
315
+
kind: Service
316
+
version: v1
317
+
name: webhook-service
318
+
```
319
+
- **manager_webhook_patch.yaml**
320
+
- Under `containers` find `manager` and add after `name`
321
+
```yaml
322
+
- "--metrics-addr=127.0.0.1:8080"
323
+
- "--webhook-port=9443"
324
+
```
325
+
- Under `volumes` find `cert` and replace `secretName`'s value with `$(SERVICE_NAME)-cert`.
326
+
- **service.yaml**
327
+
- Remove the `selector` map, if any. The `control-plane` label is not needed anymore, a unique label is applied using `commonLabels` under `config/kustomization.yaml`.
328
+
329
+
In `main.go`
330
+
- Default the `webhook-port` flag to `0`
331
+
```go
332
+
flag.IntVar(&webhookPort, "webhook-port", 0,
333
+
"Webhook Server port, disabled by default. When enabled, the manager will only work as webhook server, no reconcilers are installed.")
334
+
```
335
+
- The controller MUST register reconcilers if and only if `webhookPort == 0`.
336
+
- The controller MUST register webhooks if and only if `webhookPort != 0`.
337
+
338
+
After all the changes above are performed, `kustomize build` MUST target `config/`, rather than `config/default`. Using your favorite editor, search for `config/default` in your repository and change the paths accordingly.
339
+
340
+
In addition, often the `Makefile` contains a sed-replacement for `manager_image_patch.yaml`, this file has been moved from `config/default` to `config/manager`. Using your favorite editor, search for `manager_image_patch` in your repository and change the paths accordingly.
0 commit comments