Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ ClusterClass: ensure templates are created in the Cluster namespace #11366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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