Skip to content

Commit

Permalink
add support for Disable Inheritance in SpaceRequest (#946)
Browse files Browse the repository at this point in the history
* add support for Disable Inheritance in SpaceRequest
---------

Co-authored-by: Francisc Munteanu <fmuntean@redhat.com>
Co-authored-by: Matous Jobanek <mjobanek@redhat.com>
  • Loading branch information
3 people authored Feb 2, 2024
1 parent 06236eb commit dc76273
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
37 changes: 35 additions & 2 deletions controllers/spacerequest/spacerequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions pkg/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
6 changes: 6 additions & 0 deletions test/spacerequest/spacerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 7 additions & 0 deletions test/spacerequest/spacerequest_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dc76273

Please sign in to comment.