Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Add ClusterTopologyMachineDeploymentLabelName to MachineDeployment templates #5209

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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