-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: Specify image in server request #452
Conversation
At first sight, the code looks great. I'm going to test this soon. Should we add a few more tests to cover the newly created functions, including |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good and seems to give us what we need! 🎉
The only bigger refactoring that I would propose is to try and make the logic for checking the existence of an image a bit more simple and generic. I believe that this should be possible doing something along those lines:
- if image does not include host, prepend
registry-1.docker.io/
- parse image into
host, repository, tag
- get request to
https://{host}/v2/{repository}/manifests/{tag}
, if 200, image exists, all good, return - if 401, get token URL and service from the
Www-Authenticate
header of the 401 response - do access token request with specifying the pull scope for the given repository (for RenkuLab's gitlab include the users oauth token at
Authorization: basic {gitlab_oauth_token}
) - use aquired access token for another get request to
https://{host}/v2/{repository}/manifests/{tag}
, if 200, image exists, all good, return
I haven't tested this through myself, but I'm pretty sure that this (or some small variations of it should work. This would allow for all publicly available image registries and reduce the need for all the logical branching in the code.
@lorenzo-cavazzi I can add the tests you suggest that is a good idea. @ableuler if a response from the API (either for docker or gitlab) without a token tells you where to go to authenticate then that is great. This is what I had issues with - I did not try to see what is in the response when you do not have a token. The most trouble I had is figuring out the URL to authenticate for renku's gitlab (which may also change with different deployments) and also even for a managed gitlab. So I will try what you propose. I originally did want to have a more unified approach but gave up mostly because I was not sure what is the endpoint where you should authenticate. |
Yes, that's not specified since the token endpoint is not part of the registry itself. The v2 registry documentation only specifies how the client must be informed about where to authenticate: https://github.com/docker/distribution/blob/c192a281f8ac6f2a351fe729c8a56108f8edb377/docs/spec/auth/token.md#how-to-authenticate |
Thanks @olevski! I have yet to test it out but I'm a bit confused by this:
You have the Two more points:
|
This applies only when no custom The second one is a good point, we didn't consider the information is already there and I thought an annotation was the easiest solution. |
So I think I either have some really weird behaviour with telepresence or someone else is trying to run telepresence at the same time as me right now. If it is the latter then sorry for reinstalling the whole deployment a few times. I did not think of this. Also I just deployed some new code that addresses Andreas' comments. I have not had a chance to test it out fully yet. But checking for a public image is now much simpler as Andreas suggested. I did not know about the |
@olevski sometimes when telepresence doesn't exit properly, you have to clean up manually:
After that the application should be in a clean state again and you should be able to start another telepresence session normally. |
Ok so I made additional changes to the code to address comments you all posted:
Let me know what you think. |
Right, this is the behavior I'm talking about changing. Maybe it's better to do it in a separate PR, but atm it can happen that a user's environment will be created with some default image, even though they think they asked for something else. This situation is super confusing. It's true that this is normally handled by the UI, but we've had cases where there was some issue with the image late in the process which resulted in the default image being used and things got super confusing. So my point is just that I'd rather be conservative and fail early in this case. |
If that is a desirable change, I'd rather do it now than later since we are adding variables both here and in the UI to handle that specific case better. |
Ok this is super weird, the tests I added pass on python 3.8.5 (which is the version in my local environment) but fail on python 3.7 which is what is used on the tests in the git actions. Will figure this out. I switched to 3.7 and I can replicate the failed tests. So I can figure out what the problem is. We should also maybe specify the python version in the pipfile so that we avoid similar issues in the future. |
Hi guys, sorry for the delays. But I fixed the tests I mentioned were failing earlier - they were failing because the In addition to this I addressed all the outstanding comments and did some tests to confirm everything works. When someone requests a nested gitlab image now things work (as long as the image exists). This is currently deployed at https://tasko.dev.renku.ch/. Lastly one thing I did not touch and I think we agreed on tackling this in a separate PR is what is returned when repeated POST or GET requests are made to the endpoint that creates the servers (and the sever tied to that commit exists). Currently the server that was created is returned but if one changes the image in the POST request the response is the original server that was created even though the original server has a different image than in the POST request. I propose that we tackle this in a separate PR. One last thing that I wanted to mention is that I added tests for the logic of requesting a non-existent image, the case where you should fall back to the default or the case where a specific image is requested. These are only unit tests but they still test that the expected image name is found in the request to create the server on the backend. |
If someone is testing right now, I have to deploy an older version to test something else at https://tasko.dev.renku.ch/. Will post back when the version tied to this PR is back on. |
ok the version that matches this PR is back on https://tasko.dev.renku.ch/ |
I am trying to work with this PR while developing the UI counterpart. All seems to work fine for a while, then I start getting The response to
The 2 relevant entries logged in the notebook pod are
If I try to log out and log in again, everything works fine.
It seems that renku-notebooks considers the credentials expired but they aren't -- I can browse private repositories in the UI without problems. Maybe the error is misleading and the issue is with the JypiterHub credentials that we use to create a server but we don't use to get the servers list through P.S. I've used a private project, but it's the same with public projects. |
@lorenzo-cavazzi I cannot replicate the behaviour you describe exactly. I think I did get something similar though because for a while even though I was logged in as This is also really weird because I did not touch the authentication code at all in this PR. |
Jupyterhub gets its gitlab oauth token "directly" from gitlab (without the gateway being involved). This can lead to weird login situations where the gateway has a gitlab oauth token for user A and Jupyterhub has one for user B. Especially in our dev setup where different RenkuLab instances rely on the same gitlab AND we often juggle with multiple users, this is likely to happen. I am pretty confident that this is unrelated to the code changes proposed in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're there 🎉 .
Only 3 one-liner suggestions.
Co-authored-by: Andreas Bleuler <[email protected]>
Co-authored-by: Andreas Bleuler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Closes #304
It took a while because I realized that some of the code I wrote was already present when we are checking for the gitlab image. So I spent a bit more time to clean this up and avoid repeating/similar code.
The logic implemented here is as follows:
image
in the payload from the request to create a new user interactive serverimage
is found then:image
is not found (what we had before this PR):Also in every of the above cases the following annotations are added to the user pod that is launched:
renku.io/default_image_used
,True
orFalse
depending on wheter the image tied to the current commit could not be found and the default image was used insteadrenku.io/image
, the name of the image used i.e.renku/renkulab-py:3.7-renku0.10.4-0.6.3
This is currently deployed at
https://tasko.dev.renku.ch/
. I found the easiest way to test is to just use telepresence and replaceNone
with an image value that you would like to test in hererequested_image = payload.get("image", None)
in line 85 inapi/notebooks.py
.