From 0ad60d4d9e96350ce5837c577a627e41b95d2249 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 7 Feb 2019 13:02:37 +0100 Subject: [PATCH 1/2] Bump docker/distribution to 0d3efadf0154c2b8a4e7b6621fff9809655cc580 Signed-off-by: Sebastiaan van Stijn --- vendor.conf | 2 +- .../github.com/docker/distribution/README.md | 3 +- .../distribution/reference/normalize.go | 29 ++++++++++++++ .../distribution/reference/reference.go | 4 +- .../docker/distribution/vendor.conf | 38 ++++++++++++------- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/vendor.conf b/vendor.conf index 7575e238f..6f51eee1a 100644 --- a/vendor.conf +++ b/vendor.conf @@ -14,7 +14,7 @@ github.com/containernetworking/cni v0.6.0 github.com/containernetworking/plugins v0.7.0 github.com/coreos/go-systemd v14 github.com/davecgh/go-spew v1.1.0 -github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621 +github.com/docker/distribution 0d3efadf0154c2b8a4e7b6621fff9809655cc580 github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00 github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9 github.com/docker/go-metrics 4ea375f7759c82740c893fc030bc37088d2ec098 diff --git a/vendor/github.com/docker/distribution/README.md b/vendor/github.com/docker/distribution/README.md index a6e8db0fb..998878850 100644 --- a/vendor/github.com/docker/distribution/README.md +++ b/vendor/github.com/docker/distribution/README.md @@ -76,8 +76,7 @@ may be the better choice. For those who have previously deployed their own registry based on the Registry 1.0 implementation and wish to deploy a Registry 2.0 while retaining images, data migration is required. A tool to assist with migration efforts has been -created. For more information see [docker/migrator] -(https://github.com/docker/migrator). +created. For more information see [docker/migrator](https://github.com/docker/migrator). ## Contribute diff --git a/vendor/github.com/docker/distribution/reference/normalize.go b/vendor/github.com/docker/distribution/reference/normalize.go index 2d71fc5e9..b3dfb7a6d 100644 --- a/vendor/github.com/docker/distribution/reference/normalize.go +++ b/vendor/github.com/docker/distribution/reference/normalize.go @@ -56,6 +56,35 @@ func ParseNormalizedNamed(s string) (Named, error) { return named, nil } +// ParseDockerRef normalizes the image reference following the docker convention. This is added +// mainly for backward compatibility. +// The reference returned can only be either tagged or digested. For reference contains both tag +// and digest, the function returns digested reference, e.g. docker.io/library/busybox:latest@ +// sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa will be returned as +// docker.io/library/busybox@sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa. +func ParseDockerRef(ref string) (Named, error) { + named, err := ParseNormalizedNamed(ref) + if err != nil { + return nil, err + } + if _, ok := named.(NamedTagged); ok { + if canonical, ok := named.(Canonical); ok { + // The reference is both tagged and digested, only + // return digested. + newNamed, err := WithName(canonical.Name()) + if err != nil { + return nil, err + } + newCanonical, err := WithDigest(newNamed, canonical.Digest()) + if err != nil { + return nil, err + } + return newCanonical, nil + } + } + return TagNameOnly(named), nil +} + // splitDockerDomain splits a repository name to domain and remotename string. // If no valid domain is found, the default domain is used. Repository name // needs to be already validated before. diff --git a/vendor/github.com/docker/distribution/reference/reference.go b/vendor/github.com/docker/distribution/reference/reference.go index fd3510e9e..8c0c23b2f 100644 --- a/vendor/github.com/docker/distribution/reference/reference.go +++ b/vendor/github.com/docker/distribution/reference/reference.go @@ -15,7 +15,7 @@ // tag := /[\w][\w.-]{0,127}/ // // digest := digest-algorithm ":" digest-hex -// digest-algorithm := digest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ] +// digest-algorithm := digest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ]* // digest-algorithm-separator := /[+.-_]/ // digest-algorithm-component := /[A-Za-z][A-Za-z0-9]*/ // digest-hex := /[0-9a-fA-F]{32,}/ ; At least 128 bit digest value @@ -205,7 +205,7 @@ func Parse(s string) (Reference, error) { var repo repository nameMatch := anchoredNameRegexp.FindStringSubmatch(matches[1]) - if nameMatch != nil && len(nameMatch) == 3 { + if len(nameMatch) == 3 { repo.domain = nameMatch[1] repo.path = nameMatch[2] } else { diff --git a/vendor/github.com/docker/distribution/vendor.conf b/vendor/github.com/docker/distribution/vendor.conf index 443b4bcfe..12f71672f 100644 --- a/vendor/github.com/docker/distribution/vendor.conf +++ b/vendor/github.com/docker/distribution/vendor.conf @@ -1,41 +1,51 @@ -github.com/Azure/azure-sdk-for-go c6f0533defaaaa26ea4dff3c9774e36033088112 -github.com/Sirupsen/logrus d26492970760ca5d33129d2d799e34be5c4782eb -github.com/aws/aws-sdk-go c6fc52983ea2375810aa38ddb5370e9cdf611716 -github.com/bshuster-repo/logrus-logstash-hook 5f729f2fb50a301153cae84ff5c58981d51c095a +github.com/Azure/azure-sdk-for-go 4650843026a7fdec254a8d9cf893693a254edd0b +github.com/Azure/go-autorest eaa7994b2278094c904d31993d26f56324db3052 +github.com/sirupsen/logrus 3d4380f53a34dcdc95f0c1db702615992b38d9a4 +github.com/aws/aws-sdk-go f831d5a0822a1ad72420ab18c6269bca1ddaf490 +github.com/bshuster-repo/logrus-logstash-hook d2c0ecc1836d91814e15e23bb5dc309c3ef51f4a +github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 github.com/bugsnag/bugsnag-go b1d153021fcd90ca3f080db36bec96dc690fb274 github.com/bugsnag/osext 0dd3f918b21bec95ace9dc86c7e70266cfc5c702 github.com/bugsnag/panicwrap e2c28503fcd0675329da73bf48b33404db873782 -github.com/denverdino/aliyungo afedced274aa9a7fcdd47ac97018f0f8db4e5de2 -github.com/docker/goamz f0a21f5b2e12f83a505ecf79b633bb2035cf6f85 +github.com/denverdino/aliyungo 6df11717a253d9c7d4141f9af4deaa7c580cd531 +github.com/dgrijalva/jwt-go a601269ab70c205d26370c16f7c81e9017c14e04 +github.com/docker/go-metrics 399ea8c73916000c64c2c76e8da00ca82f8387ab github.com/docker/libtrust fa567046d9b14f6aa788882a950d69651d230b21 github.com/garyburd/redigo 535138d7bcd717d6531c701ef5933d98b1866257 github.com/go-ini/ini 2ba15ac2dc9cdf88c110ec2dc0ced7fa45f5678c -github.com/golang/protobuf/proto 8d92cf5fc15a4382f8964b08e1f42a75c0591aa3 -github.com/gorilla/context 14f550f51af52180c2eefed15e5fd18d63c0a64a +github.com/golang/protobuf 8d92cf5fc15a4382f8964b08e1f42a75c0591aa3 github.com/gorilla/handlers 60c7bfde3e33c201519a200a4507a158cc03a17b -github.com/gorilla/mux e444e69cbd2e2e3e0749a2f3c717cec491552bbf +github.com/gorilla/mux 599cba5e7b6137d46ddf58fb1765f5d928e69604 github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d +github.com/marstr/guid 8bd9a64bf37eb297b492a4101fb28e80ac0b290f +github.com/satori/go.uuid f58768cc1a7a7e77a3bd49e98cdd21419399b6a3 +github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c github.com/miekg/dns 271c58e0c14f552178ea321a545ff9af38930f39 github.com/mitchellh/mapstructure 482a9fd5fa83e8c4e7817413b80f3eb8feec03ef -github.com/ncw/swift b964f2ca856aac39885e258ad25aec08d5f64ee6 +github.com/ncw/swift a0320860b16212c2b59b4912bb6508cda1d7cee6 +github.com/prometheus/client_golang c332b6f63c0658a65eca15c0e5247ded801cf564 +github.com/prometheus/client_model 99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c +github.com/prometheus/common 89604d197083d4781071d3c65855d24ecfb0a563 +github.com/prometheus/procfs cb4147076ac75738c9a7d279075a253c0cc5acbd +github.com/Shopify/logrus-bugsnag 577dee27f20dd8f1a529f82210094af593be12bd github.com/spf13/cobra 312092086bed4968099259622145a0c9ae280064 github.com/spf13/pflag 5644820622454e71517561946e3d94b9f9db6842 -github.com/stevvooe/resumable 51ad44105773cafcbe91927f70ac68e1bf78f8b4 -github.com/xenolf/lego/acme a9d8cec0e6563575e5868a005359ac97911b5985 +github.com/xenolf/lego a9d8cec0e6563575e5868a005359ac97911b5985 github.com/yvasiyarov/go-metrics 57bccd1ccd43f94bb17fdd8bf3007059b802f85e github.com/yvasiyarov/gorelic a9bba5b9ab508a086f9a12b8c51fab68478e2128 github.com/yvasiyarov/newrelic_platform_go b21fdbd4370f3717f3bbd2bf41c223bc273068e6 golang.org/x/crypto c10c31b5e94b6f7a0283272dc2bb27163dcea24b golang.org/x/net 4876518f9e71663000c348837735820161a42df7 golang.org/x/oauth2 045497edb6234273d67dbc25da3f2ddbc4c4cacf -golang.org/x/time/rate a4bde12657593d5e90d0533a3e4fd95e635124cb +golang.org/x/time a4bde12657593d5e90d0533a3e4fd95e635124cb google.golang.org/api 9bf6e6e569ff057f75d9604a46c52928f17d2b54 google.golang.org/appengine 12d5545dc1cfa6047a286d5e853841b6471f4c19 google.golang.org/cloud 975617b05ea8a58727e6c1a06b6161ff4185a9f2 google.golang.org/grpc d3ddb4469d5a1b949fc7a7da7c1d6a0d1b6de994 gopkg.in/check.v1 64131543e7896d5bcc6bd5a76287eb75ea96c673 gopkg.in/square/go-jose.v1 40d457b439244b546f023d056628e5184136899b -gopkg.in/yaml.v2 bef53efd0c76e49e6de55ead051f886bea7e9420 +gopkg.in/yaml.v2 v2.2.1 rsc.io/letsencrypt e770c10b0f1a64775ae91d240407ce00d1a5bdeb https://github.com/dmcgowan/letsencrypt.git github.com/opencontainers/go-digest a6d0ee40d4207ea02364bd3b9e8e77b9159ba1eb +github.com/opencontainers/image-spec ab7389ef9f50030c9b245bc16b981c7ddf192882 From 51affb8839cac2731c6d537c151e3a83046f85a7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 7 Feb 2019 13:22:58 +0100 Subject: [PATCH 2/2] Replace util.NormalizeImageRef with reference.ParseDockerRef Using the utility caused other project to have containerd/cri as a dependency, only for this utility. The new `reference.ParseDockerRef` function does the same (it's a copy of this function). Tests were kept for now, but could be removed in future. Signed-off-by: Sebastiaan van Stijn --- pkg/containerd/importer/importer.go | 4 ++-- pkg/server/helpers.go | 3 +-- pkg/server/helpers_test.go | 4 ++-- pkg/server/image_pull.go | 5 ++--- pkg/util/image.go | 23 +++-------------------- 5 files changed, 10 insertions(+), 29 deletions(-) diff --git a/pkg/containerd/importer/importer.go b/pkg/containerd/importer/importer.go index eabce9ca6..3ac38752f 100644 --- a/pkg/containerd/importer/importer.go +++ b/pkg/containerd/importer/importer.go @@ -32,13 +32,13 @@ import ( "github.com/containerd/containerd/images" "github.com/containerd/containerd/leases" "github.com/containerd/containerd/log" + "github.com/docker/distribution/reference" "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/specs-go" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ctrdutil "github.com/containerd/cri/pkg/containerd/util" - "github.com/containerd/cri/pkg/util" ) // This code reuses the docker import code from containerd/containerd#1602. @@ -220,7 +220,7 @@ func Import(ctx context.Context, client *containerd.Client, reader io.Reader, op } for _, ref := range mfst.RepoTags { - normalized, err := util.NormalizeImageRef(ref) + normalized, err := reference.ParseDockerRef(ref) if err != nil { return refs, errors.Wrapf(err, "normalize image ref %q", ref) } diff --git a/pkg/server/helpers.go b/pkg/server/helpers.go index b44be5a2a..228a349a4 100644 --- a/pkg/server/helpers.go +++ b/pkg/server/helpers.go @@ -50,7 +50,6 @@ import ( containerstore "github.com/containerd/cri/pkg/store/container" imagestore "github.com/containerd/cri/pkg/store/image" sandboxstore "github.com/containerd/cri/pkg/store/sandbox" - "github.com/containerd/cri/pkg/util" ) const ( @@ -264,7 +263,7 @@ func (c *criService) localResolve(refOrID string) (imagestore.Image, error) { return func(ref string) string { // ref is not image id, try to resolve it locally. // TODO(random-liu): Handle this error better for debugging. - normalized, err := util.NormalizeImageRef(ref) + normalized, err := reference.ParseDockerRef(ref) if err != nil { return "" } diff --git a/pkg/server/helpers_test.go b/pkg/server/helpers_test.go index fb27803ee..5d33cd127 100644 --- a/pkg/server/helpers_test.go +++ b/pkg/server/helpers_test.go @@ -23,6 +23,7 @@ import ( "github.com/BurntSushi/toml" "github.com/containerd/containerd/runtime/linux/runctypes" runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" + "github.com/docker/distribution/reference" imagedigest "github.com/opencontainers/go-digest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -31,7 +32,6 @@ import ( criconfig "github.com/containerd/cri/pkg/config" "github.com/containerd/cri/pkg/store" imagestore "github.com/containerd/cri/pkg/store/image" - "github.com/containerd/cri/pkg/util" ) // TestGetUserFromImage tests the logic of getting image uid or user name of image user. @@ -104,7 +104,7 @@ func TestGetRepoDigestAndTag(t *testing.T) { }, } { t.Logf("TestCase %q", desc) - named, err := util.NormalizeImageRef(test.ref) + named, err := reference.ParseDockerRef(test.ref) assert.NoError(t, err) repoDigest, repoTag := getRepoDigestAndTag(named, digest, test.schema1) assert.Equal(t, test.expectedRepoDigest, repoDigest) diff --git a/pkg/server/image_pull.go b/pkg/server/image_pull.go index 56b05e8e9..0e6c4d2ae 100644 --- a/pkg/server/image_pull.go +++ b/pkg/server/image_pull.go @@ -28,13 +28,12 @@ import ( "github.com/containerd/containerd/reference" "github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes/docker" + distribution "github.com/docker/distribution/reference" imagespec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - - "github.com/containerd/cri/pkg/util" ) // For image management: @@ -81,7 +80,7 @@ import ( // PullImage pulls an image with authentication config. func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest) (*runtime.PullImageResponse, error) { imageRef := r.GetImage().GetImage() - namedRef, err := util.NormalizeImageRef(imageRef) + namedRef, err := distribution.ParseDockerRef(imageRef) if err != nil { return nil, errors.Wrapf(err, "failed to parse image reference %q", imageRef) } diff --git a/pkg/util/image.go b/pkg/util/image.go index 0f471fc42..3a9883604 100644 --- a/pkg/util/image.go +++ b/pkg/util/image.go @@ -26,25 +26,8 @@ import ( // and digest, the function returns digested reference, e.g. docker.io/library/busybox:latest@ // sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa will be returned as // docker.io/library/busybox@sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa. +// +// Deprecated: use github.com/docker/reference.ParseDockerRef() instead func NormalizeImageRef(ref string) (reference.Named, error) { - named, err := reference.ParseNormalizedNamed(ref) - if err != nil { - return nil, err - } - if _, ok := named.(reference.NamedTagged); ok { - if canonical, ok := named.(reference.Canonical); ok { - // The reference is both tagged and digested, only - // return digested. - newNamed, err := reference.WithName(canonical.Name()) - if err != nil { - return nil, err - } - newCanonical, err := reference.WithDigest(newNamed, canonical.Digest()) - if err != nil { - return nil, err - } - return newCanonical, nil - } - } - return reference.TagNameOnly(named), nil + return reference.ParseDockerRef(ref) }