Skip to content

Commit

Permalink
Merge pull request #9435 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…9433-to-release-1.5

[release-1.5] 📖 add documentation about namingStrategy in ClusterClasses
  • Loading branch information
k8s-ci-robot authored Sep 14, 2023
2 parents 5d27ce3 + ff50343 commit 66f5ad7
Showing 1 changed file with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ flexible enough to be used in as many Clusters as possible by supporting variant
* [Basic ClusterClass](#basic-clusterclass)
* [ClusterClass with MachineHealthChecks](#clusterclass-with-machinehealthchecks)
* [ClusterClass with patches](#clusterclass-with-patches)
* [ClusterClass with custom naming strategies](#clusterclass-with-custom-naming-strategies)
* [Defining a custom naming strategy for ControlPlane objects](#defining-a-custom-naming-strategy-for-controlplane-objects)
* [Defining a custom naming strategy for MachineDeployment objects](#defining-a-custom-naming-strategy-for-machinedeployment-objects)
* [Defining a custom naming strategy for MachinePool objects](#defining-a-custom-naming-strategy-for-machinepool-objects)
* [Advanced features of ClusterClass with patches](#advanced-features-of-clusterclass-with-patches)
* [MachineDeployment variable overrides](#machinedeployment-variable-overrides)
* [Builtin variables](#builtin-variables)
Expand All @@ -18,7 +22,6 @@ flexible enough to be used in as many Clusters as possible by supporting variant
* [Optional patches](#optional-patches)
* [Version-aware patches](#version-aware-patches)
* [JSON patches tips & tricks](#json-patches-tips--tricks)


## Basic ClusterClass

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

</aside>

## ClusterClass with custom naming strategies

The controller needs to generate names for new objects when a Cluster is getting created
from a ClusterClass. These names have to be unique for each namespace. The naming
strategy enables this by concatenating the cluster name with a random suffix.

It is possible to provide a custom template for the name generation of ControlPlane, MachineDeployment
and MachinePool objects.

The generated names must comply with the [RFC 1123](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names) standard.

### Defining a custom naming strategy for ControlPlane objects

The naming strategy for ControlPlane supports the following properties:

- `template`: Custom template which is used when generating the name of the ControlPlane object.

The following variables can be referenced in templates:

- `.cluster.name`: The name of the cluster object.
- `.random`: A random alphanumeric string, without vowels, of length 5.

Example which would match the default behavior:

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: ClusterClass
metadata:
name: docker-clusterclass-v0.1.0
spec:
controlPlane:
...
namingStrategy:
template: "{{ .cluster.name }}-{{ .random }}"
...
```

### Defining a custom naming strategy for MachineDeployment objects

The naming strategy for MachineDeployments supports the following properties:

- `template`: Custom template which is used when generating the name of the MachineDeployment object.

The following variables can be referenced in templates:

- `.cluster.name`: The name of the cluster object.
- `.random`: A random alphanumeric string, without vowels, of length 5.
- `.machineDeployment.topologyName`: The name of the MachineDeployment topology (`Cluster.spec.topology.workers.machineDeployments[].name`)

Example which would match the default behavior:

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: ClusterClass
metadata:
name: docker-clusterclass-v0.1.0
spec:
controlPlane:
...
workers:
machineDeployments:
- class: default-worker
...
namingStrategy:
template: "{{ .cluster.name }}-{{ .machineDeployment.topologyName }}-{{ .random }}"
```

### Defining a custom naming strategy for MachinePool objects

The naming strategy for MachinePools supports the following properties:

- `template`: Custom template which is used when generating the name of the MachinePool object.

The following variables can be referenced in templates:

- `.cluster.name`: The name of the cluster object.
- `.random`: A random alphanumeric string, without vowels, of length 5.
- `.machinePool.topologyName`: The name of the MachinePool topology (`Cluster.spec.topology.workers.machinePools[].name`).

Example which would match the default behavior:

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: ClusterClass
metadata:
name: docker-clusterclass-v0.1.0
spec:
controlPlane:
...
workers:
machinePools:
- class: default-worker
...
namingStrategy:
template: "{{ .cluster.name }}-{{ .machinePool.topologyName }}-{{ .random }}"
```

## Advanced features of ClusterClass with patches

This section will explain more advanced features of ClusterClass patches.
Expand Down

0 comments on commit 66f5ad7

Please sign in to comment.