Skip to content

Commit 72b19b1

Browse files
authored
⚠️ Restructure classRef field in Cluster.spec.topology (#12235)
* Restructure classRef field in Cluster.spec.topology Signed-off-by: Stefan Büringer buringerst@vmware.com * Fix review findings * Simplify field patterns --------- Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent 1f629e1 commit 72b19b1

37 files changed

+408
-178
lines changed

api/v1beta1/cluster_types.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,15 @@ type Topology struct {
546546
// +kubebuilder:validation:MaxLength=253
547547
Class string `json:"class"`
548548

549-
// classNamespace is the namespace of the ClusterClass object to create the topology.
550-
// If the namespace is empty or not set, it is defaulted to the namespace of the cluster object.
551-
// Value must follow the DNS1123Subdomain syntax.
549+
// classNamespace is the namespace of the ClusterClass that should be used for the topology.
550+
// If classNamespace is empty or not set, it is defaulted to the namespace of the Cluster object.
551+
// classNamespace must be a valid namespace name and because of that be at most 63 characters in length
552+
// and it must consist only of lower case alphanumeric characters or hyphens (-), and must start
553+
// and end with an alphanumeric character.
552554
// +optional
553555
// +kubebuilder:validation:MinLength=1
554-
// +kubebuilder:validation:MaxLength=253
555-
// +kubebuilder:validation:Pattern=`^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$`
556+
// +kubebuilder:validation:MaxLength=63
557+
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
556558
ClassNamespace string `json:"classNamespace,omitempty"`
557559

558560
// version is the Kubernetes version of the cluster.

api/v1beta1/conversion.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,16 @@ func Convert_v1beta2_ClusterStatus_To_v1beta1_ClusterStatus(in *clusterv1.Cluste
247247
return nil
248248
}
249249

250+
func Convert_v1beta1_Topology_To_v1beta2_Topology(in *Topology, out *clusterv1.Topology, s apimachineryconversion.Scope) error {
251+
if err := autoConvert_v1beta1_Topology_To_v1beta2_Topology(in, out, s); err != nil {
252+
return err
253+
}
254+
255+
out.ClassRef.Name = in.Class
256+
out.ClassRef.Namespace = in.ClassNamespace
257+
return nil
258+
}
259+
250260
func Convert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in *ClusterStatus, out *clusterv1.ClusterStatus, s apimachineryconversion.Scope) error {
251261
if err := autoConvert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in, out, s); err != nil {
252262
return err
@@ -307,6 +317,16 @@ func Convert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in *ClusterStatus, o
307317
return nil
308318
}
309319

320+
func Convert_v1beta2_Topology_To_v1beta1_Topology(in *clusterv1.Topology, out *Topology, s apimachineryconversion.Scope) error {
321+
if err := autoConvert_v1beta2_Topology_To_v1beta1_Topology(in, out, s); err != nil {
322+
return err
323+
}
324+
325+
out.Class = in.ClassRef.Name
326+
out.ClassNamespace = in.ClassRef.Namespace
327+
return nil
328+
}
329+
310330
func Convert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentStatus(in *clusterv1.MachineDeploymentStatus, out *MachineDeploymentStatus, s apimachineryconversion.Scope) error {
311331
if err := autoConvert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentStatus(in, out, s); err != nil {
312332
return err

api/v1beta1/zz_generated.conversion.go

Lines changed: 13 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/cluster_types.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -538,20 +538,9 @@ type ClusterAvailabilityGate struct {
538538

539539
// Topology encapsulates the information of the managed resources.
540540
type Topology struct {
541-
// class is the name of the ClusterClass object to create the topology.
541+
// classRef is the ref to the ClusterClass that should be used for the topology.
542542
// +required
543-
// +kubebuilder:validation:MinLength=1
544-
// +kubebuilder:validation:MaxLength=253
545-
Class string `json:"class"`
546-
547-
// classNamespace is the namespace of the ClusterClass object to create the topology.
548-
// If the namespace is empty or not set, it is defaulted to the namespace of the cluster object.
549-
// Value must follow the DNS1123Subdomain syntax.
550-
// +optional
551-
// +kubebuilder:validation:MinLength=1
552-
// +kubebuilder:validation:MaxLength=253
553-
// +kubebuilder:validation:Pattern=`^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$`
554-
ClassNamespace string `json:"classNamespace,omitempty"`
543+
ClassRef ClusterClassRef `json:"classRef"`
555544

556545
// version is the Kubernetes version of the cluster.
557546
// +required
@@ -586,6 +575,30 @@ type Topology struct {
586575
Variables []ClusterVariable `json:"variables,omitempty"`
587576
}
588577

578+
// ClusterClassRef is the ref to the ClusterClass that should be used for the topology.
579+
type ClusterClassRef struct {
580+
// name is the name of the ClusterClass that should be used for the topology.
581+
// name must be a valid ClusterClass name and because of that be at most 253 characters in length
582+
// and it must consist only of lower case alphanumeric characters, hyphens (-) and periods (.), and must start
583+
// and end with an alphanumeric character.
584+
// +required
585+
// +kubebuilder:validation:MinLength=1
586+
// +kubebuilder:validation:MaxLength=253
587+
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
588+
Name string `json:"name"`
589+
590+
// namespace is the namespace of the ClusterClass that should be used for the topology.
591+
// If namespace is empty or not set, it is defaulted to the namespace of the Cluster object.
592+
// namespace must be a valid namespace name and because of that be at most 63 characters in length
593+
// and it must consist only of lower case alphanumeric characters or hyphens (-), and must start
594+
// and end with an alphanumeric character.
595+
// +optional
596+
// +kubebuilder:validation:MinLength=1
597+
// +kubebuilder:validation:MaxLength=63
598+
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
599+
Namespace string `json:"namespace,omitempty"`
600+
}
601+
589602
// ControlPlaneTopology specifies the parameters for the control plane nodes in the cluster.
590603
type ControlPlaneTopology struct {
591604
// metadata is the metadata applied to the ControlPlane and the Machines of the ControlPlane
@@ -1180,8 +1193,8 @@ func (c *Cluster) GetClassKey() types.NamespacedName {
11801193
return types.NamespacedName{}
11811194
}
11821195

1183-
namespace := cmp.Or(c.Spec.Topology.ClassNamespace, c.Namespace)
1184-
return types.NamespacedName{Namespace: namespace, Name: c.Spec.Topology.Class}
1196+
namespace := cmp.Or(c.Spec.Topology.ClassRef.Namespace, c.Namespace)
1197+
return types.NamespacedName{Namespace: namespace, Name: c.Spec.Topology.ClassRef.Name}
11851198
}
11861199

11871200
// GetV1Beta1Conditions returns the set of conditions for this object.

api/v1beta2/index/cluster_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ func TestClusterByClusterClassRef(t *testing.T) {
4646
},
4747
Spec: clusterv1.ClusterSpec{
4848
Topology: &clusterv1.Topology{
49-
Class: "class1",
49+
ClassRef: clusterv1.ClusterClassRef{
50+
Name: "class1",
51+
},
5052
},
5153
},
5254
},
@@ -61,8 +63,10 @@ func TestClusterByClusterClassRef(t *testing.T) {
6163
},
6264
Spec: clusterv1.ClusterSpec{
6365
Topology: &clusterv1.Topology{
64-
Class: "class1",
65-
ClassNamespace: "other",
66+
ClassRef: clusterv1.ClusterClassRef{
67+
Name: "class1",
68+
Namespace: "other",
69+
},
6670
},
6771
},
6872
},

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/zz_generated.openapi.go

Lines changed: 36 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/clusterctl/client/cluster/assets/topology-test/existing-my-cluster.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ spec:
2626
name: my-cluster-zrq96
2727
namespace: default
2828
topology:
29-
class: my-cluster-class
29+
classRef:
30+
name: my-cluster-class
3031
version: v1.21.2
3132
controlPlane:
3233
metadata: {}

cmd/clusterctl/client/cluster/assets/topology-test/existing-my-second-cluster.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ spec:
2727
name: my-second-cluster-zrq96
2828
namespace: default
2929
topology:
30-
class: my-cluster-class
30+
classRef:
31+
name: my-cluster-class
3132
version: v1.21.2
3233
controlPlane:
3334
metadata: {}

cmd/clusterctl/client/cluster/assets/topology-test/modified-my-cluster.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ spec:
1313
cidrBlocks: ["192.168.0.0/16"]
1414
serviceDomain: "cluster.local"
1515
topology:
16-
class: my-cluster-class
16+
classRef:
17+
name: my-cluster-class
1718
version: v1.21.2
1819
controlPlane:
1920
metadata: {}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ spec:
186186
cidrBlocks: ["192.168.0.0/16"]
187187
serviceDomain: "cluster.local"
188188
topology:
189-
class: my-cluster-class
189+
classRef:
190+
name: my-cluster-class
190191
version: v1.21.2
191192
controlPlane:
192193
metadata: {}

0 commit comments

Comments
 (0)