Skip to content

Commit

Permalink
switch to github.com/distribution/reference module
Browse files Browse the repository at this point in the history
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 <github@gone.nl>
  • Loading branch information
thaJeztah committed Aug 1, 2024
1 parent 5447c5d commit 261dd69
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions cmd/optimizer-nri-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/image_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pkg/auth/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/remote/remotes/docker/fetcher_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -76,6 +76,6 @@ func FuzzFetcher(data []byte) int {
}

func FuzzParseDockerRef(data []byte) int {
_, _ = refDocker.ParseDockerRef(string(data))
_, _ = distribution.ParseDockerRef(string(data))
return 1
}
8 changes: 4 additions & 4 deletions pkg/resolve/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions pkg/stargz/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down

0 comments on commit 261dd69

Please sign in to comment.