Skip to content

Commit

Permalink
Allow cross-namespace template instances
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Nov 2, 2024
1 parent 9f5a94e commit 0af1fb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions exp/topology/desiredstate/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ func templateToTemplate(in templateToInput) (*unstructured.Unstructured, error)
if in.currentObjectRef != nil && in.currentObjectRef.Name != "" {
template.SetName(in.currentObjectRef.Name)
}
template.SetNamespace(in.cluster.Namespace)

return template, nil
}
Expand Down
27 changes: 27 additions & 0 deletions exp/topology/desiredstate/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,33 @@ func TestComputeControlPlaneInfrastructureMachineTemplate(t *testing.T) {
g.Expect(obj.GetOwnerReferences()[0].Kind).To(Equal("Cluster"))
g.Expect(obj.GetOwnerReferences()[0].Name).To(Equal(cluster.Name))
})

t.Run("Always generates the infrastructureMachineTemplate from the template in the cluster namespace", func(t *testing.T) {
g := NewWithT(t)

cluster := cluster.DeepCopy()
cluster.Namespace = "differs"
scope := scope.New(cluster)
scope.Blueprint = blueprint

obj, err := computeControlPlaneInfrastructureMachineTemplate(ctx, scope)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(obj).ToNot(BeNil())

assertTemplateToTemplate(g, assertTemplateInput{
cluster: scope.Current.Cluster,
templateRef: blueprint.ClusterClass.Spec.ControlPlane.MachineInfrastructure.Ref,
template: blueprint.ControlPlane.InfrastructureMachineTemplate,
currentRef: nil,
obj: obj,
})

// Ensure Cluster ownership is added to generated InfrastructureCluster.
g.Expect(obj.GetOwnerReferences()).To(HaveLen(1))
g.Expect(obj.GetOwnerReferences()[0].Kind).To(Equal("Cluster"))
g.Expect(obj.GetOwnerReferences()[0].Name).To(Equal(cluster.Name))
})

t.Run("If there is already a reference to the infrastructureMachineTemplate, it preserves the reference name", func(t *testing.T) {
g := NewWithT(t)

Expand Down

0 comments on commit 0af1fb1

Please sign in to comment.