Skip to content

Commit 0af1fb1

Browse files
Allow cross-namespace template instances
Signed-off-by: Danil-Grigorev <[email protected]>
1 parent 9f5a94e commit 0af1fb1

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

exp/topology/desiredstate/desired_state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ func templateToTemplate(in templateToInput) (*unstructured.Unstructured, error)
13471347
if in.currentObjectRef != nil && in.currentObjectRef.Name != "" {
13481348
template.SetName(in.currentObjectRef.Name)
13491349
}
1350+
template.SetNamespace(in.cluster.Namespace)
13501351

13511352
return template, nil
13521353
}

exp/topology/desiredstate/desired_state_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)