Skip to content

Commit

Permalink
Update API with clusterclass machinepool support
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Case <richard.case@outlook.com>
  • Loading branch information
willie-yao and richardcase committed Jun 7, 2023
1 parent 60b1426 commit e4a2474
Show file tree
Hide file tree
Showing 9 changed files with 799 additions and 23 deletions.
11 changes: 11 additions & 0 deletions api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Topology.Workers.MachineDeployments[i].Strategy = restored.Spec.Topology.Workers.MachineDeployments[i].Strategy
dst.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck
}

dst.Spec.Topology.Workers.MachinePools = restored.Spec.Topology.Workers.MachinePools
}
}

Expand Down Expand Up @@ -125,6 +127,7 @@ func (src *ClusterClass) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.ControlPlane.NodeDrainTimeout = restored.Spec.ControlPlane.NodeDrainTimeout
dst.Spec.ControlPlane.NodeVolumeDetachTimeout = restored.Spec.ControlPlane.NodeVolumeDetachTimeout
dst.Spec.ControlPlane.NodeDeletionTimeout = restored.Spec.ControlPlane.NodeDeletionTimeout
dst.Spec.Workers.MachinePools = restored.Spec.Workers.MachinePools

for i := range restored.Spec.Workers.MachineDeployments {
dst.Spec.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Workers.MachineDeployments[i].MachineHealthCheck
Expand Down Expand Up @@ -375,3 +378,11 @@ func Convert_v1beta1_ClusterClass_To_v1alpha4_ClusterClass(in *clusterv1.Cluster
// ClusterClass.Status has been added in v1beta1.
return autoConvert_v1beta1_ClusterClass_To_v1alpha4_ClusterClass(in, out, s)
}

func Convert_v1beta1_WorkersClass_To_v1alpha4_WorkersClass(in *clusterv1.WorkersClass, out *WorkersClass, s apiconversion.Scope) error {
return autoConvert_v1beta1_WorkersClass_To_v1alpha4_WorkersClass(in, out, s)
}

func Convert_v1beta1_WorkersTopology_To_v1alpha4_WorkersTopology(in *clusterv1.WorkersTopology, out *WorkersTopology, s apiconversion.Scope) error {
return autoConvert_v1beta1_WorkersTopology_To_v1alpha4_WorkersTopology(in, out, s)
}
32 changes: 12 additions & 20 deletions api/v1alpha4/zz_generated.conversion.go

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

47 changes: 47 additions & 0 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ type WorkersTopology struct {
// MachineDeployments is a list of machine deployments in the cluster.
// +optional
MachineDeployments []MachineDeploymentTopology `json:"machineDeployments,omitempty"`

// MachinePools is a list of machine pools in the cluster.
// +optional
MachinePools []MachinePoolTopology `json:"machinePools,omitempty"`
}

// MachineDeploymentTopology specifies the different parameters for a set of worker nodes in the topology.
Expand Down Expand Up @@ -238,6 +242,42 @@ type MachineHealthCheckTopology struct {
MachineHealthCheckClass `json:",inline"`
}

// MachinePoolTopology specifies the different parameters for a pool of worker nodes in the topology.
// This pool of nodes is managed by a MachinePool object whose lifecycle is managed by the Cluster controller.
type MachinePoolTopology struct {
// Metadata is the metadata applied to the MachinePool.
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
// +optional
Metadata ObjectMeta `json:"metadata,omitempty"`

// Class is the name of the MachinePoolClass used to create the pool of worker nodes.
// This should match one of the deployment classes defined in the ClusterClass object
// mentioned in the `Cluster.Spec.Class` field.
Class string `json:"class"`

// Name is the unique identifier for this MachinePoolTopology.
// The value is used with other unique identifiers to create a MachinePool's Name
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
// the values are hashed together.
Name string `json:"name"`

// FailureDomains is the failure domains the machine pool will be created in.
// Must match a key in the FailureDomains map stored on the cluster object.
// +optional
FailureDomains []string `json:"failureDomains,omitempty"`

// Replicas is the number of nodes belonging to this pool.
// If the value is nil, the MachinePool is created without the number of Replicas (defaulting to 1)
// and it's assumed that an external entity (like cluster autoscaler) is responsible for the management
// of this value.
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// Variables can be used to customize the MachinePool through patches.
// +optional
Variables *MachinePoolVariables `json:"variables,omitempty"`
}

// ClusterVariable can be used to customize the Cluster through patches. Each ClusterVariable is associated with a
// Variable definition in the ClusterClass `status` variables.
type ClusterVariable struct {
Expand Down Expand Up @@ -268,6 +308,13 @@ type MachineDeploymentVariables struct {
Overrides []ClusterVariable `json:"overrides,omitempty"`
}

// MachinePoolVariables can be used to provide variables for a specific MachinePool.
type MachinePoolVariables struct {
// Overrides can be used to override Cluster level variables.
// +optional
Overrides []ClusterVariable `json:"overrides,omitempty"`
}

// ANCHOR_END: ClusterSpec

// ANCHOR: ClusterNetwork
Expand Down
52 changes: 52 additions & 0 deletions api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ type WorkersClass struct {
// a set of worker nodes.
// +optional
MachineDeployments []MachineDeploymentClass `json:"machineDeployments,omitempty"`

// MachinePools is a list of machine pool classes that can be used to create
// a set of worker nodes.
// +optional
MachinePools []MachinePoolClass `json:"machinePools,omitempty"`
}

// MachineDeploymentClass serves as a template to define a set of worker nodes of the cluster
Expand Down Expand Up @@ -244,6 +249,40 @@ type MachineHealthCheckClass struct {
RemediationTemplate *corev1.ObjectReference `json:"remediationTemplate,omitempty"`
}

// MachinePoolClass serves as a template to define a pool of worker nodes of the cluster
// provisioned using `ClusterClass`.
type MachinePoolClass struct {
// Class denotes a type of machine pool present in the cluster,
// this name MUST be unique within a ClusterClass and can be referenced
// in the Cluster to create a managed MachinePool.
Class string `json:"class"`

// Template is a local struct containing a collection of templates for creation of
// MachinePools objects representing a pool of worker nodes.
Template MachinePoolClassTemplate `json:"template"`

// FailureDomains is the list of failure domains the MachinePool should be attached to.
// Must match a key in the FailureDomains map stored on the cluster object.
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass.
// +optional
FailureDomains []string `json:"failureDomains,omitempty"`
}

type MachinePoolClassTemplate struct {
// Metadata is the metadata applied to the MachinePool.
// At runtime this metadata is merged with the corresponding metadata from the topology.
// +optional
Metadata ObjectMeta `json:"metadata,omitempty"`

// Bootstrap contains the bootstrap template reference to be used
// for the creation of the Machines in the MachinePool.
Bootstrap LocalObjectTemplate `json:"bootstrap"`

// Infrastructure contains the infrastructure template reference to be used
// for the creation of the MachinePool.
Infrastructure LocalObjectTemplate `json:"infrastructure"`
}

// IsZero returns true if none of the values of MachineHealthCheckClass are defined.
func (m MachineHealthCheckClass) IsZero() bool {
return reflect.ValueOf(m).IsZero()
Expand Down Expand Up @@ -472,6 +511,11 @@ type PatchSelectorMatch struct {
// .spec.workers.machineDeployments.
// +optional
MachineDeploymentClass *PatchSelectorMatchMachineDeploymentClass `json:"machineDeploymentClass,omitempty"`

// MachinePoolClass selects templates referenced in specific MachinePoolClasses in
// .spec.workers.machinePools.
// +optional
MachinePoolClass *PatchSelectorMatchMachinePoolClass `json:"machinePoolClass,omitempty"`
}

// PatchSelectorMatchMachineDeploymentClass selects templates referenced
Expand All @@ -482,6 +526,14 @@ type PatchSelectorMatchMachineDeploymentClass struct {
Names []string `json:"names,omitempty"`
}

// PatchSelectorMatchMachinePoolClass selects templates referenced
// in specific MachinePoolClasses in .spec.workers.machinePools.
type PatchSelectorMatchMachinePoolClass struct {
// Names selects templates by class names.
// +optional
Names []string `json:"names,omitempty"`
}

// JSONPatch defines a JSON patch.
type JSONPatch struct {
// Op defines the operation of the patch.
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const (
// a classy Cluster to define the maximum concurrency while upgrading MachineDeployments.
ClusterTopologyUpgradeConcurrencyAnnotation = "topology.cluster.x-k8s.io/upgrade-concurrency"

// ClusterTopologyMachinePoolNameLabel is the label set on the generated MachinePool objects
// to track the name of the MachinePool topology it represents.
ClusterTopologyMachinePoolNameLabel = "topology.cluster.x-k8s.io/pool-name"

// ClusterTopologyUnsafeUpdateClassNameAnnotation can be used to disable the webhook check on
// update that disallows a pre-existing Cluster to be populated with Topology information and Class.
ClusterTopologyUnsafeUpdateClassNameAnnotation = "unsafe.topology.cluster.x-k8s.io/disable-update-class-name-check"
Expand Down
Loading

0 comments on commit e4a2474

Please sign in to comment.