-
Notifications
You must be signed in to change notification settings - Fork 950
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
feature: support push image in daemon side #2641
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2641 +/- ##
==========================================
- Coverage 69.46% 69.12% -0.35%
==========================================
Files 283 285 +2
Lines 18827 18957 +130
==========================================
+ Hits 13079 13104 +25
- Misses 4286 4379 +93
- Partials 1462 1474 +12
|
apis/server/image_bridge.go
Outdated
// no need return error here | ||
if err := s.ImageMgr.PushImage(ctx, name, tag, &authConfig, newWriteFlusher(rw)); err != nil { | ||
logrus.Errorf("failed to push image %s with tag %s: %v", name, tag, err) | ||
return 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.
return err
or return 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 think like pull
and exec
, return nil 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.
could we check image before push? PushImage
will return 404 as error. And the user doesn't know error because we don't return it.
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.
@fuweid , have do the check, if containerd can get image, we will push
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 re-check the code here, we use jsonstream to pass infos to client, but stream only start after push image, that means no other error can not be send to client, so I think should be return error
here
client/image_push_test.go
Outdated
} | ||
} | ||
|
||
func TestImagePushWrongError(t *testing.T) { |
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 this case is duplicated with TestImagePushServerError
. It doesn't help. Could we consider to remove this? WDYT?
apis/server/image_bridge.go
Outdated
// no need return error here | ||
if err := s.ImageMgr.PushImage(ctx, name, tag, &authConfig, newWriteFlusher(rw)); err != nil { | ||
logrus.Errorf("failed to push image %s with tag %s: %v", name, tag, err) | ||
return 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.
could we check image before push? PushImage
will return 404 as error. And the user doesn't know error because we don't return it.
daemon/mgr/image.go
Outdated
|
||
stream := jsonstream.New(out, nil) | ||
err = mgr.client.PushImage(ctx, ref.String(), authConfig, stream) | ||
stream.Wait() |
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 think we should wait here. If the image is not found, the stream.Wait()
will be dead end. WDYT?
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 it ok here, since in stream.New(), it have do the add, but move it to ctrd/image.go
make more sense.
// New creates a 'JSONStream' instance and use a goroutine to recv/send data.
func New(out io.Writer, f Formater) *JSONStream {
format := f
if format == nil {
format = newDefaultFormat()
}
stream := &JSONStream{
w: out,
cache: make(chan interface{}, 16),
f: format,
}
stream.wg.Add(1)
ctrd/utils.go
Outdated
@@ -16,6 +16,9 @@ import ( | |||
"github.com/pkg/errors" | |||
) | |||
|
|||
// pushTracker records push progress detail | |||
var pushTracker = docker.NewInMemoryTracker() |
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 am not sure that it is good to use global variables. There is one case:
Someone has pushed image A with desc A1. If other one tries to push image B which also contains desc A1, the status might be done
. But it might be under committing.
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.
It remind me, looks like a parallel caused bug, we can also do a fix for containerd
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.
please remove this line since you uses temp var.
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.
containerd ctr is command , not a server implement. it doesn't have the issue.
@Ace-Tang please rebase it with current master to make the CI happy. |
ctrd/image.go
Outdated
@@ -176,6 +178,63 @@ func (c *Client) importImage(ctx context.Context, importer ctrdmetaimages.Import | |||
return imgs, nil | |||
} | |||
|
|||
// PushImage pushs image to registry |
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.
pushes?
ctrd/image.go
Outdated
|
||
defer stream.Close() | ||
if err != nil { | ||
// Send Error information to client through stream |
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.
s/Error/error?
ctrd/image.go
Outdated
@@ -13,6 +14,7 @@ import ( | |||
|
|||
"github.com/containerd/containerd" | |||
"github.com/containerd/containerd/errdefs" | |||
"github.com/containerd/containerd/images" |
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 this line duplicate with next line?
daemon/mgr/image.go
Outdated
@@ -43,6 +43,9 @@ type ImageMgr interface { | |||
// PullImage pulls images from specified registry. | |||
PullImage(ctx context.Context, ref string, authConfig *types.AuthConfig, out io.Writer) error | |||
|
|||
// PushImage push image to specified registry. |
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.
pushes
ctrd/interface.go
Outdated
@@ -89,6 +89,8 @@ type ImageAPIClient interface { | |||
SaveImage(ctx context.Context, exporter ctrdmetaimages.Exporter, ref string) (io.ReadCloser, error) | |||
// Commit commits an image from a container. | |||
Commit(ctx context.Context, config *CommitConfig) (digest.Digest, error) | |||
// PushImage pushs a image to registry |
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.
pushes
daemon/mgr/image.go
Outdated
@@ -174,6 +177,25 @@ func (mgr *ImageManager) PullImage(ctx context.Context, ref string, authConfig * | |||
return mgr.StoreImageReference(ctx, img) | |||
} | |||
|
|||
// PushImage push image to specified registry. |
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.
pushes
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.
please repush to re-trigger travis-ci. thanks!
ctrd/utils.go
Outdated
@@ -16,6 +16,9 @@ import ( | |||
"github.com/pkg/errors" | |||
) | |||
|
|||
// pushTracker records push progress detail | |||
var pushTracker = docker.NewInMemoryTracker() |
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.
please remove this line since you uses temp var.
test/api_image_push_test.go
Outdated
SkipIfFalse(c, environment.IsLinux) | ||
} | ||
|
||
// TestImageCreateOk tests creating an image is OK. |
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.
wrong 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.
Removed
test/api_image_push_test.go
Outdated
name := "not_exist_image" | ||
resp, err := request.Post("/images/" + name + "/push") | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 500) |
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 using 500 instead of 404 for not-exist-image?
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, should be 404
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.
404 means no such route
I am afraid that 404 mean image not found rather than endpoint route not found.
ctrd/utils.go
Outdated
@@ -16,6 +16,9 @@ import ( | |||
"github.com/pkg/errors" | |||
) | |||
|
|||
// pushTracker records push progress detail | |||
var pushTracker = docker.NewInMemoryTracker() |
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.
containerd ctr is command , not a server implement. it doesn't have the issue.
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.
Please add this HTTP endpoint in swagger.yml first to define this API explicitly. Thanks. @Ace-Tang
pkg/jsonstream/image_push.go
Outdated
) | ||
|
||
// Pushjobs defines a job in upload progress | ||
type Pushjobs struct { |
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 the camel way of PushJobs
instead of Pushjobs
?
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.
Updated
apis/swagger.yml
Outdated
summary: "push an image on the registry" | ||
description: "push an image on the registry" | ||
consumes: | ||
- "application/json" |
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 maybe we need some discussion. I think there the in HTTP request, we are not consuming application/json
, and actually it is application/octet-stream
that consumes type of file, like that described in moby: https://github.com/moby/moby/blob/master/api/swagger.yaml#L6735 .
And please add
- name: "X-Registry-Auth"
in: "header"
description: "A base64-encoded auth configuration. [See the authentication section for details.](#section/Authentication)"
type: "string"
required: 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.
Updated
apis/server/image_bridge.go
Outdated
} | ||
|
||
// Error information has be sent to client, so no need call resp.Write | ||
// no need return error 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.
wrong comment 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.
Updated
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.
Basicly, LGTM
implement push command in daemon side, since containerd v1.0.3 version push get some problem when push image with index.json which have multiple platforms. But it works good with only one platform, this feature is our need. fixes: #2099 Signed-off-by: Ace-Tang <aceapril@126.com>
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
implement push command in daemon side, since containerd v1.0.3
version push get some problem when push image with index.json which
have multiple platforms. But it works good with only one platform,
this feature is our need.
fixes: #2099
Signed-off-by: Ace-Tang aceapril@126.com
Ⅰ. Describe what this PR did
Ⅱ. Does this pull request fix one issue?
fixes: #2099
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
not easy to add ci test, since it need a registry
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews