Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Detect if the user to init on Tenant already has a project on OSO (OSIO#1446) #554

Closed

Conversation

xcoulon
Copy link
Contributor

@xcoulon xcoulon commented Mar 9, 2018

Add function to list projects on OSO for the user, given his/her OSO token.
Check that there's no project, or a single project named after the user.
Include option in User service to support custom HTTP transport.
Rename vars in controller.Tenant to avoid collision with packages (user and cluster).
Add test on the controller.TenantController.Setup() method using go-vcr.
Add a function in openshift pkg to retrieve the name of the user's projects (and factorize
the code to perform the GET request on the Openshift API endpoint).

Also: use encoded token in the go-vcr recording for TestResolveServiceAccountToken

Fixes openshiftio/openshift.io#1446

Signed-off-by: Xavier Coulon [email protected]

@xcoulon xcoulon requested a review from aslakknutsen March 9, 2018 16:32
@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-1

…IO#1446)

Add function to list projects on OSO for the user, given his/her OSO token.
Check that there's no project,  otherwise, clean/remove all user's namespaces.
Include option in User service to support custom HTTP transport.
Rename vars in controller.Tenant to avoid collision with packages (`user` and `cluster`).
Add test on the controller.TenantController.Setup() method using `go-vcr`.
Add a function in `openshift` pkg to retrieve the name of the user's projects (and factorize
the code to perform the GET request on the Openshift API endpoint).

Also: use encoded token in the go-vcr recording for TestResolveServiceAccountToken

Fixes openshiftio/openshift.io#1446

Signed-off-by: Xavier Coulon <[email protected]>
@xcoulon xcoulon force-pushed the IssueOSIO1446_detect_OSO_project branch from bb40a68 to dc160d3 Compare March 9, 2018 17:18
@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-2

xcoulon added 2 commits March 13, 2018 16:21
do not use a go routine at first. Create the user's NS and check
the result, then use go routines for all other namespaces to create
@xcoulon xcoulon force-pushed the IssueOSIO1446_detect_OSO_project branch from 0eb1052 to a002aca Compare March 13, 2018 15:23
@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-3

- do not call the API to list the user's projects
- process the ProjectRequest response and return an error
if something wrong happened (403, 409, 500)

Signed-off-by: Xavier Coulon <[email protected]>
@xcoulon xcoulon force-pushed the IssueOSIO1446_detect_OSO_project branch from 5bda3d5 to 44d965a Compare March 13, 2018 17:51
@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-5

xcoulon added 3 commits March 16, 2018 11:31
…st header

Added some a custom method on the generated Goa contexts
to support `AbsolutURL` while taking into account the
optional `X-Forwarded-Path` request headers

Signed-off-by: Xavier Coulon <[email protected]>
also, splitted the single, wayyy too long `go-vcr` recording file
(yaml) into 1 file per test, to better understand and monitor
the requests that are executed.

Signed-off-by: Xavier Coulon <[email protected]>
@xcoulon xcoulon force-pushed the IssueOSIO1446_detect_OSO_project branch from a32a9e5 to c4d7a35 Compare March 16, 2018 17:41
@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-11

@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-13

Makefile Outdated
@@ -215,6 +215,9 @@ app/controllers.go: $(DESIGNS) $(GOAGEN_BIN) $(VENDOR_DIR)
$(GOAGEN_BIN) controller -d ${PACKAGE_NAME}/${DESIGN_DIR} -o controller/ --pkg controller --app-pkg app
$(GOAGEN_BIN) swagger -d ${PACKAGE_NAME}/${DESIGN_DIR}
$(GOAGEN_BIN) client -d github.com/fabric8-services/fabric8-auth/design --notool --out auth --pkg client
$(GOAGEN_BIN) client -d github.com/fabric8-services/fabric8-auth/design --notool --out auth --pkg client
Copy link
Contributor

Choose a reason for hiding this comment

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

above line is a duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch, thanks!

@@ -0,0 +1,173 @@
package errors
Copy link
Contributor

Choose a reason for hiding this comment

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

Why create a new one when we already have it in wit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I need some type of errors that are specific to tenant and openshift.

Copy link
Contributor

Choose a reason for hiding this comment

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

is there a way to put it in a place that like in https://github.com/fabric8-services and then use it from library? Won't this add up the code duplication? And errors/bgs getting replicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I've been thinking about it for a few packages, including errors and log amongst others. It would probably make sense to have something like fabric8-commons for all those shared pkgs. But that should be part of another PR, IMO

_, err := executeRequest(context.Background(),
request{
method: "DELETE",
url: fmt.Sprintf("%s/oapi/v1/projects/%s", strings.TrimSuffix(clusterURL, "/"), name),
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we use the client APIs to do this? https://github.com/kubernetes/client-go or if it is a OpenShift specific operation then we can also use https://github.com/openshift/client-go

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'm fine with that. @aslakknutsen, what do you think about it ?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could, but Openshift go client has historically been a beast and we only need like 2 simple REST calls

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok, maybe we would wanna consider moving all our api calls to client-go of openshift!

// "cassette_method": cassetteRequest.Method,
// "http_request_url": httpRequest.URL,
// "cassette_url": cassetteRequest.URL,
// }, "Cassette method/url doesn't match with the current request")
Copy link
Contributor

Choose a reason for hiding this comment

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

remove comments!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Signed-off-by: Xavier Coulon <[email protected]>
@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-14

@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-15

Copy link
Contributor

@surajssd surajssd left a comment

Choose a reason for hiding this comment

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

sure we can go forward with using the lib that has some code copied for sake of reducing dependency

@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-16

@xcoulon xcoulon force-pushed the IssueOSIO1446_detect_OSO_project branch from 28b8cce to 037eb0a Compare April 17, 2018 14:13
@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-18

Copy link
Contributor

@aslakknutsen aslakknutsen left a comment

Choose a reason for hiding this comment

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

Somehow we lost 'repo.CreateTenant'?

And for some reason Jenkins and Che refused to get provisioned in the users access.. ?

@xcoulon
Copy link
Contributor Author

xcoulon commented May 7, 2018

Somehow we lost 'repo.CreateTenant'?
And for some reason Jenkins and Che refused to get provisioned in the users access.. ?

@aslakknutsen could you clarify on the 2 problems you reported ?

@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-22

@aslakknutsen
Copy link
Contributor

aslakknutsen commented May 15, 2018

@xcoulon CreateTenant is never called: https://github.com/fabric8-services/fabric8-tenant/pull/554/files#diff-dfb0ecdc519ac765cb68432d078cc1d0L104

In the current v we changed it to use Create instead of Save, so the second attempt to provision the same user would fail. As there is no real clean path to when we provision a user in the live v we can get multiple concurrent requests to provision. So to avoid the second request starting the same process, they use the DB as a 'lock', only 1 request can sucessfully INSERT a tenant record. One of the two concurrent requests will pass, the rest will fail.

@aslakknutsen
Copy link
Contributor

@xcoulon About Che and Jenkins I'm unsure. It might be related to a local issue when I tried to run it, but all namespaces except Che and Jenkins provisioned just fine. Che and Jenkins failed for some reason.

@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-23

@xcoulon
Copy link
Contributor Author

xcoulon commented May 15, 2018

[test]

@codecov-io
Copy link

codecov-io commented May 15, 2018

Codecov Report

Merging #554 into master will increase coverage by 14.79%.
The diff coverage is 64.48%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #554       +/-   ##
===========================================
+ Coverage   35.37%   50.17%   +14.79%     
===========================================
  Files          31       36        +5     
  Lines        2086     2326      +240     
===========================================
+ Hits          738     1167      +429     
+ Misses       1259     1036      -223     
- Partials       89      123       +34
Impacted Files Coverage Δ
auth/auth_client.go 78.78% <ø> (-0.63%) ⬇️
jsonapi/error_handler.go 0% <ø> (ø) ⬆️
controller/tenants.go 79.45% <ø> (ø) ⬆️
goasupport/context/generate_context_ext.go 0% <0%> (ø)
cluster/service.go 75% <100%> (-2.02%) ⬇️
openshift/whoami.go 85.71% <100%> (+17.71%) ⬆️
openshift/delete_namespace.go 100% <100%> (ø)
token/decode.go 83.33% <100%> (+1.51%) ⬆️
tenant/repository.go 65.21% <100%> (+14.49%) ⬆️
cluster/resolve.go 57.14% <40%> (-1.2%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb89f5a...0b59af6. Read the comment docs.

@xcoulon
Copy link
Contributor Author

xcoulon commented May 15, 2018

@aslakknutsen I addressed the comment about the missing record in the db (#554 (comment)). Please let me know if it's ok now, and if the Che and Jenkins namespaces still cause troubles for you

@fabric8cd
Copy link
Contributor

@xcoulon snapshot fabric8-tenant image is available for testing. docker pull docker.io/fabric8/fabric8-tenant:SNAPSHOT-PR-554-24

@xcoulon
Copy link
Contributor Author

xcoulon commented May 16, 2018

[test]

@alexeykazakov
Copy link
Contributor

This seems to be outdated. Closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants