-
Notifications
You must be signed in to change notification settings - Fork 394
allow to use context for getting signatures #316
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
Conversation
|
ACK, something like that needs to happen, but You only care about |
|
@mtrmac yes, that is correct. I can add this as new argument for |
|
(BTW if you are planning to carry this patch, there are more places that need to be patched: |
https://golang.org/pkg/context/ says
so this would be an even bigger API break. Oh well, we can do it, or perhaps add … (For reference, previous stab at this: #43 ) |
|
Right we don't have an API commitment yet so I'm fine adding CTX to the first argument of interfaces so we'll be more idiomatic. I had started doing this somewhere in another PR also but not sure where it went. I'm +1 here |
|
i'm fine with adding |
|
(for now we only care about signatures, so I can plumb that, leaving you guys with the rest ;-) |
8316870 to
f6b7b85
Compare
runcom
left a comment
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.
Seems ok but I want to explicitly use context.TODO or context.Background when you pass nil as context
directory/directory_test.go
Outdated
| require.NoError(t, err) | ||
| defer src.Close() | ||
| sigs, err := src.GetSignatures() | ||
| sigs, err := src.GetSignatures(nil) |
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 believe we want to pass context.TODO here even if this is a test (or context.Background better)
docker/docker_client.go
Outdated
| // The host name and schema is taken from the client or autodetected, and the path is relative to it, i.e. the path usually starts with /v2/. | ||
| func (c *dockerClient) makeRequest(method, path string, headers map[string][]string, stream io.Reader) (*http.Response, error) { | ||
| func (c *dockerClient) makeRequest(ctx context.Context, method, path string, headers map[string][]string, stream io.Reader) (*http.Response, error) { | ||
| if err := c.detectProperties(); err != nil { |
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 function also needs ctx
docker/docker_client.go
Outdated
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if ctx != nil { |
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.
We should make sure context is either todo or background here so I'll drop this if.
req.WithContext can accept nil?
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.
req.WithContext can't accept nil unfortunately but context.Background seems ok here?
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 please :)
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.
Why should this accept nil? nil is an invalid Context value, and callers who pass it should just crash. This PR is already touching all callers, so it can ensure that nil is never used.
Or am I missing anything?
docker/docker_client.go
Outdated
| url := fmt.Sprintf(resolvedPingV2URL, scheme, c.registry) | ||
| resp, err := c.makeRequestToResolvedURL("GET", url, nil, nil, -1, true) | ||
| // FIXME: Pass the context.Context | ||
| resp, err := c.makeRequestToResolvedURL(nil, "GET", url, nil, nil, -1, true) |
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.
Use context.TODO or Background
docker/docker_image.go
Outdated
| path := fmt.Sprintf(tagsPath, reference.Path(i.src.ref.ref)) | ||
| res, err := i.src.c.makeRequest("GET", path, nil, nil) | ||
| // FIXME: Pass the context.Context | ||
| res, err := i.src.c.makeRequest(nil, "GET", path, nil, nil) |
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.
TODO or Background
d054424 to
61bb862
Compare
|
@runcom all fixed :) |
|
@mfojtik you need to sign your commits ( |
|
@runcom i'm sure they are signed :-) (github shows "verified") i guess you checking the commit message? |
|
@mfojtik Verified means GPG signed, you need "Signed-by" |
|
@runcom the bot still does not like me :/ |
|
seems like everything's ok now |
|
you just need to rebase this I guess |
|
@runcom already did :) |
|
ok weird... i must have the link to travis cached... all green now. guess this is ready for shipping? |
|
LGTM but we also need @mtrmac review :) |
storage/storage_image.go
Outdated
| func (s *storageImageSource) GetSignatures() (signatures [][]byte, err error) { | ||
| func (s *storageImageSource) GetSignatures(ctx context.Context) (signatures [][]byte, err error) { | ||
| var offset int | ||
| // FIXME: pass the context.Context |
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.
containers/storage is generally dealing with local files, ignoring the ctx here should be fine.
| } | ||
|
|
||
| func (s *openshiftImageSource) GetSignatures() ([][]byte, error) { | ||
| func (s *openshiftImageSource) GetSignatures(ctx context.Context) ([][]byte, error) { |
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.
Could this one be implemented now?
I’m perfectly fine with having context support missing in most of the API, but when it exists, it would be better for users if it reliably worked.
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 containers/image should switch to use the client-go from openshift as external dependency once we cut that out. In that case the context will be available.
This change was just to satisfy the interface.
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.
In the mean time we would still have unreliable API, that’s not great. I’ll take a stab at this.
(As for using the OpenShift client, that would be great (I extracting those thousand lines in openshift-copies.go was annoying and by now it’s probably pretty behind the original, and I do hate the duplication), but the two times this was attempted, it added 60? MB to the size of skopeo, which is just too much.)
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.
@mfojtik added in https://github.com/mtrmac/image/tree/add-context-openshift , can you add that into this PR?
(Disclaimer: I’m still on Go 1.6, so this is untested. I’ll have to update ~immediately, I know.)
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.
added your commit.
docker/docker_client.go
Outdated
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if ctx != nil { |
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.
Why should this accept nil? nil is an invalid Context value, and callers who pass it should just crash. This PR is already touching all callers, so it can ensure that nil is never used.
Or am I missing anything?
| url := fmt.Sprintf(resolvedPingV2URL, scheme, c.registry) | ||
| resp, err := c.makeRequestToResolvedURL("GET", url, nil, nil, -1, true) | ||
| // FIXME: Pass the context.Context | ||
| resp, err := c.makeRequestToResolvedURL(ctx, "GET", url, nil, nil, -1, true) |
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.
The FIXME seems to already have been resolved.
docker/docker_client.go
Outdated
| req = req.WithContext(ctx) | ||
| } else { | ||
| req = req.WithContext(context.Background()) | ||
| } |
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.
Below this, setupRequestAuth and getBearerToken also need Context support.
| url := fmt.Sprintf(resolvedPingV1URL, scheme, c.registry) | ||
| resp, err := c.makeRequestToResolvedURL("GET", url, nil, nil, -1, true) | ||
| // FIXME: Pass the context.Context | ||
| resp, err := c.makeRequestToResolvedURL(ctx, "GET", url, nil, nil, -1, true) |
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.
The FIXME seems to already have been resolved.
docker/docker_image_dest.go
Outdated
| uploadPath := fmt.Sprintf(blobUploadPath, reference.Path(d.ref.ref)) | ||
| logrus.Debugf("Uploading %s", uploadPath) | ||
| res, err := d.c.makeRequest("POST", uploadPath, nil, nil) | ||
| res, err := d.c.makeRequest(context.Background(), "POST", uploadPath, nil, nil) |
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.
All of the .Background() in this file should be .TODO() AFAICT.
docker/docker_image_dest.go
Outdated
| // but the X-Registry-Supports-Signatures API extension does not support that yet. | ||
|
|
||
| existingSignatures, err := d.c.getExtensionsSignatures(d.ref, d.manifestDigest) | ||
| existingSignatures, err := d.c.getExtensionsSignatures(nil, d.ref, d.manifestDigest) |
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.
context.TODO(), not nil, please.
docker/docker_image_src.go
Outdated
| // which is not nil. | ||
| func (s *dockerImageSource) getSignaturesFromLookaside() ([][]byte, error) { | ||
| func (s *dockerImageSource) getSignaturesFromLookaside(ctx context.Context) ([][]byte, error) { | ||
| if err := s.ensureManifestIsLoaded(); err != nil { |
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.
ensureManifestIsLoaded also needs to handle ctx.
docker/docker_image_src.go
Outdated
| if err != nil { | ||
| return nil, false, err | ||
| } | ||
| if ctx != nil { |
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.
Drop this conditional please; ctx == nil is invalid.
|
@mtrmac all comments addressed |
|
@mfojtik looks like a rebase is needed. |
docker/docker_image_src.go
Outdated
| ) | ||
| for _, url := range urls { | ||
| resp, err = s.c.makeRequestToResolvedURL("GET", url, nil, nil, -1, false) | ||
| resp, err = s.c.makeRequestToResolvedURL(context.Background(), "GET", url, nil, nil, -1, false) |
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.
context.TODO(), not .Background(), everywhere in this file
| } | ||
|
|
||
| func (s *openshiftImageSource) GetSignatures() ([][]byte, error) { | ||
| func (s *openshiftImageSource) GetSignatures(ctx context.Context) ([][]byte, error) { |
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.
In the mean time we would still have unreliable API, that’s not great. I’ll take a stab at this.
(As for using the OpenShift client, that would be great (I extracting those thousand lines in openshift-copies.go was annoying and by now it’s probably pretty behind the original, and I do hate the duplication), but the two times this was attempted, it added 60? MB to the size of skopeo, which is just too much.)
00973d5 to
8305c27
Compare
|
@mtrmac updated, PTAL |
|
LGTM fwiw. |
Signed-off-by: Michal Fojtik <[email protected]>
Signed-off-by: Miloslav Trmač <[email protected]>
|
@mtrmac updated, lets wait for tests to pass |
|
@runcom guess this one is now good for shipping |
@mtrmac @runcom since we plan to use the containers/image for downloading signatures from external location, we want to wrap every HTTP request to any location with
context.Contextthat allows to set timeouts and deadlines for the request (so we won't open a request to a black hole, etc.)i don't want to sweep all containers/image code and address all cases for now (but somebody should ;-) just plumb the code we currently need for openshift/origin#15494
@smarterclayton FYI