Skip to content

Commit a5ada5c

Browse files
committed
ClusterClass: Introduce NamingStrategy and allow generating names using go templates
1 parent 022ccf1 commit a5ada5c

13 files changed

+531
-28
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: 39 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 to change the naming pattern used when creating the control plane provider object.
110+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .random }}`.
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,15 @@ type ControlPlaneClass struct {
127131
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
128132
}
129133

134+
// ControlPlaneClassNamingStrategy defines a naming strategy for templated objects of a ControlPlaneClass.
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+
Template *string `json:"template,omitempty"`
141+
}
142+
130143
// WorkersClass is a collection of deployment classes.
131144
type WorkersClass struct {
132145
// MachineDeployments is a list of machine deployment classes that can be used to create
@@ -162,6 +175,10 @@ type MachineDeploymentClass struct {
162175
// +optional
163176
FailureDomain *string `json:"failureDomain,omitempty"`
164177

178+
// NamingStrategy allows to change the naming pattern used when creating the MachineDeployment.
179+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machineDeployment.topologyName }}-{{ .random }}`.
180+
NamingStrategy *MachineDeploymentClassNamingStrategy `json:"namingStrategy,omitempty"`
181+
165182
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
166183
// The default value is 0, meaning that the node can be drained without any time limitations.
167184
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
@@ -212,6 +229,15 @@ type MachineDeploymentClassTemplate struct {
212229
Infrastructure LocalObjectTemplate `json:"infrastructure"`
213230
}
214231

232+
// MachineDeploymentClassNamingStrategy defines a naming strategy for templated objects of a MachineDeploymentClass.
233+
type MachineDeploymentClassNamingStrategy struct {
234+
// Template defines the template to use for generating the name of the MachineDeployment object.
235+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machineDeployment.topologyName }}-{{ .random }}`.
236+
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
237+
// get concatenated with a random suffix of length 5.
238+
Template *string `json:"template,omitempty"`
239+
}
240+
215241
// MachineHealthCheckClass defines a MachineHealthCheck for a group of Machines.
216242
type MachineHealthCheckClass struct {
217243
// UnhealthyConditions contains a list of the conditions that determine
@@ -267,6 +293,10 @@ type MachinePoolClass struct {
267293
// +optional
268294
FailureDomains []string `json:"failureDomains,omitempty"`
269295

296+
// NamingStrategy allows to change the naming pattern used when creating the MachinePool.
297+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machinePool.topologyName }}-{{ .random }}`.
298+
NamingStrategy *MachinePoolClassNamingStrategy `json:"namingStrategy,omitempty"`
299+
270300
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
271301
// The default value is 0, meaning that the node can be drained without any time limitations.
272302
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
@@ -312,6 +342,15 @@ type MachinePoolClassTemplate struct {
312342
Infrastructure LocalObjectTemplate `json:"infrastructure"`
313343
}
314344

345+
// MachinePoolClassNamingStrategy defines a naming strategy for templated objects of a MachinePoolClass.
346+
type MachinePoolClassNamingStrategy struct {
347+
// Template defines the template to use for generating the name of the MachinePool object.
348+
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machinePool.topologyName }}-{{ .random }}`.
349+
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
350+
// get concatenated with a random suffix of length 5.
351+
Template *string `json:"template,omitempty"`
352+
}
353+
315354
// IsZero returns true if none of the values of MachineHealthCheckClass are defined.
316355
func (m MachineHealthCheckClass) IsZero() bool {
317356
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)