Skip to content

Commit 46e045c

Browse files
authored
Merge pull request #8820 from willie-yao/cc-mp-api
✨ Update API with ClusterClass MachinePool support
2 parents 6dc0819 + 1b4af03 commit 46e045c

9 files changed

+1008
-23
lines changed

api/v1alpha4/conversion.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
7373
dst.Spec.Topology.Workers.MachineDeployments[i].Strategy = restored.Spec.Topology.Workers.MachineDeployments[i].Strategy
7474
dst.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck
7575
}
76+
77+
dst.Spec.Topology.Workers.MachinePools = restored.Spec.Topology.Workers.MachinePools
7678
}
7779
}
7880

@@ -125,6 +127,7 @@ func (src *ClusterClass) ConvertTo(dstRaw conversion.Hub) error {
125127
dst.Spec.ControlPlane.NodeDrainTimeout = restored.Spec.ControlPlane.NodeDrainTimeout
126128
dst.Spec.ControlPlane.NodeVolumeDetachTimeout = restored.Spec.ControlPlane.NodeVolumeDetachTimeout
127129
dst.Spec.ControlPlane.NodeDeletionTimeout = restored.Spec.ControlPlane.NodeDeletionTimeout
130+
dst.Spec.Workers.MachinePools = restored.Spec.Workers.MachinePools
128131

129132
for i := range restored.Spec.Workers.MachineDeployments {
130133
dst.Spec.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Workers.MachineDeployments[i].MachineHealthCheck
@@ -375,3 +378,13 @@ func Convert_v1beta1_ClusterClass_To_v1alpha4_ClusterClass(in *clusterv1.Cluster
375378
// ClusterClass.Status has been added in v1beta1.
376379
return autoConvert_v1beta1_ClusterClass_To_v1alpha4_ClusterClass(in, out, s)
377380
}
381+
382+
func Convert_v1beta1_WorkersClass_To_v1alpha4_WorkersClass(in *clusterv1.WorkersClass, out *WorkersClass, s apiconversion.Scope) error {
383+
// WorkersClass.MachinePools has been added in v1beta1.
384+
return autoConvert_v1beta1_WorkersClass_To_v1alpha4_WorkersClass(in, out, s)
385+
}
386+
387+
func Convert_v1beta1_WorkersTopology_To_v1alpha4_WorkersTopology(in *clusterv1.WorkersTopology, out *WorkersTopology, s apiconversion.Scope) error {
388+
// WorkersTopology.MachinePools has been added in v1beta1.
389+
return autoConvert_v1beta1_WorkersTopology_To_v1alpha4_WorkersTopology(in, out, s)
390+
}

api/v1alpha4/zz_generated.conversion.go

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

api/v1beta1/cluster_types.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ type WorkersTopology struct {
149149
// MachineDeployments is a list of machine deployments in the cluster.
150150
// +optional
151151
MachineDeployments []MachineDeploymentTopology `json:"machineDeployments,omitempty"`
152+
153+
// MachinePools is a list of machine pools in the cluster.
154+
// +optional
155+
MachinePools []MachinePoolTopology `json:"machinePools,omitempty"`
152156
}
153157

154158
// MachineDeploymentTopology specifies the different parameters for a set of worker nodes in the topology.
@@ -240,6 +244,66 @@ type MachineHealthCheckTopology struct {
240244
MachineHealthCheckClass `json:",inline"`
241245
}
242246

247+
// MachinePoolTopology specifies the different parameters for a pool of worker nodes in the topology.
248+
// This pool of nodes is managed by a MachinePool object whose lifecycle is managed by the Cluster controller.
249+
type MachinePoolTopology struct {
250+
// Metadata is the metadata applied to the MachinePool.
251+
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
252+
// +optional
253+
Metadata ObjectMeta `json:"metadata,omitempty"`
254+
255+
// Class is the name of the MachinePoolClass used to create the pool of worker nodes.
256+
// This should match one of the deployment classes defined in the ClusterClass object
257+
// mentioned in the `Cluster.Spec.Class` field.
258+
Class string `json:"class"`
259+
260+
// Name is the unique identifier for this MachinePoolTopology.
261+
// The value is used with other unique identifiers to create a MachinePool's Name
262+
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
263+
// the values are hashed together.
264+
Name string `json:"name"`
265+
266+
// FailureDomains is the list of failure domains the machine pool will be created in.
267+
// Must match a key in the FailureDomains map stored on the cluster object.
268+
// +optional
269+
FailureDomains []string `json:"failureDomains,omitempty"`
270+
271+
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
272+
// The default value is 0, meaning that the node can be drained without any time limitations.
273+
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
274+
// +optional
275+
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
276+
277+
// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
278+
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
279+
// +optional
280+
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`
281+
282+
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the MachinePool
283+
// hosts after the MachinePool is marked for deletion. A duration of 0 will retry deletion indefinitely.
284+
// Defaults to 10 seconds.
285+
// +optional
286+
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
287+
288+
// Minimum number of seconds for which a newly created machine pool should
289+
// be ready.
290+
// Defaults to 0 (machine will be considered available as soon as it
291+
// is ready)
292+
// +optional
293+
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
294+
295+
// Replicas is the number of nodes belonging to this pool.
296+
// If the value is nil, the MachinePool is created without the number of Replicas (defaulting to 1)
297+
// and it's assumed that an external entity (like cluster autoscaler) is responsible for the management
298+
// of this value.
299+
// +optional
300+
Replicas *int32 `json:"replicas,omitempty"`
301+
302+
// Variables can be used to customize the MachinePool through patches.
303+
// +optional
304+
Variables *MachinePoolVariables `json:"variables,omitempty"`
305+
}
306+
243307
// ClusterVariable can be used to customize the Cluster through patches. Each ClusterVariable is associated with a
244308
// Variable definition in the ClusterClass `status` variables.
245309
type ClusterVariable struct {
@@ -270,6 +334,13 @@ type MachineDeploymentVariables struct {
270334
Overrides []ClusterVariable `json:"overrides,omitempty"`
271335
}
272336

337+
// MachinePoolVariables can be used to provide variables for a specific MachinePool.
338+
type MachinePoolVariables struct {
339+
// Overrides can be used to override Cluster level variables.
340+
// +optional
341+
Overrides []ClusterVariable `json:"overrides,omitempty"`
342+
}
343+
273344
// ANCHOR_END: ClusterSpec
274345

275346
// ANCHOR: ClusterNetwork

api/v1beta1/clusterclass_types.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ type WorkersClass struct {
133133
// a set of worker nodes.
134134
// +optional
135135
MachineDeployments []MachineDeploymentClass `json:"machineDeployments,omitempty"`
136+
137+
// MachinePools is a list of machine pool classes that can be used to create
138+
// a set of worker nodes.
139+
// +optional
140+
MachinePools []MachinePoolClass `json:"machinePools,omitempty"`
136141
}
137142

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

252+
// MachinePoolClass serves as a template to define a pool of worker nodes of the cluster
253+
// provisioned using `ClusterClass`.
254+
type MachinePoolClass struct {
255+
// Class denotes a type of machine pool present in the cluster,
256+
// this name MUST be unique within a ClusterClass and can be referenced
257+
// in the Cluster to create a managed MachinePool.
258+
Class string `json:"class"`
259+
260+
// Template is a local struct containing a collection of templates for creation of
261+
// MachinePools objects representing a pool of worker nodes.
262+
Template MachinePoolClassTemplate `json:"template"`
263+
264+
// FailureDomains is the list of failure domains the MachinePool should be attached to.
265+
// Must match a key in the FailureDomains map stored on the cluster object.
266+
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachinePoolClass.
267+
// +optional
268+
FailureDomains []string `json:"failureDomains,omitempty"`
269+
270+
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
271+
// The default value is 0, meaning that the node can be drained without any time limitations.
272+
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
273+
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachinePoolClass.
274+
// +optional
275+
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
276+
277+
// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
278+
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
279+
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachinePoolClass.
280+
// +optional
281+
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`
282+
283+
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine
284+
// hosts after the Machine Pool is marked for deletion. A duration of 0 will retry deletion indefinitely.
285+
// Defaults to 10 seconds.
286+
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachinePoolClass.
287+
// +optional
288+
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
289+
290+
// Minimum number of seconds for which a newly created machine pool should
291+
// be ready.
292+
// Defaults to 0 (machine will be considered available as soon as it
293+
// is ready)
294+
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachinePoolClass.
295+
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
296+
}
297+
298+
// MachinePoolClassTemplate defines how a MachinePool generated from a MachinePoolClass
299+
// should look like.
300+
type MachinePoolClassTemplate struct {
301+
// Metadata is the metadata applied to the MachinePool.
302+
// At runtime this metadata is merged with the corresponding metadata from the topology.
303+
// +optional
304+
Metadata ObjectMeta `json:"metadata,omitempty"`
305+
306+
// Bootstrap contains the bootstrap template reference to be used
307+
// for the creation of the Machines in the MachinePool.
308+
Bootstrap LocalObjectTemplate `json:"bootstrap"`
309+
310+
// Infrastructure contains the infrastructure template reference to be used
311+
// for the creation of the MachinePool.
312+
Infrastructure LocalObjectTemplate `json:"infrastructure"`
313+
}
314+
247315
// IsZero returns true if none of the values of MachineHealthCheckClass are defined.
248316
func (m MachineHealthCheckClass) IsZero() bool {
249317
return reflect.ValueOf(m).IsZero()
@@ -472,6 +540,11 @@ type PatchSelectorMatch struct {
472540
// .spec.workers.machineDeployments.
473541
// +optional
474542
MachineDeploymentClass *PatchSelectorMatchMachineDeploymentClass `json:"machineDeploymentClass,omitempty"`
543+
544+
// MachinePoolClass selects templates referenced in specific MachinePoolClasses in
545+
// .spec.workers.machinePools.
546+
// +optional
547+
MachinePoolClass *PatchSelectorMatchMachinePoolClass `json:"machinePoolClass,omitempty"`
475548
}
476549

477550
// PatchSelectorMatchMachineDeploymentClass selects templates referenced
@@ -482,6 +555,14 @@ type PatchSelectorMatchMachineDeploymentClass struct {
482555
Names []string `json:"names,omitempty"`
483556
}
484557

558+
// PatchSelectorMatchMachinePoolClass selects templates referenced
559+
// in specific MachinePoolClasses in .spec.workers.machinePools.
560+
type PatchSelectorMatchMachinePoolClass struct {
561+
// Names selects templates by class names.
562+
// +optional
563+
Names []string `json:"names,omitempty"`
564+
}
565+
485566
// JSONPatch defines a JSON patch.
486567
type JSONPatch struct {
487568
// Op defines the operation of the patch.

api/v1beta1/common_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const (
5757
// a classy Cluster to define the maximum concurrency while upgrading MachineDeployments.
5858
ClusterTopologyUpgradeConcurrencyAnnotation = "topology.cluster.x-k8s.io/upgrade-concurrency"
5959

60+
// ClusterTopologyMachinePoolNameLabel is the label set on the generated MachinePool objects
61+
// to track the name of the MachinePool topology it represents.
62+
ClusterTopologyMachinePoolNameLabel = "topology.cluster.x-k8s.io/pool-name"
63+
6064
// ClusterTopologyUnsafeUpdateClassNameAnnotation can be used to disable the webhook check on
6165
// update that disallows a pre-existing Cluster to be populated with Topology information and Class.
6266
ClusterTopologyUnsafeUpdateClassNameAnnotation = "unsafe.topology.cluster.x-k8s.io/disable-update-class-name-check"

0 commit comments

Comments
 (0)