Skip to content

Commit

Permalink
Add checks for not topology owned templates to never reconcile.
Browse files Browse the repository at this point in the history
  • Loading branch information
adilGhaffarDev committed Jun 28, 2022
1 parent 8a6b4c6 commit 262e40f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/controllers/topology/cluster/current_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func (r *Reconciler) getCurrentControlPlaneState(ctx context.Context, cluster *c
if err != nil {
return nil, errors.Wrapf(err, "failed to get InfrastructureMachineTemplate for %s", tlog.KObj{Obj: res.Object})
}
// check that the referenced object has the ClusterTopologyOwnedLabel label.
// Nb. This is to make sure that a managed topology cluster does not have a reference to an object that is not
// owned by the topology.
if !labels.IsTopologyOwned(res.InfrastructureMachineTemplate) {
return nil, fmt.Errorf("referenced infra cluster object %s is not topology owned", tlog.KObj{Obj: res.InfrastructureMachineTemplate})
}

mhc := &clusterv1.MachineHealthCheck{}
// MachineHealthCheck always has the same name and namespace as the ControlPlane object it belongs to.
Expand Down Expand Up @@ -158,6 +164,12 @@ func (r *Reconciler) getCurrentMachineDeploymentState(ctx context.Context, clust
for i := range md.Items {
m := &md.Items[i]

// check that the MachineDeployment has the ClusterTopologyOwnedLabel label.
// Nb. This is to make sure that a managed topology cluster does not have a reference to an object that is not
// owned by the topology.
if !labels.IsTopologyOwned(m) {
return nil, fmt.Errorf(" %s is not topology owned", tlog.KObj{Obj: m})
}
// Retrieve the name which is assigned in Cluster's topology
// from a well-defined label.
mdTopologyName, ok := m.ObjectMeta.Labels[clusterv1.ClusterTopologyMachineDeploymentLabelName]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestGetCurrentState(t *testing.T) {
// ControlPlane and ControlPlaneInfrastructureMachineTemplate objects.
controlPlaneInfrastructureMachineTemplate := builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "cpInfraTemplate").
Build()
controlPlaneInfrastructureMachineTemplate.SetLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""})
controlPlaneTemplateWithInfrastructureMachine := builder.ControlPlaneTemplate(metav1.NamespaceDefault, "cpTemplateWithInfra1").
WithInfrastructureMachineTemplate(controlPlaneInfrastructureMachineTemplate).
Build()
Expand Down

0 comments on commit 262e40f

Please sign in to comment.