Skip to content

Commit

Permalink
Add ClusterTopologyMachineDeploymentLabelName to MD templates
Browse files Browse the repository at this point in the history
- Adding ClusterTopologyMachineDeploymentLabelName to the generated
  Bootstrap and Infrastructure Machine templates
- Adding assertions to verify the label name and value on the generated
  templates
  • Loading branch information
anusha94 committed Sep 6, 2021
1 parent 84d7a3c commit ea5ac6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions controllers/topology/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, machineDeployme
currentObjectRef: currentBootstrapTemplateRef,
})

bootstrapTemplateLabels := desiredMachineDeployment.BootstrapTemplate.GetLabels()
if bootstrapTemplateLabels == nil {
bootstrapTemplateLabels = map[string]string{}
}
// Add ClusterTopologyMachineDeploymentLabel to the generated Bootstrap template
bootstrapTemplateLabels[clusterv1.ClusterTopologyMachineDeploymentLabelName] = machineDeploymentTopology.Name
desiredMachineDeployment.BootstrapTemplate.SetLabels(bootstrapTemplateLabels)

// Compute the Infrastructure template.
var currentInfraMachineTemplateRef *corev1.ObjectReference
if currentMachineDeployment != nil && currentMachineDeployment.InfrastructureMachineTemplate != nil {
Expand All @@ -249,6 +257,14 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, machineDeployme
currentObjectRef: currentInfraMachineTemplateRef,
})

infraMachineTemplateLabels := desiredMachineDeployment.InfrastructureMachineTemplate.GetLabels()
if infraMachineTemplateLabels == nil {
infraMachineTemplateLabels = map[string]string{}
}
// Add ClusterTopologyMachineDeploymentLabel to the generated InfrastructureMachine template
infraMachineTemplateLabels[clusterv1.ClusterTopologyMachineDeploymentLabelName] = machineDeploymentTopology.Name
desiredMachineDeployment.InfrastructureMachineTemplate.SetLabels(infraMachineTemplateLabels)

// Compute the MachineDeployment object.
gv := clusterv1.GroupVersion
desiredMachineDeploymentObj := &clusterv1.MachineDeployment{
Expand Down
3 changes: 3 additions & 0 deletions controllers/topology/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ func TestComputeMachineDeployment(t *testing.T) {
actual, err := computeMachineDeployment(ctx, scope, mdTopology)
g.Expect(err).ToNot(HaveOccurred())

g.Expect(actual.BootstrapTemplate.GetLabels()).To(HaveKeyWithValue(clusterv1.ClusterTopologyMachineDeploymentLabelName, "big-pool-of-machines"))
g.Expect(actual.InfrastructureMachineTemplate.GetLabels()).To(HaveKeyWithValue(clusterv1.ClusterTopologyMachineDeploymentLabelName, "big-pool-of-machines"))

actualMd := actual.Object
g.Expect(*actualMd.Spec.Replicas).To(Equal(replicas))
g.Expect(actualMd.Spec.ClusterName).To(Equal("cluster1"))
Expand Down

0 comments on commit ea5ac6b

Please sign in to comment.