Skip to content

Commit 0b47b2b

Browse files
srm09Sagar Muchhal
authored and
Sagar Muchhal
committed
Extend cluster builtin to include classNamespace
This patch extends the cluster builtins to include the classNamespace of the Cluster object.
1 parent 155e660 commit 0b47b2b

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ spec:
609609
In addition to variables specified in the ClusterClass, the following builtin variables can be
610610
referenced in patches:
611611
- `builtin.cluster.{name,namespace,uid,metadata.labels,metadata.annotations}`
612-
- `builtin.cluster.topology.{version,class}`
612+
- `builtin.cluster.topology.{version,class,classNamespace}`
613613
- `builtin.cluster.network.{serviceDomain,services,pods,ipFamily}`
614614
- Note: ipFamily is deprecated and will be removed in a future release. see https://github.com/kubernetes-sigs/cluster-api/issues/7521.
615615
- `builtin.controlPlane.{replicas,version,name,metadata.labels,metadata.annotations}`

exp/runtime/hooks/api/v1alpha1/topologymutation_variable_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ type ClusterTopologyBuiltins struct {
7979
// class is the name of the ClusterClass of the Cluster.
8080
// +optional
8181
Class string `json:"class,omitempty"`
82+
83+
// classNamespace is the namespace of the ClusterClass of the Cluster.
84+
// +optional
85+
ClassNamespace string `json:"classNamespace,omitempty"`
8286
}
8387

8488
// ClusterNetworkBuiltins represents builtin cluster network variables.

exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controllers/topology/cluster/patches/variables/variables.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ func Global(clusterTopology *clusterv1.Topology, cluster *clusterv1.Cluster, pat
5656
Namespace: cluster.Namespace,
5757
UID: cluster.UID,
5858
Topology: &runtimehooksv1.ClusterTopologyBuiltins{
59-
Version: cluster.Spec.Topology.Version,
60-
Class: cluster.GetClassKey().Name,
59+
Version: cluster.Spec.Topology.Version,
60+
Class: cluster.GetClassKey().Name,
61+
ClassNamespace: cluster.GetClassKey().Namespace,
6162
},
6263
},
6364
}

internal/controllers/topology/cluster/patches/variables/variables_test.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ func TestGlobal(t *testing.T) {
107107
"metadata": {"labels":{"foo":"bar"}, "annotations":{"fizz":"buzz"}},
108108
"topology":{
109109
"version": "v1.21.1",
110-
"class": "clusterClass1"
110+
"class": "clusterClass1",
111+
"classNamespace": "default"
111112
},
112113
"network":{
113114
"serviceDomain":"cluster.local",
@@ -179,7 +180,8 @@ func TestGlobal(t *testing.T) {
179180
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
180181
"topology":{
181182
"version": "v1.21.1",
182-
"class": "clusterClass1"
183+
"class": "clusterClass1",
184+
"classNamespace": "default"
183185
},
184186
"network":{
185187
"serviceDomain":"cluster.local",
@@ -250,8 +252,9 @@ func TestGlobal(t *testing.T) {
250252
"namespace": "default",
251253
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
252254
"topology":{
253-
"version": "v1.21.1",
254-
"class": "clusterClass1"
255+
"version": "v1.21.1",
256+
"class": "clusterClass1",
257+
"classNamespace": "default"
255258
},
256259
"network":{
257260
"services":["10.10.10.1/24"],
@@ -318,8 +321,9 @@ func TestGlobal(t *testing.T) {
318321
"namespace": "default",
319322
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
320323
"topology":{
321-
"version": "v1.21.1",
322-
"class": "clusterClass1"
324+
"version": "v1.21.1",
325+
"class": "clusterClass1",
326+
"classNamespace": "default"
323327
},
324328
"network":{
325329
"serviceDomain":"cluster.local",
@@ -382,7 +386,8 @@ func TestGlobal(t *testing.T) {
382386
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
383387
"topology":{
384388
"version": "v1.21.1",
385-
"class": "clusterClass1"
389+
"class": "clusterClass1",
390+
"classNamespace": "default"
386391
}
387392
}}`),
388393
},

internal/webhooks/patch_validation.go

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ var builtinVariables = sets.Set[string]{}.Insert(
478478
// ClusterTopology builtins.
479479
"builtin.cluster.topology",
480480
"builtin.cluster.topology.class",
481+
"builtin.cluster.topology.classNamespace",
481482
"builtin.cluster.topology.version",
482483

483484
// ClusterNetwork builtins

0 commit comments

Comments
 (0)