Skip to content

Commit

Permalink
fix some findings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Sep 21, 2023
1 parent c4c58e5 commit 79b07d6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 46 deletions.
10 changes: 6 additions & 4 deletions internal/controllers/topology/cluster/blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestGetBlueprint(t *testing.T) {
builder.GenericInfrastructureClusterTemplateCRD,
builder.GenericInfrastructureMachineTemplateCRD,
builder.GenericInfrastructureMachineCRD,
builder.GenericInfrastructureMachinePoolTemplateCRD,
builder.GenericInfrastructureMachinePoolCRD,
builder.GenericControlPlaneTemplateCRD,
builder.GenericBootstrapConfigTemplateCRD,
}
Expand Down Expand Up @@ -233,7 +235,7 @@ func TestGetBlueprint(t *testing.T) {
},
},
{
name: "Fails if ClusterClass has a MachineDeploymentClass referencing a BootstrapTemplate that does not exist",
name: "Fails if ClusterClass has a MachineDeploymentClass referencing a BootstrapConfigTemplate that does not exist",
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
WithInfrastructureClusterTemplate(infraClusterTemplate).
WithControlPlaneTemplate(controlPlaneTemplate).
Expand Down Expand Up @@ -329,7 +331,7 @@ func TestGetBlueprint(t *testing.T) {
},
},
{
name: "Fails if ClusterClass has a MachinePoolClass referencing a BootstrapConfig that does not exist",
name: "Fails if ClusterClass has a MachinePoolClass referencing a BootstrapConfigTemplate that does not exist",
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
WithInfrastructureClusterTemplate(infraClusterTemplate).
WithControlPlaneTemplate(controlPlaneTemplate).
Expand Down Expand Up @@ -413,8 +415,8 @@ func TestGetBlueprint(t *testing.T) {
g.Expect(tt.want.ClusterClass).To(EqualObject(got.ClusterClass, IgnoreAutogeneratedMetadata))
g.Expect(tt.want.InfrastructureClusterTemplate).To(EqualObject(got.InfrastructureClusterTemplate), cmp.Diff(got.InfrastructureClusterTemplate, tt.want.InfrastructureClusterTemplate))
g.Expect(got.ControlPlane).To(BeComparableTo(tt.want.ControlPlane), cmp.Diff(got.ControlPlane, tt.want.ControlPlane))
g.Expect(tt.want.MachineDeployments).To(BeComparableTo(got.MachineDeployments), got.MachineDeployments, tt.want.MachineDeployments)
g.Expect(tt.want.MachinePools).To(BeComparableTo(got.MachinePools), got.MachinePools, tt.want.MachinePools)
g.Expect(tt.want.MachineDeployments).To(BeComparableTo(got.MachineDeployments), cmp.Diff(got.MachineDeployments, tt.want.MachineDeployments))
g.Expect(tt.want.MachinePools).To(BeComparableTo(got.MachinePools), cmp.Diff(got.MachinePools, tt.want.MachinePools))
})
}
}
46 changes: 26 additions & 20 deletions internal/controllers/topology/cluster/current_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestGetCurrentState(t *testing.T) {
builder.GenericBootstrapConfigTemplateCRD,
builder.GenericInfrastructureMachineTemplateCRD,
builder.GenericInfrastructureMachineCRD,
builder.GenericInfrastructureMachinePoolTemplateCRD,
builder.GenericInfrastructureMachinePoolCRD,
}

// The following is a block creating a number of objects for use in the test cases.
Expand Down Expand Up @@ -160,10 +162,14 @@ func TestGetCurrentState(t *testing.T) {
// MachinePool and related objects.
emptyMachinePools := make(map[string]*scope.MachinePoolState)

machinePoolInfrastructure := builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra2").
machinePoolInfrastructureTemplate := builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "infra2").
Build()
machinePoolInfrastructure := builder.InfrastructureMachinePool(metav1.NamespaceDefault, "infra2").
Build()
machinePoolInfrastructure.SetLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""})
machinePoolBootstrap := builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap2").
machinePoolBootstrapTemplate := builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap2").
Build()
machinePoolBootstrap := builder.BootstrapConfig(metav1.NamespaceDefault, "bootstrap2").
Build()
machinePoolBootstrap.SetLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""})

Expand Down Expand Up @@ -434,7 +440,7 @@ func TestGetCurrentState(t *testing.T) {
machinePoolBootstrap,
machinePool,
},
// Expecting valid return with valid ControlPlane, ControlPlane Infrastructure and InfrastructureCluster state, but no defined MachineDeployment state.
// Expecting valid return with valid ControlPlane, ControlPlane Infrastructure, InfrastructureCluster, MachineDeployment and MachinePool state.
want: &scope.ClusterState{
Cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
WithTopology(builder.ClusterTopology().
Expand Down Expand Up @@ -680,8 +686,8 @@ func TestGetCurrentState(t *testing.T) {
},
MachinePools: map[string]*scope.MachinePoolBlueprint{
"mpClass": {
BootstrapTemplate: machinePoolBootstrap,
InfrastructureMachinePoolTemplate: machinePoolInfrastructure,
BootstrapTemplate: machinePoolBootstrapTemplate,
InfrastructureMachinePoolTemplate: machinePoolInfrastructureTemplate,
},
},
},
Expand Down Expand Up @@ -762,8 +768,8 @@ func TestGetCurrentState(t *testing.T) {
},
MachinePools: map[string]*scope.MachinePoolBlueprint{
"mpClass": {
BootstrapTemplate: machinePoolBootstrap,
InfrastructureMachinePoolTemplate: machinePoolInfrastructure,
BootstrapTemplate: machinePoolBootstrapTemplate,
InfrastructureMachinePoolTemplate: machinePoolInfrastructureTemplate,
},
},
},
Expand All @@ -781,7 +787,7 @@ func TestGetCurrentState(t *testing.T) {
machinePool,
machinePool2,
},
// 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 Down Expand Up @@ -857,7 +863,7 @@ func TestGetCurrentState(t *testing.T) {
machineDeploymentInfrastructure,
builder.MachineDeployment(metav1.NamespaceDefault, "no-bootstrap").
WithLabels(machineDeployment.Labels).
// No BootstrapTemplate reference!
// No BootstrapConfigTemplate reference!
WithInfrastructureTemplate(machineDeploymentInfrastructure).
Build(),
},
Expand All @@ -883,8 +889,8 @@ func TestGetCurrentState(t *testing.T) {
},
MachinePools: map[string]*scope.MachinePoolBlueprint{
"mpClass": {
BootstrapTemplate: machinePoolBootstrap,
InfrastructureMachinePoolTemplate: machinePoolInfrastructure,
BootstrapTemplate: machinePoolBootstrapTemplate,
InfrastructureMachinePoolTemplate: machinePoolInfrastructureTemplate,
},
},
},
Expand All @@ -896,11 +902,11 @@ func TestGetCurrentState(t *testing.T) {
machinePoolInfrastructure,
builder.MachinePool(metav1.NamespaceDefault, "no-bootstrap").
WithLabels(machinePool.Labels).
// No BootstrapTemplate reference!
// No BootstrapConfig reference!
WithInfrastructure(machinePoolInfrastructure).
Build(),
},
// Expect error as Bootstrap Template not defined for MachinePools relevant to the Cluster.
// Expect error as BootstrapConfig not defined for MachinePools relevant to the Cluster.
wantErr: true,
},
{
Expand Down Expand Up @@ -943,7 +949,7 @@ func TestGetCurrentState(t *testing.T) {
wantErr: true,
},
{
name: "Fails if a Cluster has a MachinePools without the InfrastructureMachineTemplate ref",
name: "Fails if a Cluster has a MachinePools without the InfrastructureMachinePool ref",
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
WithTopology(builder.ClusterTopology().
WithMachinePool(clusterv1.MachinePoolTopology{
Expand All @@ -961,8 +967,8 @@ func TestGetCurrentState(t *testing.T) {
},
MachinePools: map[string]*scope.MachinePoolBlueprint{
"mpClass": {
BootstrapTemplate: machinePoolBootstrap,
InfrastructureMachinePoolTemplate: machinePoolInfrastructure,
BootstrapTemplate: machinePoolBootstrapTemplate,
InfrastructureMachinePoolTemplate: machinePoolInfrastructureTemplate,
},
},
},
Expand All @@ -975,10 +981,10 @@ func TestGetCurrentState(t *testing.T) {
builder.MachinePool(metav1.NamespaceDefault, "no-infra").
WithLabels(machinePool.Labels).
WithBootstrap(machinePoolBootstrap).
// No InfrastructureMachineTemplate reference!
// No InfrastructureMachinePool reference!
Build(),
},
// Expect error as Infrastructure Template not defined for MachinePool relevant to the Cluster.
// Expect error as InfrastructureMachinePool not defined for MachinePool relevant to the Cluster.
wantErr: true,
},
{
Expand Down Expand Up @@ -1093,8 +1099,8 @@ func TestGetCurrentState(t *testing.T) {
g.Expect(got.Cluster).To(EqualObject(tt.want.Cluster, IgnoreAutogeneratedMetadata))
g.Expect(got.InfrastructureCluster).To(EqualObject(tt.want.InfrastructureCluster))
g.Expect(got.ControlPlane).To(BeComparableTo(tt.want.ControlPlane), cmp.Diff(got.ControlPlane, tt.want.ControlPlane))
g.Expect(got.MachineDeployments).To(BeComparableTo(tt.want.MachineDeployments))
g.Expect(got.MachinePools).To(BeComparableTo(tt.want.MachinePools))
g.Expect(got.MachineDeployments).To(BeComparableTo(tt.want.MachineDeployments), cmp.Diff(got.MachineDeployments, tt.want.MachineDeployments))
g.Expect(got.MachinePools).To(BeComparableTo(tt.want.MachinePools), cmp.Diff(got.MachinePools, tt.want.MachinePools))
})
}
}
Expand Down
Loading

0 comments on commit 79b07d6

Please sign in to comment.