Skip to content

Commit 2502f5c

Browse files
authored
Merge pull request #7298 from sbueringer/pr-doc-upgrade-capi-cc
📖 book: add doc about Cluster API updates with ClusterClass
2 parents dca818a + e9db68a commit 2502f5c

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

docs/book/src/tasks/experimental-features/cluster-class/operate-cluster.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A managed Cluster can be used to:
99
* [Add a MachineDeployment](#add-a-machinedeployment)
1010
* [Use variables in a Cluster](#use-variables)
1111
* [Rebase a Cluster to a different ClusterClass](#rebase-a-cluster)
12+
* [Upgrading Cluster API](#upgrading-cluster-api)
1213
* [Tips and tricks](#tips-and-tricks)
1314

1415
## Upgrade a Cluster
@@ -266,6 +267,104 @@ Please note that:
266267

267268
</aside>
268269

270+
# Upgrading Cluster API
271+
272+
There are some special considerations for ClusterClass regarding Cluster API upgrades when the upgrade includes a bump
273+
of the apiVersion of infrastructure, bootstrap or control plane provider CRDs.
274+
275+
The recommended approach is to first upgrade Cluster API and then update the apiVersions in the ClusterClass references afterwards.
276+
By following above steps, there won't be any disruptions of the reconciliation as the Cluster topology controller is able to reconcile the Cluster
277+
even with the old apiVersions in the ClusterClass.
278+
279+
Note: The apiVersions in ClusterClass cannot be updated before Cluster API because the new apiVersions don't exist in
280+
the management cluster before the Cluster API upgrade.
281+
282+
In general the Cluster topology controller always uses exactly the versions of the CRDs referenced in the ClusterClass.
283+
This means in the following example the Cluster topology controller will always use `v1beta1` when reconciling/applying
284+
patches for the infrastructure ref, even if the `DockerClusterTemplate` already has a `v1beta2` apiVersion.
285+
286+
```yaml
287+
apiVersion: cluster.x-k8s.io/v1beta1
288+
kind: ClusterClass
289+
metadata:
290+
name: quick-start
291+
namespace: default
292+
spec:
293+
infrastructure:
294+
ref:
295+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
296+
kind: DockerClusterTemplate
297+
...
298+
```
299+
300+
<aside class="note warning">
301+
302+
<h1>Bumping apiVersions in ClusterClass</h1>
303+
304+
When upgrading the apiVersions in references in the ClusterClass the corresponding patches have to be changed accordingly.
305+
This includes bumping the apiVersion in the patch selector and potentially updating the JSON patch to changes in the new
306+
apiVersion of the referenced CRD. The following example shows how to upgrade the ClusterClass in this case.
307+
308+
ClusterClass with the old apiVersion:
309+
```yaml
310+
apiVersion: cluster.x-k8s.io/v1beta1
311+
kind: ClusterClass
312+
metadata:
313+
name: quick-start
314+
spec:
315+
infrastructure:
316+
ref:
317+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
318+
kind: DockerClusterTemplate
319+
...
320+
patches:
321+
- name: lbImageRepository
322+
definitions:
323+
- selector:
324+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
325+
kind: DockerClusterTemplate
326+
matchResources:
327+
infrastructureCluster: true
328+
jsonPatches:
329+
- op: add
330+
path: "/spec/template/spec/loadBalancer/imageRepository"
331+
valueFrom:
332+
variable: lbImageRepository
333+
```
334+
335+
ClusterClass with the new apiVersion:
336+
```yaml
337+
apiVersion: cluster.x-k8s.io/v1beta1
338+
kind: ClusterClass
339+
metadata:
340+
name: quick-start
341+
spec:
342+
infrastructure:
343+
ref:
344+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 # apiVersion updated
345+
kind: DockerClusterTemplate
346+
...
347+
patches:
348+
- name: lbImageRepository
349+
definitions:
350+
- selector:
351+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 # apiVersion updated
352+
kind: DockerClusterTemplate
353+
matchResources:
354+
infrastructureCluster: true
355+
jsonPatches:
356+
- op: add
357+
# Path has been updated, as in this example imageRepository has been renamed
358+
# to imageRepo in v1beta2 of DockerClusterTemplate.
359+
path: "/spec/template/spec/loadBalancer/imageRepo"
360+
valueFrom:
361+
variable: lbImageRepository
362+
```
363+
364+
If external patches are used in the ClusterClass, it has to be ensured that all external patches support the new apiVersion
365+
before bumping apiVersions.
366+
367+
</aside>
269368
270369
[Quick Start guide]: ../../../user/quick-start.md
271370
[ClusterClass rebase]: ./change-clusterclass.md#rebase

docs/book/src/tasks/experimental-features/runtime-sdk/implement-topology-mutation-hook.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,34 @@ function openSwaggerUI() {
188188
window.open("https://editor.swagger.io/?url=" + schemaURL)
189189
}
190190
</script>
191+
192+
## Dealing with Cluster API upgrades with apiVersion bumps
193+
194+
There are some special considerations regarding Cluster API upgrades when the upgrade includes a bump
195+
of the apiVersion of infrastructure, bootstrap or control plane provider CRDs.
196+
197+
When calling external patches the Cluster topology controller is always sending the templates in the apiVersion of the references
198+
in the ClusterClass.
199+
200+
While inline patches are always referring to one specific apiVersion, external patch implementations are more flexible. They can
201+
be written in a way that they are able to handle multiple apiVersions of a CRD. This can be done by calculating patches differently
202+
depending on which apiVersion is received by the external patch implementation.
203+
204+
This allows users more flexibility during Cluster API upgrades:
205+
206+
Variant 1: External patch implementation supporting two apiVersions at the same time
207+
208+
1. Update Cluster API
209+
2. Update the external patch implementation to be able to handle custom resources with the old and the new apiVersion
210+
3. Update the references in ClusterClasses to use the new apiVersion
211+
212+
**Note** In this variant it doesn't matter if Cluster API or the external patch implementation is updated first.
213+
214+
Variant 2: Deploy an additional instance of the external patch implementation which can handle the new apiVersion
215+
216+
1. Upgrade Cluster API
217+
2. Deploy the new external patch implementation which is able to handle the new apiVersion
218+
3. Update ClusterClasses to use the new apiVersion and the new external patch implementation
219+
4. Remove the old external patch implementation as it's not used anymore
220+
221+
**Note** In this variant it doesn't matter if Cluster API is updated or the new external patch implementation is deployed first.

0 commit comments

Comments
 (0)