Skip to content

Commit

Permalink
Allow cross-namespace template instances
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Nov 1, 2024
1 parent 9f5a94e commit 865ef0e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 29 deletions.
10 changes: 0 additions & 10 deletions controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,6 @@ func validateKubeadmControlPlaneSpec(s controlplanev1.KubeadmControlPlaneSpec, n
),
)
}
if s.MachineTemplate.InfrastructureRef.Namespace != namespace {
allErrs = append(
allErrs,
field.Invalid(
pathPrefix.Child("machineTemplate", "infrastructure", "namespace"),
s.MachineTemplate.InfrastructureRef.Namespace,
"must match metadata.namespace",
),
)
}

// Validate the metadata of the MachineTemplate
allErrs = append(allErrs, s.MachineTemplate.ObjectMeta.Validate(pathPrefix.Child("machineTemplate", "metadata"))...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import (
)

var (
invalidNamespaceName = "bar"
ctx = ctrl.SetupSignalHandler()
ctx = ctrl.SetupSignalHandler()
)

func TestKubeadmControlPlaneDefault(t *testing.T) {
Expand Down Expand Up @@ -116,9 +115,6 @@ func TestKubeadmControlPlaneValidateCreate(t *testing.T) {
val := intstr.FromString("1")
stringMaxSurge.Spec.RolloutStrategy.RollingUpdate.MaxSurge = &val

invalidNamespace := valid.DeepCopy()
invalidNamespace.Spec.MachineTemplate.InfrastructureRef.Namespace = invalidNamespaceName

missingReplicas := valid.DeepCopy()
missingReplicas.Spec.Replicas = nil

Expand Down Expand Up @@ -182,11 +178,6 @@ func TestKubeadmControlPlaneValidateCreate(t *testing.T) {
expectErr: false,
kcp: valid,
},
{
name: "should return error when kubeadmControlPlane namespace and infrastructureTemplate namespace mismatch",
expectErr: true,
kcp: invalidNamespace,
},
{
name: "should return error when replicas is nil",
expectErr: true,
Expand Down Expand Up @@ -446,9 +437,6 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) {
scaleToEven := before.DeepCopy()
scaleToEven.Spec.Replicas = ptr.To[int32](2)

invalidNamespace := before.DeepCopy()
invalidNamespace.Spec.MachineTemplate.InfrastructureRef.Namespace = invalidNamespaceName

missingReplicas := before.DeepCopy()
missingReplicas.Spec.Replicas = nil

Expand Down Expand Up @@ -765,12 +753,6 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) {
before: before,
kcp: scaleToEven,
},
{
name: "should return error when trying to reference cross namespace",
expectErr: true,
before: before,
kcp: invalidNamespace,
},
{
name: "should return error when trying to scale to nil",
expectErr: true,
Expand Down
1 change: 1 addition & 0 deletions exp/topology/desiredstate/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ func templateToTemplate(in templateToInput) (*unstructured.Unstructured, error)
if in.currentObjectRef != nil && in.currentObjectRef.Name != "" {
template.SetName(in.currentObjectRef.Name)
}
template.SetNamespace(in.cluster.Namespace)

return template, nil
}
Expand Down

0 comments on commit 865ef0e

Please sign in to comment.