Procházet zdrojové kódy

daemon/c8d: use new containerd LabelDistributionSource constant

Introduced in https://github.com/containerd/containerd/commit/dd3eedf3c35c1213292da7c6ef5e033d2a5b5d4d

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Bjorn Neergaard před 2 roky
rodič
revize
8cd5f04ea3
2 změnil soubory, kde provedl 6 přidání a 8 odebrání
  1. 4 7
      daemon/containerd/image_push.go
  2. 2 1
      daemon/containerd/store.go

+ 4 - 7
daemon/containerd/image_push.go

@@ -13,6 +13,7 @@ import (
 	cerrdefs "github.com/containerd/containerd/errdefs"
 	"github.com/containerd/containerd/images"
 	containerdimages "github.com/containerd/containerd/images"
+	containerdlabels "github.com/containerd/containerd/labels"
 	"github.com/containerd/containerd/log"
 	"github.com/containerd/containerd/platforms"
 	"github.com/containerd/containerd/remotes"
@@ -246,23 +247,19 @@ func getDigestSources(ctx context.Context, store content.Manager, digest digest.
 
 	sources := extractDistributionSources(info.Labels)
 	if sources == nil {
-		return nil, errdefs.NotFound(fmt.Errorf("label %q is not attached to %s", labelDistributionSource, digest.String()))
+		return nil, errdefs.NotFound(fmt.Errorf("label %q is not attached to %s", containerdlabels.LabelDistributionSource, digest.String()))
 	}
 
 	return sources, nil
 }
 
-// TODO(vvoland): Remove and use containerd const in containerd 1.7+
-// https://github.com/containerd/containerd/pull/8224
-const labelDistributionSource = "containerd.io/distribution.source."
-
 func extractDistributionSources(labels map[string]string) []distributionSource {
 	var sources []distributionSource
 
 	// Check if this blob has a distributionSource label
 	// if yes, read it as source
 	for k, v := range labels {
-		if reg := strings.TrimPrefix(k, labelDistributionSource); reg != k {
+		if reg := strings.TrimPrefix(k, containerdlabels.LabelDistributionSource); reg != k {
 			for _, repo := range strings.Split(v, ",") {
 				ref, err := reference.ParseNamed(reg + "/" + repo)
 				if err != nil {
@@ -287,7 +284,7 @@ type distributionSource struct {
 func (source distributionSource) ToAnnotation() (string, string) {
 	domain := reference.Domain(source.registryRef)
 	v := reference.Path(source.registryRef)
-	return labelDistributionSource + domain, v
+	return containerdlabels.LabelDistributionSource + domain, v
 }
 
 func (source distributionSource) GetReference(dgst digest.Digest) (reference.Named, error) {

+ 2 - 1
daemon/containerd/store.go

@@ -5,6 +5,7 @@ import (
 
 	"github.com/containerd/containerd/content"
 	cerrdefs "github.com/containerd/containerd/errdefs"
+	containerdlabels "github.com/containerd/containerd/labels"
 	"github.com/distribution/reference"
 	"github.com/opencontainers/go-digest"
 	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -42,7 +43,7 @@ func (p fakeStoreWithSources) Info(ctx context.Context, dgst digest.Digest) (con
 			return info, err
 		}
 
-		key := labelDistributionSource + reference.Domain(source.registryRef)
+		key := containerdlabels.LabelDistributionSource + reference.Domain(source.registryRef)
 		value := reference.Path(source.registryRef)
 		return content.Info{
 			Digest: dgst,