Skip to content
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

fix: add spacebindingrequests to workspace binding list #387

Merged
merged 18 commits into from
Feb 5, 2024

Conversation

mfrancisc
Copy link
Contributor

@mfrancisc mfrancisc commented Jan 9, 2024

Users are unable to manage SpaceBindingRequests that are not provisioned ( meaning there is no SpaceBinding associated with it).

This PR adds the SpaceBindingRequests ( that have no SpaceBinding associated) to the list of Bindings in the Workspace, so that RHTAP users can manage them from the UI.

Jira: https://issues.redhat.com/browse/ASC-443

Related PR:

TODO:

  • Update E2E tests

Copy link
Contributor

@filariow filariow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job! just a few nits

pkg/proxy/handlers/spacelister_get.go Outdated Show resolved Hide resolved
pkg/proxy/proxy.go Outdated Show resolved Hide resolved
pkg/proxy/proxy.go Show resolved Hide resolved
pkg/proxy/handlers/spacelister_get.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 9, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (8e59443) 78.03% compared to head (dae3ca8) 78.40%.

Files Patch % Lines
pkg/proxy/handlers/spacelister_get.go 93.47% 4 Missing and 2 partials ⚠️
pkg/proxy/proxy.go 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #387      +/-   ##
==========================================
+ Coverage   78.03%   78.40%   +0.37%     
==========================================
  Files          38       38              
  Lines        3223     3306      +83     
==========================================
+ Hits         2515     2592      +77     
- Misses        616      620       +4     
- Partials       92       94       +2     
Flag Coverage Δ
unittests 78.40% <92.15%> (+0.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

mfrancisc and others added 2 commits January 10, 2024 09:51
Co-authored-by: Francesco Ilario <filario@redhat.com>
Co-authored-by: Francesco Ilario <filario@redhat.com>
@mfrancisc
Copy link
Contributor Author

/retest

Copy link
Contributor

@filariow filariow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@sadlerap sadlerap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but one optional thing that might be beneficial.

pkg/proxy/handlers/spacelister_get.go Outdated Show resolved Hide resolved
@@ -77,9 +79,16 @@ func GetUserWorkspace(ctx echo.Context, spaceLister *SpaceLister, workspaceName
ctx.Logger().Error(fmt.Sprintf("unauthorized access - there is no SpaceBinding present for the user %s and the workspace %s", userSignup.CompliantUsername, workspaceName))
return nil, nil
}

// list all SpaceBindingRequests , just in case there might be some failing to create a SpaceBinding resource.
allSpaceBindingRequests, err := listSpaceBindingRequestsForSpace(ctx, GetMembersFunc, space)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned about adding even more stuff to the GetUserWorkspace() function. This function is currently used not only in our WS lister API but it's called for every request to the proxy in case there is a workspace context in the request. And we don't care about failed SBRs in that case (or even about the available user roles either btw).
Maybe it's time to split this function to two? One to remain a lightweight version for the general proxy requests and and with all additional information for the WS lister. Or make this function flexible/configurable so it can be used everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Let me take a look an split it so that proxy request do not have to populate the bindings list. Thanks for the suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexeykazakov @MatousJobanek I've created 2 functions GetUserWorkspace used by proxy only and GetUserWorkspaceWithBindings used by the spacelister.

Please take a look when you have some time.

PS: there is one new error condition which is not tested 574d4eb#diff-23bf3528567b934bf6ab8d0d690dc61a0ac564ba1b43b89cb5ddde609bb150b1R75-R79 , I can add a specific test in the proxy_test.go as I'm not sure where that should go in the current TestProxy since it's more a combination of different headers and requests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that important where you add this test. Add it to whatever place you think makes sense. But let's add a test for it if it's not too tricky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a specific test for this error condition in 98d2640

mfrancisc and others added 4 commits January 15, 2024 18:11
Co-authored-by: Andy Sadler <ansadler@redhat.com>
# Conflicts:
#	go.mod
#	go.sum
#	pkg/proxy/proxy.go
# Conflicts:
#	go.mod
#	go.sum
space, err := spaceLister.GetInformerServiceFunc().GetSpace(workspaceName)
if err != nil {
ctx.Logger().Error(errs.Wrap(err, "unable to get space"))
return userSignup, nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why returning nil instead of err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left the functionality unchanged

space, err := spaceLister.GetInformerServiceFunc().GetSpace(workspaceName)
if err != nil {
ctx.Logger().Error(errs.Wrap(err, "unable to get space"))
return nil, nil
}

I see we return 404 when when usersignup and space are not found.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's add a comment to the function description stating that if no space found then a "nil" returned instead of an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. Done 52690f3

# Conflicts:
#	pkg/proxy/handlers/spacelister_test.go
Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall but it looks like we could add more unit tests.
Could you please take a look at the codecov report and cover the missing cases when it's not too tricky?

Copy link
Contributor

@filariow filariow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mfrancisc
Copy link
Contributor Author

Could you please take a look at the codecov report and cover the missing cases when it's not too tricky?

@alexeykazakov thanks for pointing that out, I've added some more unit tests to cover the error cases, please take a look at 1c1fa6f

Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks.

Copy link

openshift-ci bot commented Feb 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, filariow, mfrancisc, sadlerap

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Feb 2, 2024
Copy link

sonarqubecloud bot commented Feb 5, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

8 New issues
0 Security Hotspots
No data about Coverage
9.3% Duplication on New Code

See analysis details on SonarCloud

@mfrancisc mfrancisc merged commit 545695d into codeready-toolchain:master Feb 5, 2024
11 of 12 checks passed
@mfrancisc mfrancisc deleted the fixbindinglist branch February 5, 2024 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants