@@ -81,7 +81,7 @@ func (r *Reconciler) getCurrentInfrastructureClusterState(ctx context.Context, c
8181 // Nb. This is to make sure that a managed topology cluster does not have a reference to an object that is not
8282 // owned by the topology.
8383 if ! labels .IsTopologyOwned (infra ) {
84- return nil , fmt .Errorf ("referenced infra cluster object %s is not topology owned" , tlog.KObj {Obj : infra })
84+ return nil , fmt .Errorf ("infra cluster object %s referenced from cluster %s is not topology owned" , tlog.KObj {Obj : infra }, tlog. KObj { Obj : cluster })
8585 }
8686 return infra , nil
8787}
@@ -102,7 +102,7 @@ func (r *Reconciler) getCurrentControlPlaneState(ctx context.Context, cluster *c
102102 // Nb. This is to make sure that a managed topology cluster does not have a reference to an object that is not
103103 // owned by the topology.
104104 if ! labels .IsTopologyOwned (res .Object ) {
105- return nil , fmt .Errorf ("referenced control plane object %s is not topology owned" , tlog.KObj {Obj : res .Object })
105+ return nil , fmt .Errorf ("control plane object %s referenced from cluster %s is not topology owned" , tlog.KObj {Obj : res .Object }, tlog. KObj { Obj : cluster })
106106 }
107107
108108 // If the clusterClass does not mandate the controlPlane has infrastructureMachines, return.
@@ -119,6 +119,12 @@ func (r *Reconciler) getCurrentControlPlaneState(ctx context.Context, cluster *c
119119 if err != nil {
120120 return nil , errors .Wrapf (err , "failed to get InfrastructureMachineTemplate for %s" , tlog.KObj {Obj : res .Object })
121121 }
122+ // check that the referenced object has the ClusterTopologyOwnedLabel label.
123+ // Nb. This is to make sure that a managed topology cluster does not have a reference to an object that is not
124+ // owned by the topology.
125+ if ! labels .IsTopologyOwned (res .InfrastructureMachineTemplate ) {
126+ return nil , fmt .Errorf ("control plane InfrastructureMachineTemplate object %s referenced from cluster %s is not topology owned" , tlog.KObj {Obj : res .InfrastructureMachineTemplate }, tlog.KObj {Obj : cluster })
127+ }
122128
123129 mhc := & clusterv1.MachineHealthCheck {}
124130 // MachineHealthCheck always has the same name and namespace as the ControlPlane object it belongs to.
@@ -181,6 +187,12 @@ func (r *Reconciler) getCurrentMachineDeploymentState(ctx context.Context, clust
181187 if err != nil {
182188 return nil , errors .Wrap (err , fmt .Sprintf ("%s Bootstrap reference could not be retrieved" , tlog.KObj {Obj : m }))
183189 }
190+ // check that the referenced object has the ClusterTopologyOwnedLabel label.
191+ // Nb. This is to make sure that a managed topology cluster does not have a reference to an object that is not
192+ // owned by the topology.
193+ if ! labels .IsTopologyOwned (b ) {
194+ return nil , fmt .Errorf ("BootstrapTemplate object %s referenced from MD %s is not topology owned" , tlog.KObj {Obj : b }, tlog.KObj {Obj : m })
195+ }
184196
185197 // Gets the InfrastructureMachineTemplate
186198 infraRef := m .Spec .Template .Spec .InfrastructureRef
@@ -191,6 +203,12 @@ func (r *Reconciler) getCurrentMachineDeploymentState(ctx context.Context, clust
191203 if err != nil {
192204 return nil , errors .Wrap (err , fmt .Sprintf ("%s Infrastructure reference could not be retrieved" , tlog.KObj {Obj : m }))
193205 }
206+ // check that the referenced object has the ClusterTopologyOwnedLabel label.
207+ // Nb. This is to make sure that a managed topology cluster does not have a reference to an object that is not
208+ // owned by the topology.
209+ if ! labels .IsTopologyOwned (infra ) {
210+ return nil , fmt .Errorf ("InfrastructureMachineTemplate object %s referenced from MD %s is not topology owned" , tlog.KObj {Obj : infra }, tlog.KObj {Obj : m })
211+ }
194212
195213 // Gets the MachineHealthCheck.
196214 mhc := & clusterv1.MachineHealthCheck {}
0 commit comments