Skip to content

Commit c4e2d67

Browse files
authored
Merge pull request kubernetes-sigs#9433 from chrischdi/pr-topology-namingstrategy-docs
📖 add documentation about namingStrategy in ClusterClasses
2 parents d877050 + 457692a commit c4e2d67

File tree

1 file changed

+101
-1
lines changed

1 file changed

+101
-1
lines changed

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

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ flexible enough to be used in as many Clusters as possible by supporting variant
1010
* [Basic ClusterClass](#basic-clusterclass)
1111
* [ClusterClass with MachineHealthChecks](#clusterclass-with-machinehealthchecks)
1212
* [ClusterClass with patches](#clusterclass-with-patches)
13+
* [ClusterClass with custom naming strategies](#clusterclass-with-custom-naming-strategies)
14+
* [Defining a custom naming strategy for ControlPlane objects](#defining-a-custom-naming-strategy-for-controlplane-objects)
15+
* [Defining a custom naming strategy for MachineDeployment objects](#defining-a-custom-naming-strategy-for-machinedeployment-objects)
16+
* [Defining a custom naming strategy for MachinePool objects](#defining-a-custom-naming-strategy-for-machinepool-objects)
1317
* [Advanced features of ClusterClass with patches](#advanced-features-of-clusterclass-with-patches)
1418
* [MachineDeployment variable overrides](#machinedeployment-variable-overrides)
1519
* [Builtin variables](#builtin-variables)
@@ -18,7 +22,6 @@ flexible enough to be used in as many Clusters as possible by supporting variant
1822
* [Optional patches](#optional-patches)
1923
* [Version-aware patches](#version-aware-patches)
2024
* [JSON patches tips & tricks](#json-patches-tips--tricks)
21-
2225

2326
## Basic ClusterClass
2427

@@ -289,6 +292,103 @@ a default value, the value is automatically added to the variables list.
289292

290293
</aside>
291294

295+
## ClusterClass with custom naming strategies
296+
297+
The controller needs to generate names for new objects when a Cluster is getting created
298+
from a ClusterClass. These names have to be unique for each namespace. The naming
299+
strategy enables this by concatenating the cluster name with a random suffix.
300+
301+
It is possible to provide a custom template for the name generation of ControlPlane, MachineDeployment
302+
and MachinePool objects.
303+
304+
The generated names must comply with the [RFC 1123](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names) standard.
305+
306+
### Defining a custom naming strategy for ControlPlane objects
307+
308+
The naming strategy for ControlPlane supports the following properties:
309+
310+
- `template`: Custom template which is used when generating the name of the ControlPlane object.
311+
312+
The following variables can be referenced in templates:
313+
314+
- `.cluster.name`: The name of the cluster object.
315+
- `.random`: A random alphanumeric string, without vowels, of length 5.
316+
317+
Example which would match the default behavior:
318+
319+
```yaml
320+
apiVersion: cluster.x-k8s.io/v1beta1
321+
kind: ClusterClass
322+
metadata:
323+
name: docker-clusterclass-v0.1.0
324+
spec:
325+
controlPlane:
326+
...
327+
namingStrategy:
328+
template: "{{ .cluster.name }}-{{ .random }}"
329+
...
330+
```
331+
332+
### Defining a custom naming strategy for MachineDeployment objects
333+
334+
The naming strategy for MachineDeployments supports the following properties:
335+
336+
- `template`: Custom template which is used when generating the name of the MachineDeployment object.
337+
338+
The following variables can be referenced in templates:
339+
340+
- `.cluster.name`: The name of the cluster object.
341+
- `.random`: A random alphanumeric string, without vowels, of length 5.
342+
- `.machineDeployment.topologyName`: The name of the MachineDeployment topology (`Cluster.spec.topology.workers.machineDeployments[].name`)
343+
344+
Example which would match the default behavior:
345+
346+
```yaml
347+
apiVersion: cluster.x-k8s.io/v1beta1
348+
kind: ClusterClass
349+
metadata:
350+
name: docker-clusterclass-v0.1.0
351+
spec:
352+
controlPlane:
353+
...
354+
workers:
355+
machineDeployments:
356+
- class: default-worker
357+
...
358+
namingStrategy:
359+
template: "{{ .cluster.name }}-{{ .machineDeployment.topologyName }}-{{ .random }}"
360+
```
361+
362+
### Defining a custom naming strategy for MachinePool objects
363+
364+
The naming strategy for MachinePools supports the following properties:
365+
366+
- `template`: Custom template which is used when generating the name of the MachinePool object.
367+
368+
The following variables can be referenced in templates:
369+
370+
- `.cluster.name`: The name of the cluster object.
371+
- `.random`: A random alphanumeric string, without vowels, of length 5.
372+
- `.machinePool.topologyName`: The name of the MachinePool topology (`Cluster.spec.topology.workers.machinePools[].name`).
373+
374+
Example which would match the default behavior:
375+
376+
```yaml
377+
apiVersion: cluster.x-k8s.io/v1beta1
378+
kind: ClusterClass
379+
metadata:
380+
name: docker-clusterclass-v0.1.0
381+
spec:
382+
controlPlane:
383+
...
384+
workers:
385+
machinePools:
386+
- class: default-worker
387+
...
388+
namingStrategy:
389+
template: "{{ .cluster.name }}-{{ .machinePool.topologyName }}-{{ .random }}"
390+
```
391+
292392
## Advanced features of ClusterClass with patches
293393

294394
This section will explain more advanced features of ClusterClass patches.

0 commit comments

Comments
 (0)