Skip to content

Commit

Permalink
Merge pull request #11366 from Danil-Grigorev/cross-ns-template
Browse files Browse the repository at this point in the history
✨ ClusterClass: ensure templates are created in the Cluster namespace
  • Loading branch information
k8s-ci-robot authored Nov 4, 2024
2 parents 1c1a929 + 0af1fb1 commit 3b9a0e5
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 3b9a0e5

Please sign in to comment.