-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
API: add endpoint POST /v1/containers #349
base: master
Are you sure you want to change the base?
Conversation
Thanks @pini-gh ! I again won't be able to review this during work hours, but in the meantime, could you point me at the Sylabs client code where this is done? And explain why the existing endpoint is not sufficient? |
We have a bunch of scripts (bash + curl) which use this endpoint already with the Sylabs library. I'd prefer not to have to adapt them when switching to Singularity Registry Server. |
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'm a little confused about the use case for this view, but the code and documentation looks good! Could you better explain to me why we would want an endpoint to create a container that doesn't actually create it?
shub/apps/library/views/images.py
Outdated
def post(self, request): | ||
"""Mimic the creation a new container. | ||
|
||
POST /v1/coontainers |
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.
POST /v1/coontainers | |
POST /v1/containers |
return Response(message, status=400) | ||
|
||
try: | ||
collection_id = int(body["collection"]) |
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.
For the other function we convert everything to string (the ids) so we should probably be consistent and use one or the other, but not both.
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.
Here we need an integer to reuse later in:
collection = Collection.objects.get(id=collection_id)
In the other function, comparing strings instead of ints saves a try:
/ except:
block.
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.
yes, but if the collection doesn't exist, it will raise an error here, which you'd need to catch. .get
assumes an existing collection.
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.
Fixed.
shub/apps/library/views/images.py
Outdated
|
||
# check permissions | ||
# return 403 when collection does not exist or user is not an owner | ||
collection = Collection.objects.get(id=collection_id) |
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 is going to raise an error if it doesn't exist.
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.
Fixed.
shub/apps/library/views/images.py
Outdated
ignore here because containers' privacy is inherited from the | ||
collection they belong to. | ||
|
||
Return the newly created container. |
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 don't quite understand this endpoint - you mention that we return the newly created container, but then you mention that we "mimic the Sylabs library without actually creating the container object." What's the point?
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.
You're right. The comment should be fixed.
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.
Fixed.
This is a use case for the Sylabs library actually. And I need this endpoint to be enabled on sregistry as well so I can use the very same scripts whatever my registry is (Sylabs library or sregistry). |
Let's step back here for a second. You're asking to add an endpoint to Singularity Registry Server that doesn't actually work as expected - and only so you don't have to modify your current scripts. I'm not sure this is a reasonable request, and I'd suggest that we step back and look at the information that you need, which seems to be data for a collection. My suggestion is to add a try/except to your script, that on a 404 (or other) response to create the container, you instead do a request to get metadata about the collection (which seems to be what you are looking for). I'm happy to help you think through this. |
Well. This is not that simple. This endpoint:
As for my use case, let me reiterate: When I have to push a private image to a non-existing container I go through these steps with Sylabs library:
If I don't create the image first, it would be created during the push with If I want my scripts to work the same way with sregistry I need this endpoint. Or I'll end up having different snippets depending on which implementation the registry uses, which is not a good thing imho (reminds me web pages using different code blocks depending on the browser). |
The whole point is either way the sregistry data model is not compatible with the Sylabs API regarding container objects. You workaround this returning a false container object on calls to GET In my opinion the latter is more consistent than the former, because it involves the very same workflow as with the Sylabs library when pushing a new container. |
My concern is that by adding this view, we are requiring an additional ping of a completely non-essential endpoint to perform the same action - one more request to the registry that serves no purpose. If we get a 200 response here we can skip over that entire extra request. It's different than what the Sylabs library does, but it's logical in the context of Singularity Registry server because the idea of creating a container does not exist. I see your point and I empathize with (and think it's reasonable) that you want your curl calls to be consistent, but I'm not convinced that adding this extra endpoint adds any value to the registry (but might actually hurt it). |
o_O It brings a fix as well: the current GET |
Yes, but it's not technically required - we can return 200 off the bat and then skip the extra request. To require the extra request and (still) return a 200 response (for a container that does not exist) is not a significant improvement. |
Because you limit your use case to the interactions with the singularity client only. When using the API from any other use case, answering 200 instead of 404 is an error. |
Ok, that's definitely fair - If you can get support from others in the community and show me other usage of the Sylabs API outside of the Singularity client, then that would be enough to convince me. |
Oh well... Anyone? |
Hi @vsoch,
Here is another PR to add POST
/v1/containers
. With this new endpoint we can fix GET/v1/containers/<entity>/<collection>/<container>
so that it returns404
when the container doesn't exist.Tested against singularity client pushing to a non-existing container:
We see above that the client first checks for the container existence, then creates it if need be. While our new endpoint just mimics the container creation, this workflow matches the Sylabs library's one better, and avoids wrong answers on GET
/v1/containers/<entity>/<collection>/<container>
.