Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Sep 5, 2023
1 parent 141c721 commit ce54853
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 39 deletions.
29 changes: 6 additions & 23 deletions internal/controllers/topology/cluster/blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func TestGetBlueprint(t *testing.T) {
Template: controlPlaneTemplate,
},
MachineDeployments: map[string]*scope.MachineDeploymentBlueprint{},
MachinePools: map[string]*scope.MachinePoolBlueprint{},
},
},
{
Expand All @@ -177,6 +178,7 @@ func TestGetBlueprint(t *testing.T) {
InfrastructureMachineTemplate: controlPlaneInfrastructureMachineTemplate,
},
MachineDeployments: map[string]*scope.MachineDeploymentBlueprint{},
MachinePools: map[string]*scope.MachinePoolBlueprint{},
},
},
{
Expand Down Expand Up @@ -227,6 +229,7 @@ func TestGetBlueprint(t *testing.T) {
MachineHealthCheck: machineHealthCheck,
},
},
MachinePools: map[string]*scope.MachinePoolBlueprint{},
},
},
{
Expand Down Expand Up @@ -286,28 +289,7 @@ func TestGetBlueprint(t *testing.T) {
MachineHealthCheck: machineHealthCheck,
},
MachineDeployments: map[string]*scope.MachineDeploymentBlueprint{},
},
},
{
name: "Should read a ClusterClass without mp worker classes",
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
WithInfrastructureClusterTemplate(infraClusterTemplate).
WithControlPlaneTemplate(controlPlaneTemplate).
Build(),
objects: []client.Object{
infraClusterTemplate,
controlPlaneTemplate,
},
want: &scope.ClusterBlueprint{
ClusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
WithInfrastructureClusterTemplate(infraClusterTemplate).
WithControlPlaneTemplate(controlPlaneTemplate).
Build(),
InfrastructureClusterTemplate: infraClusterTemplate,
ControlPlane: &scope.ControlPlaneBlueprint{
Template: controlPlaneTemplate,
},
MachinePools: map[string]*scope.MachinePoolBlueprint{},
MachinePools: map[string]*scope.MachinePoolBlueprint{},
},
},
{
Expand All @@ -333,8 +315,9 @@ func TestGetBlueprint(t *testing.T) {
ControlPlane: &scope.ControlPlaneBlueprint{
Template: controlPlaneTemplate,
},
MachineDeployments: map[string]*scope.MachineDeploymentBlueprint{},
MachinePools: map[string]*scope.MachinePoolBlueprint{
"workerclass1": {
"workerclass2": {
Metadata: clusterv1.ObjectMeta{
Labels: map[string]string{"foo": "bar"},
Annotations: map[string]string{"a": "b"},
Expand Down
34 changes: 23 additions & 11 deletions internal/controllers/topology/cluster/current_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,27 @@ func TestGetCurrentState(t *testing.T) {
// MachinePool and related objects.
emptyMachinePools := make(map[string]*scope.MachinePoolState)

machinePoolInfrastructure := builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra1").
machinePoolInfrastructure := builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra2").
Build()
machinePoolInfrastructure.SetLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""})
machinePoolBootstrap := builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").
machinePoolBootstrap := builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap2").
Build()
machinePoolBootstrap.SetLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""})

machinePool := builder.MachinePool(metav1.NamespaceDefault, "md1").
machinePool := builder.MachinePool(metav1.NamespaceDefault, "mp1").
WithLabels(map[string]string{
clusterv1.ClusterNameLabel: "cluster1",
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachinePoolNameLabel: "md1",
clusterv1.ClusterTopologyMachinePoolNameLabel: "mp1",
}).
WithBootstrapTemplate(machinePoolBootstrap).
WithInfrastructureTemplate(machinePoolInfrastructure).
Build()
machinePool2 := builder.MachinePool(metav1.NamespaceDefault, "md2").
machinePool2 := builder.MachinePool(metav1.NamespaceDefault, "mp2").
WithLabels(map[string]string{
clusterv1.ClusterNameLabel: "cluster1",
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachinePoolNameLabel: "md2",
clusterv1.ClusterTopologyMachinePoolNameLabel: "mp2",
}).
WithBootstrapTemplate(machinePoolBootstrap).
WithInfrastructureTemplate(machinePoolInfrastructure).
Expand Down Expand Up @@ -442,6 +442,10 @@ func TestGetCurrentState(t *testing.T) {
Class: "mdClass",
Name: "md1",
}).
WithMachinePool(clusterv1.MachinePoolTopology{
Class: "mpClass",
Name: "mp1",
}).
Build()).
Build(),
ControlPlane: &scope.ControlPlaneState{},
Expand Down Expand Up @@ -655,8 +659,6 @@ func TestGetCurrentState(t *testing.T) {
Class: "mdClass",
Name: "md1",
}).
Build()).
WithTopology(builder.ClusterTopology().
WithMachinePool(clusterv1.MachinePoolTopology{
Class: "mpClass",
Name: "mp1",
Expand Down Expand Up @@ -691,8 +693,11 @@ func TestGetCurrentState(t *testing.T) {
machineDeploymentInfrastructure,
machineDeploymentBootstrap,
machineDeployment,
machinePoolInfrastructure,
machinePoolBootstrap,
machinePool,
},
// Expect valid return of full ClusterState with MachineDeployments properly filtered by label.
// Expect valid return of full ClusterState with MachineDeployments and MachinePools properly filtered by label.
want: &scope.ClusterState{
Cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
WithInfrastructureCluster(infraCluster).
Expand All @@ -702,6 +707,10 @@ func TestGetCurrentState(t *testing.T) {
Class: "mdClass",
Name: "md1",
}).
WithMachinePool(clusterv1.MachinePoolTopology{
Class: "mpClass",
Name: "mp1",
}).
Build()).
Build(),
ControlPlane: &scope.ControlPlaneState{Object: controlPlaneWithInfra, InfrastructureMachineTemplate: controlPlaneInfrastructureMachineTemplate},
Expand Down Expand Up @@ -732,8 +741,6 @@ func TestGetCurrentState(t *testing.T) {
Class: "mdClass",
Name: "md1",
}).
Build()).
WithTopology(builder.ClusterTopology().
WithMachinePool(clusterv1.MachinePoolTopology{
Class: "mpClass",
Name: "mp1",
Expand Down Expand Up @@ -784,6 +791,10 @@ func TestGetCurrentState(t *testing.T) {
Class: "mdClass",
Name: "md1",
}).
WithMachinePool(clusterv1.MachinePoolTopology{
Class: "mpClass",
Name: "mp1",
}).
Build()).
Build(),
ControlPlane: &scope.ControlPlaneState{Object: controlPlaneWithInfra, InfrastructureMachineTemplate: controlPlaneInfrastructureMachineTemplate},
Expand Down Expand Up @@ -1033,6 +1044,7 @@ func TestGetCurrentState(t *testing.T) {
MachineHealthCheck: machineHealthCheckForMachineDeployment,
},
},
MachinePools: emptyMachinePools,
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions internal/controllers/topology/cluster/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import (
"sigs.k8s.io/cluster-api/util"
)

const version = "1.21.2"

var (
fakeRef1 = &corev1.ObjectReference{
Kind: "refKind1",
Expand Down Expand Up @@ -275,7 +277,6 @@ func TestComputeControlPlane(t *testing.T) {
Build()
// TODO: Replace with object builder.
// current cluster objects
version := "v1.21.2"
replicas := int32(3)
topologyDuration := 10 * time.Second
nodeDrainTimeout := metav1.Duration{Duration: topologyDuration}
Expand Down Expand Up @@ -1348,7 +1349,6 @@ func TestComputeMachineDeployment(t *testing.T) {
WithWorkerMachineDeploymentClasses(mcds...).
Build()

version := "v1.21.2"
cluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand Down Expand Up @@ -1514,7 +1514,7 @@ func TestComputeMachineDeployment(t *testing.T) {
Replicas: &currentReplicas,
Template: clusterv1.MachineTemplateSpec{
Spec: clusterv1.MachineSpec{
Version: pointer.String("v1.21.2"),
Version: pointer.String(version),
Bootstrap: clusterv1.Bootstrap{
ConfigRef: contract.ObjToRef(workerBootstrapTemplate),
},
Expand Down Expand Up @@ -1749,7 +1749,6 @@ func TestComputeMachinePool(t *testing.T) {
WithWorkerMachinePoolClasses(mcps...).
Build()

version := "v1.21.2"
cluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand Down Expand Up @@ -1897,7 +1896,7 @@ func TestComputeMachinePool(t *testing.T) {
Replicas: &currentReplicas,
Template: clusterv1.MachineTemplateSpec{
Spec: clusterv1.MachineSpec{
Version: pointer.String("v1.21.2"),
Version: pointer.String(version),
Bootstrap: clusterv1.Bootstrap{
ConfigRef: contract.ObjToRef(workerBootstrapTemplate),
},
Expand Down

0 comments on commit ce54853

Please sign in to comment.