@@ -235,6 +235,33 @@ func TestComputeControlPlaneInfrastructureMachineTemplate(t *testing.T) {
235235 g .Expect (obj .GetOwnerReferences ()[0 ].Kind ).To (Equal ("Cluster" ))
236236 g .Expect (obj .GetOwnerReferences ()[0 ].Name ).To (Equal (cluster .Name ))
237237 })
238+
239+ t .Run ("Always generates the infrastructureMachineTemplate from the template in the cluster namespace" , func (t * testing.T ) {
240+ g := NewWithT (t )
241+
242+ cluster := cluster .DeepCopy ()
243+ cluster .Namespace = "differs"
244+ scope := scope .New (cluster )
245+ scope .Blueprint = blueprint
246+
247+ obj , err := computeControlPlaneInfrastructureMachineTemplate (ctx , scope )
248+ g .Expect (err ).ToNot (HaveOccurred ())
249+ g .Expect (obj ).ToNot (BeNil ())
250+
251+ assertTemplateToTemplate (g , assertTemplateInput {
252+ cluster : scope .Current .Cluster ,
253+ templateRef : blueprint .ClusterClass .Spec .ControlPlane .MachineInfrastructure .Ref ,
254+ template : blueprint .ControlPlane .InfrastructureMachineTemplate ,
255+ currentRef : nil ,
256+ obj : obj ,
257+ })
258+
259+ // Ensure Cluster ownership is added to generated InfrastructureCluster.
260+ g .Expect (obj .GetOwnerReferences ()).To (HaveLen (1 ))
261+ g .Expect (obj .GetOwnerReferences ()[0 ].Kind ).To (Equal ("Cluster" ))
262+ g .Expect (obj .GetOwnerReferences ()[0 ].Name ).To (Equal (cluster .Name ))
263+ })
264+
238265 t .Run ("If there is already a reference to the infrastructureMachineTemplate, it preserves the reference name" , func (t * testing.T ) {
239266 g := NewWithT (t )
240267
0 commit comments