diff --git a/api/v1beta1/cluster_types.go b/api/v1beta1/cluster_types.go index 7732d07d949e..2b2c5f6f80a0 100644 --- a/api/v1beta1/cluster_types.go +++ b/api/v1beta1/cluster_types.go @@ -100,6 +100,11 @@ type Topology struct { // The name of the ClusterClass object to create the topology. Class string `json:"class"` + // The namespace of the ClusterClass object to create the topology. + // + // +optional + ClassNamespace string `json:"classNamespace,omitempty"` + // The Kubernetes version of the cluster. Version string `json:"version"` @@ -628,7 +633,17 @@ func (c *Cluster) GetClassKey() types.NamespacedName { if c.Spec.Topology == nil { return types.NamespacedName{} } - return types.NamespacedName{Namespace: c.GetNamespace(), Name: c.Spec.Topology.Class} + + return types.NamespacedName{Namespace: c.GetInfrastructureNamespace(), Name: c.Spec.Topology.Class} +} + +// GetInfrastructureNamespace returns common namespace for the cluster infrastructure +func (c *Cluster) GetInfrastructureNamespace() string { + if c.Spec.Topology == nil || c.Spec.Topology.ClassNamespace == "" { + return c.Namespace + } + + return c.Spec.Topology.ClassNamespace } // GetConditions returns the set of conditions for this object. diff --git a/api/v1beta1/zz_generated.openapi.go b/api/v1beta1/zz_generated.openapi.go index a7345be50029..4e6bb507236f 100644 --- a/api/v1beta1/zz_generated.openapi.go +++ b/api/v1beta1/zz_generated.openapi.go @@ -4218,6 +4218,13 @@ func schema_sigsk8sio_cluster_api_api_v1beta1_Topology(ref common.ReferenceCallb Format: "", }, }, + "classNamespace": { + SchemaProps: spec.SchemaProps{ + Description: "The namespace of the ClusterClass object to create the topology.", + Type: []string{"string"}, + Format: "", + }, + }, "version": { SchemaProps: spec.SchemaProps{ Description: "The Kubernetes version of the cluster.", diff --git a/config/crd/bases/cluster.x-k8s.io_clusters.yaml b/config/crd/bases/cluster.x-k8s.io_clusters.yaml index 6f2877c5cc69..de61d7ee75d5 100644 --- a/config/crd/bases/cluster.x-k8s.io_clusters.yaml +++ b/config/crd/bases/cluster.x-k8s.io_clusters.yaml @@ -928,6 +928,10 @@ spec: description: The name of the ClusterClass object to create the topology. type: string + classNamespace: + description: The namespace of the ClusterClass object to create + the topology. + type: string controlPlane: description: ControlPlane describes the cluster control plane. properties: diff --git a/internal/apis/core/v1alpha4/conversion.go b/internal/apis/core/v1alpha4/conversion.go index cd69ca35d2ba..8e2ed513d13d 100644 --- a/internal/apis/core/v1alpha4/conversion.go +++ b/internal/apis/core/v1alpha4/conversion.go @@ -42,6 +42,7 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error { if dst.Spec.Topology == nil { dst.Spec.Topology = &clusterv1.Topology{} } + dst.Spec.Topology.ClassNamespace = restored.Spec.Topology.ClassNamespace dst.Spec.Topology.Variables = restored.Spec.Topology.Variables dst.Spec.Topology.ControlPlane.Variables = restored.Spec.Topology.ControlPlane.Variables diff --git a/internal/apis/core/v1alpha4/zz_generated.conversion.go b/internal/apis/core/v1alpha4/zz_generated.conversion.go index 14df0dfc9112..f5c0433a653d 100644 --- a/internal/apis/core/v1alpha4/zz_generated.conversion.go +++ b/internal/apis/core/v1alpha4/zz_generated.conversion.go @@ -1757,6 +1757,7 @@ func Convert_v1alpha4_Topology_To_v1beta1_Topology(in *Topology, out *v1beta1.To func autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error { out.Class = in.Class + // WARNING: in.ClassNamespace requires manual conversion: does not exist in peer-type out.Version = in.Version out.RolloutAfter = (*metav1.Time)(unsafe.Pointer(in.RolloutAfter)) if err := Convert_v1beta1_ControlPlaneTopology_To_v1alpha4_ControlPlaneTopology(&in.ControlPlane, &out.ControlPlane, s); err != nil {