Skip to content

Commit

Permalink
Merge pull request #10822 from srm09/add-uid-to-cluster-builtins
Browse files Browse the repository at this point in the history
✨ Extend cluster builtin to include UID
  • Loading branch information
k8s-ci-robot authored Jul 4, 2024
2 parents 5a0c7a9 + ed38302 commit 9dd9b81
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ spec:

In addition to variables specified in the ClusterClass, the following builtin variables can be
referenced in patches:
- `builtin.cluster.{name,namespace}`
- `builtin.cluster.{name,namespace,uid}`
- `builtin.cluster.topology.{version,class}`
- `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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package v1alpha1

import "k8s.io/apimachinery/pkg/types"

// BuiltinsName is the name of the builtin variable.
const BuiltinsName = "builtin"

Expand All @@ -35,6 +37,9 @@ type ClusterBuiltins struct {
// Namespace is the namespace of the cluster.
Namespace string `json:"namespace,omitempty"`

// UID is the unqiue identifier of the cluster.
UID types.UID `json:"uid,omitempty"`

// Topology represents the cluster topology variables.
Topology *ClusterTopologyBuiltins `json:"topology,omitempty"`

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.

2 changes: 2 additions & 0 deletions internal/controllers/topology/cluster/patches/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/uuid"
utilfeature "k8s.io/component-base/featuregate/testing"
"k8s.io/utils/ptr"
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
Expand Down Expand Up @@ -1073,6 +1074,7 @@ func setupTestObjects() (*scope.ClusterBlueprint, *scope.ClusterState) {
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: metav1.NamespaceDefault,
UID: uuid.NewUUID(),
},
Spec: clusterv1.ClusterSpec{
Paused: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func Global(clusterTopology *clusterv1.Topology, cluster *clusterv1.Cluster, def
Cluster: &runtimehooksv1.ClusterBuiltins{
Name: cluster.Name,
Namespace: cluster.Namespace,
UID: cluster.UID,
Topology: &runtimehooksv1.ClusterTopologyBuiltins{
Version: cluster.Spec.Topology.Version,
Class: cluster.GetClassKey().Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand All @@ -34,6 +35,7 @@ import (
)

func TestGlobal(t *testing.T) {
clusterUID := "8a35f406-6b9b-4b78-8c93-a7f878d90623"
tests := []struct {
name string
clusterTopology *clusterv1.Topology
Expand Down Expand Up @@ -68,6 +70,7 @@ func TestGlobal(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: metav1.NamespaceDefault,
UID: types.UID(clusterUID),
},
Spec: clusterv1.ClusterSpec{
Topology: &clusterv1.Topology{
Expand Down Expand Up @@ -100,6 +103,7 @@ func TestGlobal(t *testing.T) {
"cluster":{
"name": "cluster1",
"namespace": "default",
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
Expand Down Expand Up @@ -149,6 +153,7 @@ func TestGlobal(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: metav1.NamespaceDefault,
UID: types.UID(clusterUID),
},
Spec: clusterv1.ClusterSpec{
Topology: &clusterv1.Topology{
Expand Down Expand Up @@ -181,6 +186,7 @@ func TestGlobal(t *testing.T) {
"cluster":{
"name": "cluster1",
"namespace": "default",
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
Expand Down Expand Up @@ -221,6 +227,7 @@ func TestGlobal(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: metav1.NamespaceDefault,
UID: types.UID(clusterUID),
},
Spec: clusterv1.ClusterSpec{
Topology: &clusterv1.Topology{
Expand Down Expand Up @@ -252,6 +259,7 @@ func TestGlobal(t *testing.T) {
"cluster":{
"name": "cluster1",
"namespace": "default",
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
Expand Down Expand Up @@ -291,6 +299,7 @@ func TestGlobal(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: metav1.NamespaceDefault,
UID: types.UID(clusterUID),
},
Spec: clusterv1.ClusterSpec{
Topology: &clusterv1.Topology{
Expand Down Expand Up @@ -319,6 +328,7 @@ func TestGlobal(t *testing.T) {
"cluster":{
"name": "cluster1",
"namespace": "default",
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
Expand Down Expand Up @@ -357,6 +367,7 @@ func TestGlobal(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: metav1.NamespaceDefault,
UID: types.UID(clusterUID),
},
Spec: clusterv1.ClusterSpec{
Topology: &clusterv1.Topology{
Expand All @@ -381,6 +392,7 @@ func TestGlobal(t *testing.T) {
"cluster":{
"name": "cluster1",
"namespace": "default",
"uid": "8a35f406-6b9b-4b78-8c93-a7f878d90623",
"topology":{
"version": "v1.21.1",
"class": "clusterClass1"
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 @@ -471,6 +471,7 @@ var builtinVariables = sets.Set[string]{}.Insert(
"builtin.cluster",
"builtin.cluster.name",
"builtin.cluster.namespace",
"builtin.cluster.uid",

// ClusterTopology builtins.
"builtin.cluster.topology",
Expand Down

0 comments on commit 9dd9b81

Please sign in to comment.