Skip to content

Commit

Permalink
make assertions more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Mar 9, 2023
1 parent ddca598 commit 47d7636
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions test/e2e/clusterclass_rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ func assertClusterObjects(ctx context.Context, clusterProxy framework.ClusterPro

// ControlPlane
assertControlPlane(g, clusterClassObjects, clusterObjects, cluster, clusterClass)
assertControlPlaneMachines(g, clusterObjects)
assertControlPlaneMachines(g, clusterObjects, cluster)

// MachineDeployments
assertMachineDeployments(g, clusterClassObjects, clusterObjects, cluster, clusterClass)
assertMachineSets(g, clusterObjects, cluster)
assertMachineSetsMachines(g, clusterObjects)
assertMachineSetsMachines(g, clusterObjects, cluster)

By("All cluster objects have the right labels, annotations and selectors")
}, 10*time.Second, 1*time.Second).Should(Succeed())
Expand Down Expand Up @@ -375,7 +375,7 @@ func assertControlPlane(g Gomega, clusterClassObjects clusterClassObjects, clust
))
}

func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects) {
func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects, cluster *clusterv1.Cluster) {
controlPlaneMachineTemplateMetadata := mustMetadata(contract.ControlPlane().MachineTemplate().Metadata().Get(clusterObjects.ControlPlane))
controlPlaneInfrastructureMachineTemplateTemplateMetadata := mustMetadata(contract.InfrastructureMachineTemplate().Template().Metadata().Get(clusterObjects.ControlPlaneInfrastructureMachineTemplate))

Expand All @@ -384,6 +384,7 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects) {
g.Expect(machine.Labels).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.MachineControlPlaneLabel: "",
clusterv1.MachineControlPlaneNameLabel: clusterObjects.ControlPlane.GetName(),
},
Expand All @@ -405,6 +406,7 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects) {
g.Expect(infrastructureMachine.GetLabels()).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.MachineControlPlaneLabel: "",
clusterv1.MachineControlPlaneNameLabel: clusterObjects.ControlPlane.GetName(),
},
Expand All @@ -428,6 +430,7 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects) {
g.Expect(bootstrapConfig.GetLabels()).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.MachineControlPlaneLabel: "",
clusterv1.MachineControlPlaneNameLabel: clusterObjects.ControlPlane.GetName(),
},
Expand Down Expand Up @@ -589,8 +592,11 @@ func assertMachineSets(g Gomega, clusterObjects clusterObjects, cluster *cluster
g.Expect(machineSet.Labels).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineDeploymentUniqueLabel: machineTemplateHash,
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachineDeploymentNameLabel: mdTopology.Name,
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineDeploymentUniqueLabel: machineTemplateHash,
},
machineDeployment.Spec.Template.Labels,
),
Expand Down Expand Up @@ -619,7 +625,10 @@ func assertMachineSets(g Gomega, clusterObjects clusterObjects, cluster *cluster
g.Expect(machineSet.Spec.Template.Labels).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.MachineDeploymentUniqueLabel: machineTemplateHash,
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachineDeploymentNameLabel: mdTopology.Name,
clusterv1.MachineDeploymentUniqueLabel: machineTemplateHash,
},
machineDeployment.Spec.Template.Labels,
),
Expand All @@ -631,21 +640,28 @@ func assertMachineSets(g Gomega, clusterObjects clusterObjects, cluster *cluster
}
}

func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects) {
func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects, cluster *clusterv1.Cluster) {
for _, machineDeployment := range clusterObjects.MachineDeployments {
mdTopology := getMDTopology(cluster, machineDeployment)
infrastructureMachineTemplate := clusterObjects.InfrastructureMachineTemplateByMachineDeployment[machineDeployment.Name]
infrastructureMachineTemplateTemplateMetadata := mustMetadata(contract.InfrastructureMachineTemplate().Template().Metadata().Get(infrastructureMachineTemplate))
bootstrapConfigTemplate := clusterObjects.BootstrapConfigTemplateByMachineDeployment[machineDeployment.Name]
bootstrapConfigTemplateTemplateMetadata := mustMetadata(contract.BootstrapConfigTemplate().Template().Metadata().Get(bootstrapConfigTemplate))

for _, machineSet := range clusterObjects.MachineSetsByMachineDeployment[machineDeployment.Name] {
machineTemplateHash := machineSet.Labels[clusterv1.MachineDeploymentUniqueLabel]

for _, machine := range clusterObjects.MachinesByMachineSet[machineSet.Name] {
// MachineDeployment MachineSet Machine.metadata
g.Expect(machine.Labels).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineSetNameLabel: machineSet.Name,
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachineDeploymentNameLabel: mdTopology.Name,
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineSetNameLabel: machineSet.Name,
clusterv1.MachineDeploymentUniqueLabel: machineTemplateHash,
},
machineSet.Spec.Template.Labels,
),
Expand All @@ -659,8 +675,12 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects) {
g.Expect(infrastructureMachine.GetLabels()).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineSetNameLabel: machineSet.Name,
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachineDeploymentNameLabel: mdTopology.Name,
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineSetNameLabel: machineSet.Name,
clusterv1.MachineDeploymentUniqueLabel: machineTemplateHash,
},
machineSet.Spec.Template.Labels,
infrastructureMachineTemplateTemplateMetadata.Labels,
Expand All @@ -682,8 +702,12 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects) {
g.Expect(bootstrapConfig.GetLabels()).To(BeEquivalentTo(
union(
map[string]string{
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineSetNameLabel: machineSet.Name,
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachineDeploymentNameLabel: mdTopology.Name,
clusterv1.MachineDeploymentNameLabel: machineDeployment.Name,
clusterv1.MachineSetNameLabel: machineSet.Name,
clusterv1.MachineDeploymentUniqueLabel: machineTemplateHash,
},
machineSet.Spec.Template.Labels,
bootstrapConfigTemplateTemplateMetadata.Labels,
Expand Down

0 comments on commit 47d7636

Please sign in to comment.