Skip to content

Commit 0f149c2

Browse files
committed
Restructure classRef field in Cluster.spec.topology
Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent 2fbb798 commit 0f149c2

29 files changed

+268
-162
lines changed

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/v1beta2/cluster_types.go

Lines changed: 22 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,24 @@ 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+
// +required
582+
// +kubebuilder:validation:MinLength=1
583+
// +kubebuilder:validation:MaxLength=253
584+
Name string `json:"name"`
585+
586+
// namespace is the namespace of the ClusterClass that should be used for the topology.
587+
// If the namespace is empty or not set, it is defaulted to the namespace of the cluster object.
588+
// Value must follow the DNS1123Subdomain syntax.
589+
// +optional
590+
// +kubebuilder:validation:MinLength=1
591+
// +kubebuilder:validation:MaxLength=253
592+
// +kubebuilder:validation:Pattern=`^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$`
593+
Namespace string `json:"namespace,omitempty"`
594+
}
595+
589596
// ControlPlaneTopology specifies the parameters for the control plane nodes in the cluster.
590597
type ControlPlaneTopology struct {
591598
// metadata is the metadata applied to the ControlPlane and the Machines of the ControlPlane
@@ -1180,8 +1187,8 @@ func (c *Cluster) GetClassKey() types.NamespacedName {
11801187
return types.NamespacedName{}
11811188
}
11821189

1183-
namespace := cmp.Or(c.Spec.Topology.ClassNamespace, c.Namespace)
1184-
return types.NamespacedName{Namespace: namespace, Name: c.Spec.Topology.Class}
1190+
namespace := cmp.Or(c.Spec.Topology.ClassRef.Namespace, c.Namespace)
1191+
return types.NamespacedName{Namespace: namespace, Name: c.Spec.Topology.ClassRef.Name}
11851192
}
11861193

11871194
// 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: {}

cmd/clusterctl/client/cluster/assets/topology-test/objects-in-different-namespaces.yaml

Lines changed: 4 additions & 2 deletions
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: {}
@@ -34,7 +35,8 @@ spec:
3435
cidrBlocks: ["192.168.0.0/16"]
3536
serviceDomain: "cluster.local"
3637
topology:
37-
class: my-second-cluster-class
38+
classRef:
39+
name: my-second-cluster-class
3840
version: v1.21.2
3941
controlPlane:
4042
metadata: {}

cmd/clusterctl/client/cluster/objectgraph.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,13 +827,13 @@ func (o *objectGraph) setShouldNotDelete(ctx context.Context, namespace string)
827827
}
828828

829829
// ignore cluster not referencing a CC in the namespace being moved.
830-
if cluster.Spec.Topology.ClassNamespace != namespace {
830+
if cluster.Spec.Topology.ClassRef.Namespace != namespace {
831831
continue
832832
}
833833

834834
// Otherwise mark the referenced CC as should not be deleted.
835835
for _, class := range o.getClusterClasses() {
836-
if class.identity.Namespace == cluster.Spec.Topology.ClassNamespace && class.identity.Name == cluster.Spec.Topology.Class {
836+
if class.identity.Namespace == cluster.Spec.Topology.ClassRef.Namespace && class.identity.Name == cluster.Spec.Topology.ClassRef.Name {
837837
class.shouldNotDelete = true
838838
// Ensure that also the templates referenced by the CC won't be deleted.
839839
o.setShouldNotDeleteHierarchy(class)

cmd/clusterctl/client/clusterclass_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@ func TestAddClusterClassIfMissing(t *testing.T) {
219219
fmt.Sprintf(" namespace: %s\n", tt.targetNamespace) +
220220
"spec:\n" +
221221
" topology:\n" +
222-
" class: dev"
222+
" classRef:\n" +
223+
" name: dev"
223224

224225
if tt.clusterClassNamespace != "" {
225-
clusterWithTopology = fmt.Sprintf("%s\n classNamespace: %s", clusterWithTopology, tt.clusterClassNamespace)
226+
clusterWithTopology = fmt.Sprintf("%s\n namespace: %s", clusterWithTopology, tt.clusterClassNamespace)
226227
}
227228

228229
baseTemplate, err := repository.NewTemplate(repository.TemplateInput{

0 commit comments

Comments
 (0)