Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion api/v1alpha4/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ClusterClassSpec struct {

// ControlPlane is a reference to a local struct that holds the details
// for provisioning the Control Plane for the Cluster.
ControlPlane LocalObjectTemplate `json:"controlPlane,omitempty"`
ControlPlane ControlPlaneClass `json:"controlPlane,omitempty"`

// Workers describes the worker nodes for the cluster.
// It is a collection of node types which can be used to create
Expand All @@ -53,6 +53,23 @@ type ClusterClassSpec struct {
Workers WorkersClass `json:"workers,omitempty"`
}

// ControlPlaneClass defines the class for the control plane.
type ControlPlaneClass struct {
Metadata ObjectMeta `json:"metadata,omitempty"`

// LocalObjectTemplate contains the reference to the control plane provider.
LocalObjectTemplate `json:",inline"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am probably missing something but the LocalObjectTemplate we have here refs to a ControlPlaneTemplate (Ex: KubeadmControlPlaneTemplate - will be introduced in #4904 ).

This ControlPlaneTemplate will internally refer to a machine infrastructure, isnt it?
Going back the kcp template example we have a machine infra ref at kcptemplate.spec.template.spec.machineTemplate.infrastructureRef. How is this different from the new MachineInfrastructure field?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho both will reference the same InfrastructureMachineTemplate. This PR makes it explicit on the ClusterClass (i.e. you have to set the ref on the ClusterClass and inside the ControlPlaneTemplate)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, we are making this explicit;
Also, according to the initial work on #5002, ClusterClass is always going to set the reference inside the ControlPlaneTemplate, so it is not required to set it in both places upfront

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that fits for my PR as I assume that the ref can be unset in the ControlPlane even if it is set in the ClusterClass.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClusterClass is always going to set the reference inside the ControlPlaneTemplate, so it is not required to set it in both places upfront

Good to know that we are doing this, however the kcptemplate.spec.template.spec.machineTemplate.infrastructureRef is not an optional field. So are we expecting that the user set the filed both inside the ControlPlaneTemplate and inside the ClusterClass definition and also that both the fields point to the same thing?
We should throw an error incase they dont match, is it?


// MachineTemplate defines the metadata and infrastructure information
// for control plane machines.
//
// This field is supported if and only if the control plane provider template
// referenced above is Machine based and supports setting replicas.
//
// +optional
MachineInfrastructure *LocalObjectTemplate `json:"machineInfrastructure,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
106 changes: 77 additions & 29 deletions api/v1alpha4/clusterclass_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func TestClusterClassDefaultNamespaces(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down Expand Up @@ -96,7 +98,9 @@ func TestClusterClassValidationFeatureGated(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -120,7 +124,9 @@ func TestClusterClassValidationFeatureGated(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -140,7 +146,9 @@ func TestClusterClassValidationFeatureGated(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down Expand Up @@ -202,7 +210,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down Expand Up @@ -233,7 +243,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: refInAnotherNamespace},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -257,7 +269,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: refInAnotherNamespace},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: refInAnotherNamespace},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -281,7 +295,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -305,7 +321,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -329,7 +347,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down Expand Up @@ -360,7 +380,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -380,7 +402,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -405,7 +429,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -431,7 +457,9 @@ func TestClusterClassValidation(t *testing.T) {
Name: "bazx",
Namespace: "default",
}},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -456,7 +484,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -477,12 +507,14 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: &corev1.ObjectReference{
APIVersion: "foox",
Kind: "barx",
Name: "bazx",
Namespace: "default",
}},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: &corev1.ObjectReference{
APIVersion: "foox",
Kind: "barx",
Name: "bazx",
Namespace: "default",
}},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -507,7 +539,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -528,7 +562,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down Expand Up @@ -558,7 +594,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -578,7 +616,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down Expand Up @@ -609,7 +649,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -629,7 +671,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down Expand Up @@ -660,7 +704,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand All @@ -687,7 +733,9 @@ func TestClusterClassValidation(t *testing.T) {
},
Spec: ClusterClassSpec{
Infrastructure: LocalObjectTemplate{Ref: ref},
ControlPlane: LocalObjectTemplate{Ref: ref},
ControlPlane: ControlPlaneClass{
LocalObjectTemplate: LocalObjectTemplate{Ref: ref},
},
Workers: WorkersClass{
MachineDeployments: []MachineDeploymentClass{
{
Expand Down
22 changes: 22 additions & 0 deletions api/v1alpha4/zz_generated.deepcopy.go

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

Loading