Skip to content

[release-1.10] ✨ Extend cluster builtin to include classNamespace #12051

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ spec:
In addition to variables specified in the ClusterClass, the following builtin variables can be
referenced in patches:
- `builtin.cluster.{name,namespace,uid,metadata.labels,metadata.annotations}`
- `builtin.cluster.topology.{version,class}`
- `builtin.cluster.topology.{version,class,classNamespace}`
- `builtin.cluster.network.{serviceDomain,services,pods,ipFamily}`
- Note: ipFamily is deprecated and will be removed in a future release. see https://github.com/kubernetes-sigs/cluster-api/issues/7521.
- `builtin.controlPlane.{replicas,version,name,metadata.labels,metadata.annotations}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type ClusterTopologyBuiltins struct {
// class is the name of the ClusterClass of the Cluster.
// +optional
Class string `json:"class,omitempty"`

// classNamespace is the namespace of the ClusterClass of the Cluster.
// +optional
ClassNamespace string `json:"classNamespace,omitempty"`
}

// ClusterNetworkBuiltins represents builtin cluster network variables.
Expand Down
7 changes: 7 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func Global(clusterTopology *clusterv1.Topology, cluster *clusterv1.Cluster, pat
Namespace: cluster.Namespace,
UID: cluster.UID,
Topology: &runtimehooksv1.ClusterTopologyBuiltins{
Version: cluster.Spec.Topology.Version,
Class: cluster.GetClassKey().Name,
Version: cluster.Spec.Topology.Version,
Class: cluster.GetClassKey().Name,
ClassNamespace: cluster.GetClassKey().Namespace,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func TestGlobal(t *testing.T) {
"metadata": {"labels":{"foo":"bar"}, "annotations":{"fizz":"buzz"}},
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
"class": "clusterClass1",
"classNamespace": "default"
},
"network":{
"serviceDomain":"cluster.local",
Expand Down Expand Up @@ -179,7 +180,8 @@ func TestGlobal(t *testing.T) {
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
"class": "clusterClass1",
"classNamespace": "default"
},
"network":{
"serviceDomain":"cluster.local",
Expand Down Expand Up @@ -250,8 +252,9 @@ func TestGlobal(t *testing.T) {
"namespace": "default",
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
"version": "v1.21.1",
"class": "clusterClass1",
"classNamespace": "default"
},
"network":{
"services":["10.10.10.1/24"],
Expand Down Expand Up @@ -318,8 +321,9 @@ func TestGlobal(t *testing.T) {
"namespace": "default",
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
"version": "v1.21.1",
"class": "clusterClass1",
"classNamespace": "default"
},
"network":{
"serviceDomain":"cluster.local",
Expand Down Expand Up @@ -382,7 +386,8 @@ func TestGlobal(t *testing.T) {
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
"class": "clusterClass1",
"classNamespace": "default"
}
}}`),
},
Expand Down
1 change: 1 addition & 0 deletions internal/webhooks/patch_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ var builtinVariables = sets.Set[string]{}.Insert(
// ClusterTopology builtins.
"builtin.cluster.topology",
"builtin.cluster.topology.class",
"builtin.cluster.topology.classNamespace",
"builtin.cluster.topology.version",

// ClusterNetwork builtins
Expand Down