Skip to content

Commit

Permalink
ClusterClass: Introduce NamingStrategy and allow generating names usi…
Browse files Browse the repository at this point in the history
…ng go templates
  • Loading branch information
chrischdi committed Sep 8, 2023
1 parent 022ccf1 commit ae7c56e
Show file tree
Hide file tree
Showing 15 changed files with 745 additions and 28 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (src *ClusterClass) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Patches = restored.Spec.Patches
dst.Spec.Variables = restored.Spec.Variables
dst.Spec.ControlPlane.MachineHealthCheck = restored.Spec.ControlPlane.MachineHealthCheck
dst.Spec.ControlPlane.NamingStrategy = restored.Spec.ControlPlane.NamingStrategy
dst.Spec.ControlPlane.NodeDrainTimeout = restored.Spec.ControlPlane.NodeDrainTimeout
dst.Spec.ControlPlane.NodeVolumeDetachTimeout = restored.Spec.ControlPlane.NodeVolumeDetachTimeout
dst.Spec.ControlPlane.NodeDeletionTimeout = restored.Spec.ControlPlane.NodeDeletionTimeout
Expand All @@ -132,6 +133,7 @@ func (src *ClusterClass) ConvertTo(dstRaw conversion.Hub) error {
for i := range restored.Spec.Workers.MachineDeployments {
dst.Spec.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Workers.MachineDeployments[i].MachineHealthCheck
dst.Spec.Workers.MachineDeployments[i].FailureDomain = restored.Spec.Workers.MachineDeployments[i].FailureDomain
dst.Spec.Workers.MachineDeployments[i].NamingStrategy = restored.Spec.Workers.MachineDeployments[i].NamingStrategy
dst.Spec.Workers.MachineDeployments[i].NodeDrainTimeout = restored.Spec.Workers.MachineDeployments[i].NodeDrainTimeout
dst.Spec.Workers.MachineDeployments[i].NodeVolumeDetachTimeout = restored.Spec.Workers.MachineDeployments[i].NodeVolumeDetachTimeout
dst.Spec.Workers.MachineDeployments[i].NodeDeletionTimeout = restored.Spec.Workers.MachineDeployments[i].NodeDeletionTimeout
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ type ControlPlaneClass struct {
// +optional
MachineHealthCheck *MachineHealthCheckClass `json:"machineHealthCheck,omitempty"`

// NamingStrategy allows to change the naming pattern used when creating the control plane provider object.
// +optional
NamingStrategy *ControlPlaneClassNamingStrategy `json:"namingStrategy,omitempty"`

// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
Expand All @@ -127,6 +131,19 @@ type ControlPlaneClass struct {
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
}

// ControlPlaneClassNamingStrategy defines the naming strategy for control plane objects.
type ControlPlaneClassNamingStrategy struct {
// Template defines the template to use for generating the name of the ControlPlane object.
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .random }}`.
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
// get concatenated with a random suffix of length 5.
// The templating mechanism provides the following arguments:
// * `.cluster.name`: The name of the cluster object.
// * `.random`: A random alphanumeric string, without vowels, of length 5.
// +optional
Template *string `json:"template,omitempty"`
}

// WorkersClass is a collection of deployment classes.
type WorkersClass struct {
// MachineDeployments is a list of machine deployment classes that can be used to create
Expand Down Expand Up @@ -162,6 +179,10 @@ type MachineDeploymentClass struct {
// +optional
FailureDomain *string `json:"failureDomain,omitempty"`

// NamingStrategy allows to change the naming pattern used when creating the MachineDeployment.
// +optional
NamingStrategy *MachineDeploymentClassNamingStrategy `json:"namingStrategy,omitempty"`

// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
Expand Down Expand Up @@ -212,6 +233,20 @@ type MachineDeploymentClassTemplate struct {
Infrastructure LocalObjectTemplate `json:"infrastructure"`
}

// MachineDeploymentClassNamingStrategy defines the naming strategy for machine deployment objects.
type MachineDeploymentClassNamingStrategy struct {
// Template defines the template to use for generating the name of the MachineDeployment object.
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machineDeployment.topologyName }}-{{ .random }}`.
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
// get concatenated with a random suffix of length 5.
// The templating mechanism provides the following arguments:
// * `.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).
// +optional
Template *string `json:"template,omitempty"`
}

// MachineHealthCheckClass defines a MachineHealthCheck for a group of Machines.
type MachineHealthCheckClass struct {
// UnhealthyConditions contains a list of the conditions that determine
Expand Down Expand Up @@ -267,6 +302,10 @@ type MachinePoolClass struct {
// +optional
FailureDomains []string `json:"failureDomains,omitempty"`

// NamingStrategy allows to change the naming pattern used when creating the MachinePool.
// +optional
NamingStrategy *MachinePoolClassNamingStrategy `json:"namingStrategy,omitempty"`

// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
Expand Down Expand Up @@ -312,6 +351,20 @@ type MachinePoolClassTemplate struct {
Infrastructure LocalObjectTemplate `json:"infrastructure"`
}

// MachinePoolClassNamingStrategy defines the naming strategy for machine pool objects.
type MachinePoolClassNamingStrategy struct {
// Template defines the template to use for generating the name of the MachinePool object.
// If not defined, it will fallback to `{{ .cluster.name }}-{{ .machinePool.topologyName }}-{{ .random }}`.
// If the templated string exceeds 63 characters, it will be trimmed to 58 characters and will
// get concatenated with a random suffix of length 5.
// The templating mechanism provides the following arguments:
// * `.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).
// +optional
Template *string `json:"template,omitempty"`
}

// IsZero returns true if none of the values of MachineHealthCheckClass are defined.
func (m MachineHealthCheckClass) IsZero() bool {
return reflect.ValueOf(m).IsZero()
Expand Down
75 changes: 75 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae7c56e

Please sign in to comment.