Skip to content
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

Merged
merged 1 commit into from
Jan 17, 2019
Merged

feature: support push image in daemon side #2641

merged 1 commit into from
Jan 17, 2019

Conversation

Ace-Tang
Copy link
Contributor

@Ace-Tang Ace-Tang commented Jan 2, 2019

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

@codecov
Copy link

codecov bot commented Jan 2, 2019

Codecov Report

Merging #2641 into master will decrease coverage by 0.34%.
The diff coverage is 26.95%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#criv1alpha1test 31.16% <6.38%> (-0.37%) ⬇️
#criv1alpha2test 35.46% <6.38%> (-0.1%) ⬇️
#integrationtest 41.96% <19.14%> (-0.22%) ⬇️
#nodee2etest 32.04% <6.38%> (-0.31%) ⬇️
#unittest 26.96% <12.5%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pkg/jsonstream/image_progress.go 0% <0%> (ø) ⬆️
pkg/jsonstream/image_push.go 0% <0%> (ø)
apis/server/router.go 91.35% <100%> (+0.05%) ⬆️
ctrd/utils.go 100% <100%> (ø) ⬆️
ctrd/image.go 69.26% <15.38%> (-9.74%) ⬇️
daemon/mgr/image.go 59.45% <55.55%> (-0.1%) ⬇️
client/image_push.go 57.89% <57.89%> (ø)
apis/server/image_bridge.go 74.19% <61.53%> (-1.49%) ⬇️
cri/ocicni/cni_manager.go 58.82% <0%> (-11.77%) ⬇️
apis/server/utils.go 71.15% <0%> (-3.85%) ⬇️
... and 7 more

// 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
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

}
}

func TestImagePushWrongError(t *testing.T) {
Copy link
Contributor

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?

// 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
Copy link
Contributor

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.


stream := jsonstream.New(out, nil)
err = mgr.client.PushImage(ctx, ref.String(), authConfig, stream)
stream.Wait()
Copy link
Contributor

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?

Copy link
Contributor Author

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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.

@fuweid
Copy link
Contributor

fuweid commented Jan 6, 2019

@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
Copy link
Contributor

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
Copy link
Contributor

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"
Copy link
Contributor

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?

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushes

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushes

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushes

@fuweid fuweid added this to the v1.2.0 milestone Jan 8, 2019
@Ace-Tang
Copy link
Contributor Author

Ace-Tang commented Jan 8, 2019

updated, @fuweid @ZYecho

Copy link
Contributor

@fuweid fuweid left a 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()
Copy link
Contributor

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.

SkipIfFalse(c, environment.IsLinux)
}

// TestImageCreateOk tests creating an image is OK.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

name := "not_exist_image"
resp, err := request.Post("/images/" + name + "/push")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
Copy link
Contributor

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?

Copy link
Contributor Author

@Ace-Tang Ace-Tang Jan 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, should be 404

Copy link
Collaborator

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()
Copy link
Contributor

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.

Copy link
Collaborator

@allencloud allencloud left a 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

)

// Pushjobs defines a job in upload progress
type Pushjobs struct {
Copy link
Collaborator

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?

Copy link
Contributor Author

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"
Copy link
Collaborator

@allencloud allencloud Jan 15, 2019

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

}

// Error information has be sent to client, so no need call resp.Write
// no need return error here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

ctrd/image.go Show resolved Hide resolved
Copy link
Contributor

@fuweid fuweid left a 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>
Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@allencloud allencloud merged commit ff8b8fb into AliyunContainerService:master Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] build pouch push functionality (only cli side not finished now)
5 participants