Skip to content

⚠️ Restructure classRef field in Cluster.spec.topology #12235

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ func Convert_v1beta2_ClusterStatus_To_v1beta1_ClusterStatus(in *clusterv1.Cluste
return nil
}

func Convert_v1beta1_Topology_To_v1beta2_Topology(in *Topology, out *clusterv1.Topology, s apimachineryconversion.Scope) error {
if err := autoConvert_v1beta1_Topology_To_v1beta2_Topology(in, out, s); err != nil {
return err
}

out.ClassRef.Name = in.Class
out.ClassRef.Namespace = in.ClassNamespace
return nil
}

func Convert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in *ClusterStatus, out *clusterv1.ClusterStatus, s apimachineryconversion.Scope) error {
if err := autoConvert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in, out, s); err != nil {
return err
Expand Down Expand Up @@ -307,6 +317,16 @@ func Convert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in *ClusterStatus, o
return nil
}

func Convert_v1beta2_Topology_To_v1beta1_Topology(in *clusterv1.Topology, out *Topology, s apimachineryconversion.Scope) error {
if err := autoConvert_v1beta2_Topology_To_v1beta1_Topology(in, out, s); err != nil {
return err
}

out.Class = in.ClassRef.Name
out.ClassNamespace = in.ClassRef.Namespace
return nil
}

func Convert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentStatus(in *clusterv1.MachineDeploymentStatus, out *MachineDeploymentStatus, s apimachineryconversion.Scope) error {
if err := autoConvert_v1beta2_MachineDeploymentStatus_To_v1beta1_MachineDeploymentStatus(in, out, s); err != nil {
return err
Expand Down
37 changes: 13 additions & 24 deletions api/v1beta1/zz_generated.conversion.go

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

37 changes: 22 additions & 15 deletions api/v1beta2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,20 +538,9 @@ type ClusterAvailabilityGate struct {

// Topology encapsulates the information of the managed resources.
type Topology struct {
// class is the name of the ClusterClass object to create the topology.
// classRef is the ref to the ClusterClass that should be used for the topology.
// +required
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Class string `json:"class"`

// classNamespace is the namespace of the ClusterClass object to create the topology.
// If the namespace is empty or not set, it is defaulted to the namespace of the cluster object.
// Value must follow the DNS1123Subdomain syntax.
// +optional
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$`
ClassNamespace string `json:"classNamespace,omitempty"`
ClassRef ClusterClassRef `json:"classRef"`

// version is the Kubernetes version of the cluster.
// +required
Expand Down Expand Up @@ -586,6 +575,24 @@ type Topology struct {
Variables []ClusterVariable `json:"variables,omitempty"`
}

// ClusterClassRef is the ref to the ClusterClass that should be used for the topology.
type ClusterClassRef struct {
// name is the name of the ClusterClass that should be used for the topology.
// +required
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Name string `json:"name"`

// namespace is the namespace of the ClusterClass that should be used for the topology.
// If the namespace is empty or not set, it is defaulted to the namespace of the cluster object.
// Value must follow the DNS1123Subdomain syntax.
// +optional
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$`
Namespace string `json:"namespace,omitempty"`
}

// ControlPlaneTopology specifies the parameters for the control plane nodes in the cluster.
type ControlPlaneTopology struct {
// metadata is the metadata applied to the ControlPlane and the Machines of the ControlPlane
Expand Down Expand Up @@ -1180,8 +1187,8 @@ func (c *Cluster) GetClassKey() types.NamespacedName {
return types.NamespacedName{}
}

namespace := cmp.Or(c.Spec.Topology.ClassNamespace, c.Namespace)
return types.NamespacedName{Namespace: namespace, Name: c.Spec.Topology.Class}
namespace := cmp.Or(c.Spec.Topology.ClassRef.Namespace, c.Namespace)
return types.NamespacedName{Namespace: namespace, Name: c.Spec.Topology.ClassRef.Name}
}

// GetV1Beta1Conditions returns the set of conditions for this object.
Expand Down
10 changes: 7 additions & 3 deletions api/v1beta2/index/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func TestClusterByClusterClassRef(t *testing.T) {
},
Spec: clusterv1.ClusterSpec{
Topology: &clusterv1.Topology{
Class: "class1",
ClassRef: clusterv1.ClusterClassRef{
Name: "class1",
},
},
},
},
Expand All @@ -61,8 +63,10 @@ func TestClusterByClusterClassRef(t *testing.T) {
},
Spec: clusterv1.ClusterSpec{
Topology: &clusterv1.Topology{
Class: "class1",
ClassNamespace: "other",
ClassRef: clusterv1.ClusterClassRef{
Name: "class1",
Namespace: "other",
},
},
},
},
Expand Down
16 changes: 16 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

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

50 changes: 36 additions & 14 deletions api/v1beta2/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 @@ -26,7 +26,8 @@ spec:
name: my-cluster-zrq96
namespace: default
topology:
class: my-cluster-class
classRef:
name: my-cluster-class
version: v1.21.2
controlPlane:
metadata: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ spec:
name: my-second-cluster-zrq96
namespace: default
topology:
class: my-cluster-class
classRef:
name: my-cluster-class
version: v1.21.2
controlPlane:
metadata: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ spec:
cidrBlocks: ["192.168.0.0/16"]
serviceDomain: "cluster.local"
topology:
class: my-cluster-class
classRef:
name: my-cluster-class
version: v1.21.2
controlPlane:
metadata: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ spec:
cidrBlocks: ["192.168.0.0/16"]
serviceDomain: "cluster.local"
topology:
class: my-cluster-class
classRef:
name: my-cluster-class
version: v1.21.2
controlPlane:
metadata: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ spec:
cidrBlocks: ["192.168.0.0/16"]
serviceDomain: "cluster.local"
topology:
class: my-cluster-class
classRef:
name: my-cluster-class
version: v1.21.2
controlPlane:
metadata: {}
Expand All @@ -34,7 +35,8 @@ spec:
cidrBlocks: ["192.168.0.0/16"]
serviceDomain: "cluster.local"
topology:
class: my-second-cluster-class
classRef:
name: my-second-cluster-class
version: v1.21.2
controlPlane:
metadata: {}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/cluster/objectgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,13 +827,13 @@ func (o *objectGraph) setShouldNotDelete(ctx context.Context, namespace string)
}

// ignore cluster not referencing a CC in the namespace being moved.
if cluster.Spec.Topology.ClassNamespace != namespace {
if cluster.Spec.Topology.ClassRef.Namespace != namespace {
continue
}

// Otherwise mark the referenced CC as should not be deleted.
for _, class := range o.getClusterClasses() {
if class.identity.Namespace == cluster.Spec.Topology.ClassNamespace && class.identity.Name == cluster.Spec.Topology.Class {
if class.identity.Namespace == cluster.Spec.Topology.ClassRef.Namespace && class.identity.Name == cluster.Spec.Topology.ClassRef.Name {
class.shouldNotDelete = true
// Ensure that also the templates referenced by the CC won't be deleted.
o.setShouldNotDeleteHierarchy(class)
Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterctl/client/clusterclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@ func TestAddClusterClassIfMissing(t *testing.T) {
fmt.Sprintf(" namespace: %s\n", tt.targetNamespace) +
"spec:\n" +
" topology:\n" +
" class: dev"
" classRef:\n" +
" name: dev"

if tt.clusterClassNamespace != "" {
clusterWithTopology = fmt.Sprintf("%s\n classNamespace: %s", clusterWithTopology, tt.clusterClassNamespace)
clusterWithTopology = fmt.Sprintf("%s\n namespace: %s", clusterWithTopology, tt.clusterClassNamespace)
}

baseTemplate, err := repository.NewTemplate(repository.TemplateInput{
Expand Down
Loading
Loading