Skip to content

Commit

Permalink
Align ClusterClass ControlPlane with the rest of the fields
Browse files Browse the repository at this point in the history
This commits introduces ControlPlaneClass and allows users to set
metadata fields for all control plane objects. It also adds fields to
set infrastructure reference for Machine objects and clarifies what
contracts the field expects from the control plane provider.

Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri committed Jul 22, 2021
1 parent ede33e3 commit 509daea
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 39 deletions.
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"`

// 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

0 comments on commit 509daea

Please sign in to comment.