Skip to content

Commit 49e7f68

Browse files
authored
Merge pull request #9340 from chrischdi/pr-topology-namestrategy
✨ ClusterClass: Introduce NamingStrategy and allow generating names using go templates
2 parents e92e712 + e58176d commit 49e7f68

15 files changed

+825
-30
lines changed

api/v1alpha4/conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func (src *ClusterClass) ConvertTo(dstRaw conversion.Hub) error {
124124
dst.Spec.Patches = restored.Spec.Patches
125125
dst.Spec.Variables = restored.Spec.Variables
126126
dst.Spec.ControlPlane.MachineHealthCheck = restored.Spec.ControlPlane.MachineHealthCheck
127+
dst.Spec.ControlPlane.NamingStrategy = restored.Spec.ControlPlane.NamingStrategy
127128
dst.Spec.ControlPlane.NodeDrainTimeout = restored.Spec.ControlPlane.NodeDrainTimeout
128129
dst.Spec.ControlPlane.NodeVolumeDetachTimeout = restored.Spec.ControlPlane.NodeVolumeDetachTimeout
129130
dst.Spec.ControlPlane.NodeDeletionTimeout = restored.Spec.ControlPlane.NodeDeletionTimeout
@@ -132,6 +133,7 @@ func (src *ClusterClass) ConvertTo(dstRaw conversion.Hub) error {
132133
for i := range restored.Spec.Workers.MachineDeployments {
133134
dst.Spec.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Workers.MachineDeployments[i].MachineHealthCheck
134135
dst.Spec.Workers.MachineDeployments[i].FailureDomain = restored.Spec.Workers.MachineDeployments[i].FailureDomain
136+
dst.Spec.Workers.MachineDeployments[i].NamingStrategy = restored.Spec.Workers.MachineDeployments[i].NamingStrategy
135137
dst.Spec.Workers.MachineDeployments[i].NodeDrainTimeout = restored.Spec.Workers.MachineDeployments[i].NodeDrainTimeout
136138
dst.Spec.Workers.MachineDeployments[i].NodeVolumeDetachTimeout = restored.Spec.Workers.MachineDeployments[i].NodeVolumeDetachTimeout
137139
dst.Spec.Workers.MachineDeployments[i].NodeDeletionTimeout = restored.Spec.Workers.MachineDeployments[i].NodeDeletionTimeout

api/v1alpha4/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/clusterclass_types.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ type ControlPlaneClass struct {
106106
// +optional
107107
MachineHealthCheck *MachineHealthCheckClass `json:"machineHealthCheck,omitempty"`
108108

109+
// NamingStrategy allows changing the naming pattern used when creating the control plane provider object.
110+
// +optional
111+
NamingStrategy *ControlPlaneClassNamingStrategy `json:"namingStrategy,omitempty"`
112+
109113
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
110114
// The default value is 0, meaning that the node can be drained without any time limitations.
111115
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
@@ -127,6 +131,19 @@ type ControlPlaneClass struct {
127131
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
128132
}
129133

134+
// ControlPlaneClassNamingStrategy defines the naming strategy for control plane objects.
135+
type ControlPlaneClassNamingStrategy struct {
136+
// Template defines the template to use for generating the name of the ControlPlane object.
137+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .random }}`.
138+
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
139+
// get concatenated with a random suffix of length 5.
140+
// The templating mechanism provides the following arguments:
141+
// * `.cluster.name`: The name of the cluster object.
142+
// * `.random`: A random alphanumeric string, without vowels, of length 5.
143+
// +optional
144+
Template *string `json:"template,omitempty"`
145+
}
146+
130147
// WorkersClass is a collection of deployment classes.
131148
type WorkersClass struct {
132149
// MachineDeployments is a list of machine deployment classes that can be used to create
@@ -162,6 +179,10 @@ type MachineDeploymentClass struct {
162179
// +optional
163180
FailureDomain *string `json:"failureDomain,omitempty"`
164181

182+
// NamingStrategy allows changing the naming pattern used when creating the MachineDeployment.
183+
// +optional
184+
NamingStrategy *MachineDeploymentClassNamingStrategy `json:"namingStrategy,omitempty"`
185+
165186
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
166187
// The default value is 0, meaning that the node can be drained without any time limitations.
167188
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
@@ -212,6 +233,20 @@ type MachineDeploymentClassTemplate struct {
212233
Infrastructure LocalObjectTemplate `json:"infrastructure"`
213234
}
214235

236+
// MachineDeploymentClassNamingStrategy defines the naming strategy for machine deployment objects.
237+
type MachineDeploymentClassNamingStrategy struct {
238+
// Template defines the template to use for generating the name of the MachineDeployment object.
239+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machineDeployment.topologyName }}-{{ .random }}`.
240+
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
241+
// get concatenated with a random suffix of length 5.
242+
// The templating mechanism provides the following arguments:
243+
// * `.cluster.name`: The name of the cluster object.
244+
// * `.random`: A random alphanumeric string, without vowels, of length 5.
245+
// * `.machineDeployment.topologyName`: The name of the MachineDeployment topology (Cluster.spec.topology.workers.machineDeployments[].name).
246+
// +optional
247+
Template *string `json:"template,omitempty"`
248+
}
249+
215250
// MachineHealthCheckClass defines a MachineHealthCheck for a group of Machines.
216251
type MachineHealthCheckClass struct {
217252
// UnhealthyConditions contains a list of the conditions that determine
@@ -267,6 +302,10 @@ type MachinePoolClass struct {
267302
// +optional
268303
FailureDomains []string `json:"failureDomains,omitempty"`
269304

305+
// NamingStrategy allows changing the naming pattern used when creating the MachinePool.
306+
// +optional
307+
NamingStrategy *MachinePoolClassNamingStrategy `json:"namingStrategy,omitempty"`
308+
270309
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
271310
// The default value is 0, meaning that the node can be drained without any time limitations.
272311
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
@@ -312,6 +351,20 @@ type MachinePoolClassTemplate struct {
312351
Infrastructure LocalObjectTemplate `json:"infrastructure"`
313352
}
314353

354+
// MachinePoolClassNamingStrategy defines the naming strategy for machine pool objects.
355+
type MachinePoolClassNamingStrategy struct {
356+
// Template defines the template to use for generating the name of the MachinePool object.
357+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machinePool.topologyName }}-{{ .random }}`.
358+
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
359+
// get concatenated with a random suffix of length 5.
360+
// The templating mechanism provides the following arguments:
361+
// * `.cluster.name`: The name of the cluster object.
362+
// * `.random`: A random alphanumeric string, without vowels, of length 5.
363+
// * `.machinePool.topologyName`: The name of the MachinePool topology (Cluster.spec.topology.workers.machinePools[].name).
364+
// +optional
365+
Template *string `json:"template,omitempty"`
366+
}
367+
315368
// IsZero returns true if none of the values of MachineHealthCheckClass are defined.
316369
func (m MachineHealthCheckClass) IsZero() bool {
317370
return reflect.ValueOf(m).IsZero()

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)