From dc7627393870d3ac3895071db1a41eadbcc24860 Mon Sep 17 00:00:00 2001 From: Martin Mulholland <71444914+mmulholla@users.noreply.github.com> Date: Fri, 2 Feb 2024 07:54:41 -0500 Subject: [PATCH] add support for Disable Inheritance in SpaceRequest (#946) * add support for Disable Inheritance in SpaceRequest --------- Co-authored-by: Francisc Munteanu Co-authored-by: Matous Jobanek --- .../spacerequest_controller_test.go | 37 ++++++++++++++++++- pkg/space/space.go | 1 + test/spacerequest/spacerequest.go | 6 +++ test/spacerequest/spacerequest_assertions.go | 7 ++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/controllers/spacerequest/spacerequest_controller_test.go b/controllers/spacerequest/spacerequest_controller_test.go index 59cb505fd..0dc27d058 100644 --- a/controllers/spacerequest/spacerequest_controller_test.go +++ b/controllers/spacerequest/spacerequest_controller_test.go @@ -42,7 +42,8 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("success", func(t *testing.T) { sr := spacerequesttest.NewSpaceRequest("jane", srNamespace.GetName(), spacerequesttest.WithTierName("appstudio"), - spacerequesttest.WithTargetClusterRoles(srClusterRoles)) + spacerequesttest.WithTargetClusterRoles(srClusterRoles), + spacerequesttest.WithDisableInheritance(false)) t.Run("subSpace doesn't exists it should be created", func(t *testing.T) { // given @@ -59,12 +60,44 @@ func TestCreateSpaceRequest(t *testing.T) { spacerequesttest.AssertThatSpaceRequest(t, srNamespace.Name, sr.GetName(), member1.Client). HasSpecTargetClusterRoles(srClusterRoles). HasSpecTierName("appstudio"). + HasDisableInheritance(false). HasConditions(spacetest.Provisioning()). HasFinalizer() // there should be 1 subSpace that was created from the spacerequest spacetest.AssertThatSubSpace(t, hostClient, sr, parentSpace). HasTier("appstudio"). - HasSpecTargetClusterRoles(srClusterRoles) + HasSpecTargetClusterRoles(srClusterRoles). + HasDisableInheritance(false) + }) + + t.Run("subSpace created with disableInheritance", func(t *testing.T) { + sr := spacerequesttest.NewSpaceRequest("jane", srNamespace.GetName(), + spacerequesttest.WithTierName("appstudio"), + spacerequesttest.WithTargetClusterRoles(srClusterRoles), + spacerequesttest.WithDisableInheritance(true)) + + // given + member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + hostClient := test.NewFakeClient(t, appstudioTier, parentSpace) + ctrl := newReconciler(t, hostClient, member1) + + // when + _, err = ctrl.Reconcile(context.TODO(), requestFor(sr)) + + // then + require.NoError(t, err) + // spacerequest exists with expected cluster roles and finalizer + spacerequesttest.AssertThatSpaceRequest(t, srNamespace.Name, sr.GetName(), member1.Client). + HasSpecTargetClusterRoles(srClusterRoles). + HasSpecTierName("appstudio"). + HasDisableInheritance(true). + HasConditions(spacetest.Provisioning()). + HasFinalizer() + // there should be 1 subSpace that was created from the spacerequest + spacetest.AssertThatSubSpace(t, hostClient, sr, parentSpace). + HasTier("appstudio"). + HasSpecTargetClusterRoles(srClusterRoles). + HasDisableInheritance(true) }) t.Run("subSpace exists but is not ready yet", func(t *testing.T) { diff --git a/pkg/space/space.go b/pkg/space/space.go index 35a67f6cb..8d496b835 100644 --- a/pkg/space/space.go +++ b/pkg/space/space.go @@ -47,6 +47,7 @@ func NewSubSpace(spaceRequest *toolchainv1alpha1.SpaceRequest, parentSpace *tool TargetClusterRoles: spaceRequest.Spec.TargetClusterRoles, TierName: spaceRequest.Spec.TierName, ParentSpace: parentSpace.GetName(), + DisableInheritance: spaceRequest.Spec.DisableInheritance, }, } diff --git a/test/spacerequest/spacerequest.go b/test/spacerequest/spacerequest.go index 7aad24cec..d5267e1a4 100644 --- a/test/spacerequest/spacerequest.go +++ b/test/spacerequest/spacerequest.go @@ -39,6 +39,12 @@ func WithTargetClusterRoles(targetClusterRoles []string) Option { } } +func WithDisableInheritance(disableInheritance bool) Option { + return func(spaceRequest *toolchainv1alpha1.SpaceRequest) { + spaceRequest.Spec.DisableInheritance = disableInheritance + } +} + func WithDeletionTimestamp() Option { return func(spaceRequest *toolchainv1alpha1.SpaceRequest) { now := metav1.NewTime(time.Now()) diff --git a/test/spacerequest/spacerequest_assertions.go b/test/spacerequest/spacerequest_assertions.go index 5e4a201cd..865603f25 100644 --- a/test/spacerequest/spacerequest_assertions.go +++ b/test/spacerequest/spacerequest_assertions.go @@ -119,6 +119,13 @@ func (a *Assertion) HasSpecTierName(tierName string) *Assertion { return a } +func (a *Assertion) HasDisableInheritance(disableInheritance bool) *Assertion { + err := a.loadResource() + require.NoError(a.t, err) + assert.Equal(a.t, disableInheritance, a.spaceRequest.Spec.DisableInheritance) + return a +} + func (a *Assertion) HasTargetClusterURL(targetCluster string) *Assertion { err := a.loadResource() require.NoError(a.t, err)