Skip to content

Commit

Permalink
Allow cross-ns CC rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Jan 10, 2025
1 parent 1ae95a5 commit 5912b34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
6 changes: 3 additions & 3 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ 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. Empty namespace assumes the namespace of the cluster object.
// Class namespace changes are not supported by the rebase procedure, as different CC namespace uses namespace-local templates.
// Cluster templates namespace modification is not allowed.
// 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
Expand Down
14 changes: 0 additions & 14 deletions internal/topology/check/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,6 @@ func LocalObjectTemplatesAreCompatible(current, desired clusterv1.LocalObjectTem
currentGK.Kind, desiredGK.Kind),
))
}
allErrs = append(allErrs, LocalObjectTemplatesAreInSameNamespace(current, desired, pathPrefix)...)
return allErrs
}

// LocalObjectTemplatesAreInSameNamespace checks if two referenced objects are in the same namespace.
func LocalObjectTemplatesAreInSameNamespace(current, desired clusterv1.LocalObjectTemplate, pathPrefix *field.Path) field.ErrorList {
var allErrs field.ErrorList
if current.Ref.Namespace != desired.Ref.Namespace {
allErrs = append(allErrs, field.Forbidden(
pathPrefix.Child("ref", "namespace"),
fmt.Sprintf("templates must be in the same namespace as the ClusterClass (%s)",
current.Ref.Namespace),
))
}
return allErrs
}

Expand Down
22 changes: 11 additions & 11 deletions internal/topology/check/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestLocalObjectTemplatesAreCompatible(t *testing.T) {
APIVersion: "test.group.io/versiontwo",
},
}
incompatibleNamespaceChangeTemplate := clusterv1.LocalObjectTemplate{
compatibleNamespaceChangeTemplate := clusterv1.LocalObjectTemplate{
Ref: &corev1.ObjectReference{
Namespace: "different",
Name: "foo",
Expand Down Expand Up @@ -253,15 +253,15 @@ func TestLocalObjectTemplatesAreCompatible(t *testing.T) {
wantErr: false,
},
{
name: "Block change to template API Group",
name: "Allow change to template namespace",
current: template,
desired: incompatibleAPIGroupChangeTemplate,
wantErr: true,
desired: compatibleNamespaceChangeTemplate,
wantErr: false,
},
{
name: "Block change to template namespace",
name: "Block change to template API Group",
current: template,
desired: incompatibleNamespaceChangeTemplate,
desired: incompatibleAPIGroupChangeTemplate,
wantErr: true,
},
{
Expand Down Expand Up @@ -413,7 +413,7 @@ func TestClusterClassesAreCompatible(t *testing.T) {
APIVersion: "group.test.io/another-foo",
Kind: "barTemplate",
Name: "another-baz",
Namespace: "default",
Namespace: "other",
}

tests := []struct {
Expand Down Expand Up @@ -450,7 +450,7 @@ func TestClusterClassesAreCompatible(t *testing.T) {
},

{
name: "pass for compatible clusterClasses",
name: "pass for compatible clusterClasses from different NS",
current: builder.ClusterClass(metav1.NamespaceDefault, "class1").
WithInfrastructureClusterTemplate(
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
Expand All @@ -473,7 +473,7 @@ func TestClusterClassesAreCompatible(t *testing.T) {
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
Build()).
Build(),
desired: builder.ClusterClass(metav1.NamespaceDefault, "class1").
desired: builder.ClusterClass(metav1.NamespacePublic, "class1").
WithInfrastructureClusterTemplate(
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
WithControlPlaneTemplate(
Expand Down Expand Up @@ -712,7 +712,7 @@ func TestMachineDeploymentClassesAreCompatible(t *testing.T) {
APIVersion: "group.test.io/another-foo",
Kind: "barTemplate",
Name: "another-baz",
Namespace: "default",
Namespace: "other",
}
incompatibleRef := &corev1.ObjectReference{
APIVersion: "group.test.io/foo",
Expand Down Expand Up @@ -858,7 +858,7 @@ func TestMachinePoolClassesAreCompatible(t *testing.T) {
APIVersion: "group.test.io/another-foo",
Kind: "barTemplate",
Name: "another-baz",
Namespace: "default",
Namespace: "other",
}
incompatibleRef := &corev1.ObjectReference{
APIVersion: "group.test.io/foo",
Expand Down

0 comments on commit 5912b34

Please sign in to comment.