Skip to content

Commit 035ba1a

Browse files
authored
Merge pull request #6257 from apricote/clusterctl-topology-plan-allow-ns-objects
✨ clusterctl: allow Namespace objects in topology plan input
2 parents 0195739 + ca59717 commit 035ba1a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cmd/clusterctl/client/cluster/assets/topology-test/new-clusterclass-and-cluster.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: default
5+
spec: {}
6+
---
17
apiVersion: cluster.x-k8s.io/v1beta1
28
kind: ClusterClass
39
metadata:

cmd/clusterctl/client/cluster/topology.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ func (t *topologyClient) setMissingNamespaces(currentNamespace string, objs []*u
280280
}
281281
}
282282
// Set namespace on objects that do not have namespace value.
283+
// Skip Namespace objects, as they are non-namespaced.
283284
for i := range objs {
284-
if objs[i].GetNamespace() == "" {
285+
isNamespace := objs[i].GroupVersionKind().Kind == namespaceKind
286+
if objs[i].GetNamespace() == "" && !isNamespace {
285287
objs[i].SetNamespace(currentNamespace)
286288
}
287289
}
@@ -681,6 +683,14 @@ func clusterClassUsesTemplate(cc *clusterv1.ClusterClass, templateRef *corev1.Ob
681683
func uniqueNamespaces(objs []*unstructured.Unstructured) []string {
682684
ns := sets.NewString()
683685
for _, obj := range objs {
686+
// Namespace objects do not have metadata.namespace set, but we can add the
687+
// name of the obj to the namespace list, as it is another unique namespace.
688+
isNamespace := obj.GroupVersionKind().Kind == namespaceKind
689+
if isNamespace {
690+
ns.Insert(obj.GetName())
691+
continue
692+
}
693+
684694
// Note: treat empty namespace (namespace not set) as a unique namespace.
685695
// If some have a namespace set and some do not. It is safer to consider them as
686696
// objects from different namespaces.

0 commit comments

Comments
 (0)