-
Notifications
You must be signed in to change notification settings - Fork 944
fix: pull should return 404 when image not exists #2914
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,7 +200,7 @@ func (c *Client) PushImage(ctx context.Context, ref string, authConfig *types.Au | |
|
|
||
| pushTracker := docker.NewInMemoryTracker() | ||
|
|
||
| resolver, _, err := c.getResolver(ctx, authConfig, ref, []string{ref}, docker.ResolverOptions{ | ||
| resolver, _, err := c.ResolveImage(ctx, ref, []string{ref}, authConfig, docker.ResolverOptions{ | ||
| Tracker: pushTracker, | ||
| }) | ||
| if err != nil { | ||
|
|
@@ -251,21 +251,25 @@ func (c *Client) PushImage(ctx context.Context, ref string, authConfig *types.Au | |
| return nil | ||
| } | ||
|
|
||
| // FetchImage fetches image content from the remote repository. | ||
| func (c *Client) FetchImage(ctx context.Context, name string, refs []string, authConfig *types.AuthConfig, stream *jsonstream.JSONStream) (containerd.Image, error) { | ||
| wrapperCli, err := c.Get(ctx) | ||
| // ResolveImage attempts to resolve the image reference into a available reference and resolver. | ||
| func (c *Client) ResolveImage(ctx context.Context, nameRef string, refs []string, authConfig *types.AuthConfig, opts docker.ResolverOptions) (remotes.Resolver, string, error) { | ||
| resolver, availableRef, err := c.getResolver(ctx, authConfig, nameRef, refs, opts) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get a containerd grpc client: %v", err) | ||
| logrus.Errorf("image ref not found %s", nameRef) | ||
| return nil, "", err | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should check the status and make sure that it is 404
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when resolveImage return err, means that it can't find available ref to use. |
||
| } | ||
|
|
||
| resolver, availableRef, err := c.getResolver(ctx, authConfig, name, refs, docker.ResolverOptions{}) | ||
| return resolver, availableRef, nil | ||
| } | ||
|
|
||
| // FetchImage fetches image content from the remote repository. | ||
| func (c *Client) FetchImage(ctx context.Context, resolver remotes.Resolver, availableRef string, authConfig *types.AuthConfig, stream *jsonstream.JSONStream) (containerd.Image, error) { | ||
| wrapperCli, err := c.Get(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, fmt.Errorf("failed to get a containerd grpc client: %v", err) | ||
| } | ||
|
|
||
| logrus.Infof("pulling image name %v reference %v", name, availableRef) | ||
|
|
||
| ongoing := newJobs(name) | ||
| ongoing := newJobs(availableRef) | ||
|
|
||
| options := []containerd.RemoteOpt{ | ||
| containerd.WithSchema1Conversion, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ package ctrd | |
| import ( | ||
| "context" | ||
| "crypto/tls" | ||
| "fmt" | ||
| "net" | ||
| "net/http" | ||
| "net/url" | ||
|
|
@@ -166,7 +165,8 @@ func (c *Client) getResolver(ctx context.Context, authConfig *types.AuthConfig, | |
| } | ||
|
|
||
| if availableRef == "" { | ||
| return nil, "", fmt.Errorf("there is no available image reference after trying %+q", refs) | ||
| logrus.Warnf("there is no available image reference after trying %+q", refs) | ||
| return nil, "", errtypes.ErrNotfound | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I change to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sense |
||
| } | ||
|
|
||
| refToName := map[string]string{ | ||
|
|
||
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.
well. if we write something into response, the http code will be 200 which can never be changed.
so we use jsonstream to return error. the client needs to parse the json stream to get 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.
when you pull the No. 5 layer and get something wrong like connection refuse, your change is not helpful. it always be 200, not 500