From 261dd69e5a8f0a2b96c624ead549ec9cf2b7ef75 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 31 Jul 2024 13:45:01 +0200 Subject: [PATCH] switch to github.com/distribution/reference module containerd 1.7.19 and up alias the reference/docker package to the new module, and deprecate the package. Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 2 ++ cmd/optimizer-nri-plugin/main.go | 8 ++++---- pkg/auth/image_proxy.go | 2 +- pkg/auth/keychain.go | 6 +++--- pkg/remote/remotes/docker/fetcher_fuzz.go | 4 ++-- pkg/resolve/resolver.go | 8 ++++---- pkg/stargz/resolver.go | 14 ++++++-------- pkg/utils/registry/registry.go | 8 ++++---- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 86efc38d21..79f1223afb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,6 +21,8 @@ linters-settings: desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead. - pkg: "github.com/containerd/containerd/platforms" desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead. + - pkg: "github.com/containerd/containerd/reference/docker" + desc: The containerd platforms package was migrated to a separate module. Use github.com/distribution/reference instead. # govet: # check-shadowing: true # enable: diff --git a/cmd/optimizer-nri-plugin/main.go b/cmd/optimizer-nri-plugin/main.go index b3e6646da9..c5da8d0577 100644 --- a/cmd/optimizer-nri-plugin/main.go +++ b/cmd/optimizer-nri-plugin/main.go @@ -17,10 +17,10 @@ import ( "time" "github.com/containerd/log" + distribution "github.com/distribution/reference" "github.com/pkg/errors" "github.com/urfave/cli/v2" - "github.com/containerd/containerd/reference/docker" "github.com/containerd/nri/pkg/api" "github.com/containerd/nri/pkg/stub" "github.com/containerd/nydus-snapshotter/pkg/errdefs" @@ -201,12 +201,12 @@ func (p *plugin) StopContainer(_ context.Context, _ *api.PodSandbox, container * } func GetImageName(annotations map[string]string) (string, string, error) { - named, err := docker.ParseDockerRef(annotations[imageNameLabel]) + named, err := distribution.ParseDockerRef(annotations[imageNameLabel]) if err != nil { return "", "", err } - nameTagged := named.(docker.NamedTagged) - repo := docker.Path(nameTagged) + nameTagged := named.(distribution.NamedTagged) + repo := distribution.Path(nameTagged) dir := filepath.Dir(repo) image := filepath.Base(repo) diff --git a/pkg/auth/image_proxy.go b/pkg/auth/image_proxy.go index eac12b06b1..bcf227d08f 100644 --- a/pkg/auth/image_proxy.go +++ b/pkg/auth/image_proxy.go @@ -14,12 +14,12 @@ import ( "github.com/containerd/containerd/defaults" "github.com/containerd/containerd/pkg/dialer" "github.com/containerd/containerd/reference" - distribution "github.com/containerd/containerd/reference/docker" runtime_alpha "github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2" "github.com/containerd/log" "github.com/containerd/stargz-snapshotter/service/keychain/cri" "github.com/containerd/stargz-snapshotter/service/keychain/crialpha" "github.com/containerd/stargz-snapshotter/service/resolver" + distribution "github.com/distribution/reference" "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/backoff" diff --git a/pkg/auth/keychain.go b/pkg/auth/keychain.go index 5aa1ec3e39..bcbec057dd 100644 --- a/pkg/auth/keychain.go +++ b/pkg/auth/keychain.go @@ -13,8 +13,8 @@ import ( "github.com/pkg/errors" - "github.com/containerd/containerd/reference/docker" "github.com/containerd/nydus-snapshotter/pkg/label" + distribution "github.com/distribution/reference" "github.com/google/go-containerregistry/pkg/authn" ) @@ -106,12 +106,12 @@ func GetRegistryKeyChain(host, ref string, labels map[string]string) *PassKeyCha } func GetKeyChainByRef(ref string, labels map[string]string) (*PassKeyChain, error) { - named, err := docker.ParseDockerRef(ref) + named, err := distribution.ParseDockerRef(ref) if err != nil { return nil, errors.Wrapf(err, "parse ref %s", ref) } - host := docker.Domain(named) + host := distribution.Domain(named) keychain := GetRegistryKeyChain(host, ref, labels) return keychain, nil diff --git a/pkg/remote/remotes/docker/fetcher_fuzz.go b/pkg/remote/remotes/docker/fetcher_fuzz.go index ee32614493..6362ebc9d2 100644 --- a/pkg/remote/remotes/docker/fetcher_fuzz.go +++ b/pkg/remote/remotes/docker/fetcher_fuzz.go @@ -26,7 +26,7 @@ import ( "net/http/httptest" "net/url" - refDocker "github.com/containerd/containerd/reference/docker" + distribution "github.com/distribution/reference" ) func FuzzFetcher(data []byte) int { @@ -76,6 +76,6 @@ func FuzzFetcher(data []byte) int { } func FuzzParseDockerRef(data []byte) int { - _, _ = refDocker.ParseDockerRef(string(data)) + _, _ = distribution.ParseDockerRef(string(data)) return 1 } diff --git a/pkg/resolve/resolver.go b/pkg/resolve/resolver.go index 4ebb49cfb8..50ba6217a3 100644 --- a/pkg/resolve/resolver.go +++ b/pkg/resolve/resolver.go @@ -12,9 +12,9 @@ import ( "io" "net/http" - "github.com/containerd/containerd/reference/docker" "github.com/containerd/nydus-snapshotter/pkg/auth" "github.com/containerd/nydus-snapshotter/pkg/utils/transport" + distribution "github.com/distribution/reference" "github.com/google/go-containerregistry/pkg/name" retryablehttp "github.com/hashicorp/go-retryablehttp" "github.com/pkg/errors" @@ -32,12 +32,12 @@ func NewResolver() *Resolver { } func (r *Resolver) Resolve(ref, digest string, labels map[string]string) (io.ReadCloser, error) { - named, err := docker.ParseDockerRef(ref) + named, err := distribution.ParseDockerRef(ref) if err != nil { return nil, errors.Wrapf(err, "failed parse docker ref %s", ref) } - host := docker.Domain(named) - sref := fmt.Sprintf("%s/%s", host, docker.Path(named)) + host := distribution.Domain(named) + sref := fmt.Sprintf("%s/%s", host, distribution.Path(named)) nref, err := name.ParseReference(sref) if err != nil { return nil, errors.Wrapf(err, "failed to parse ref %q (%q)", sref, digest) diff --git a/pkg/stargz/resolver.go b/pkg/stargz/resolver.go index 2182aee057..4199a391cb 100644 --- a/pkg/stargz/resolver.go +++ b/pkg/stargz/resolver.go @@ -18,15 +18,13 @@ import ( "strings" "time" - "github.com/pkg/errors" - - "github.com/containerd/containerd/reference/docker" "github.com/containerd/log" "github.com/containerd/nydus-snapshotter/pkg/utils/transport" + "github.com/containerd/stargz-snapshotter/estargz" + distribution "github.com/distribution/reference" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" - - "github.com/containerd/stargz-snapshotter/estargz" + "github.com/pkg/errors" ) const httpTimeout = 15 * time.Second @@ -152,12 +150,12 @@ func parseFooter(p []byte) (tocOffset int64, ok bool) { } func (r *Resolver) resolve(ref, digest string, keychain authn.Keychain) (*io.SectionReader, error) { - named, err := docker.ParseDockerRef(ref) + named, err := distribution.ParseDockerRef(ref) if err != nil { return nil, err } - host := docker.Domain(named) - sref := fmt.Sprintf("%s/%s", host, docker.Path(named)) + host := distribution.Domain(named) + sref := fmt.Sprintf("%s/%s", host, distribution.Path(named)) nref, err := name.ParseReference(sref) if err != nil { return nil, errors.Wrapf(err, "failed to parse ref %q (%q)", sref, digest) diff --git a/pkg/utils/registry/registry.go b/pkg/utils/registry/registry.go index 3ca7445a2a..ab7403c76d 100644 --- a/pkg/utils/registry/registry.go +++ b/pkg/utils/registry/registry.go @@ -15,7 +15,7 @@ import ( "time" snpkg "github.com/containerd/containerd/pkg/snapshotters" - "github.com/containerd/containerd/reference/docker" + distribution "github.com/distribution/reference" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote/transport" @@ -37,12 +37,12 @@ func ConvertToVPCHost(registryHost string) string { } func ParseImage(imageID string) (Image, error) { - named, err := docker.ParseDockerRef(imageID) + named, err := distribution.ParseDockerRef(imageID) if err != nil { return Image{}, err } - host := docker.Domain(named) - repo := docker.Path(named) + host := distribution.Domain(named) + repo := distribution.Path(named) return Image{ Host: host, Repo: repo,