Browse Source

Merge pull request #45243 from thaJeztah/c8d_push_nits

c8d: push: addressing some nits
Sebastiaan van Stijn 2 years ago
parent
commit
126e212fb0
2 changed files with 14 additions and 13 deletions
  1. 8 9
      daemon/containerd/image_push.go
  2. 6 4
      daemon/containerd/progress.go

+ 8 - 9
daemon/containerd/image_push.go

@@ -56,10 +56,10 @@ func (i *ImageService) PushImage(ctx context.Context, targetRef reference.Named,
 	store := i.client.ContentStore()
 	store := i.client.ContentStore()
 
 
 	resolver, tracker := i.newResolverFromAuthConfig(authConfig)
 	resolver, tracker := i.newResolverFromAuthConfig(authConfig)
-	pushProgress := pushProgress{Tracker: tracker}
+	progress := pushProgress{Tracker: tracker}
 	jobs := newJobs()
 	jobs := newJobs()
 	finishProgress := jobs.showProgress(ctx, out, combinedProgress([]progressUpdater{
 	finishProgress := jobs.showProgress(ctx, out, combinedProgress([]progressUpdater{
-		&pushProgress,
+		&progress,
 		pullProgress{ShowExists: false, Store: store},
 		pullProgress{ShowExists: false, Store: store},
 	}))
 	}))
 	defer finishProgress()
 	defer finishProgress()
@@ -71,7 +71,7 @@ func (i *ImageService) PushImage(ctx context.Context, targetRef reference.Named,
 		return err
 		return err
 	}
 	}
 	for dgst := range mountableBlobs {
 	for dgst := range mountableBlobs {
-		pushProgress.addMountable(dgst)
+		progress.addMountable(dgst)
 	}
 	}
 
 
 	// Create a store which fakes the local existence of possibly mountable blobs.
 	// Create a store which fakes the local existence of possibly mountable blobs.
@@ -201,9 +201,8 @@ func extractDistributionSources(labels map[string]string) []distributionSource {
 	// Check if this blob has a distributionSource label
 	// Check if this blob has a distributionSource label
 	// if yes, read it as source
 	// if yes, read it as source
 	for k, v := range labels {
 	for k, v := range labels {
-		registry := strings.TrimPrefix(k, labelDistributionSource)
-		if registry != k {
-			ref, err := reference.ParseNamed(registry + "/" + v)
+		if reg := strings.TrimPrefix(k, labelDistributionSource); reg != k {
+			ref, err := reference.ParseNamed(reg + "/" + v)
 			if err != nil {
 			if err != nil {
 				continue
 				continue
 			}
 			}
@@ -242,15 +241,15 @@ func canBeMounted(mediaType string, targetRef reference.Named, isInsecureFunc fu
 		return false
 		return false
 	}
 	}
 
 
-	registry := reference.Domain(targetRef)
+	reg := reference.Domain(targetRef)
 
 
 	// Cross-repo mount doesn't seem to work with insecure registries.
 	// Cross-repo mount doesn't seem to work with insecure registries.
-	isInsecure := isInsecureFunc(registry)
+	isInsecure := isInsecureFunc(reg)
 	if isInsecure {
 	if isInsecure {
 		return false
 		return false
 	}
 	}
 
 
 	// If the source registry is the same as the one we are pushing to
 	// If the source registry is the same as the one we are pushing to
 	// then the cross-repo mount will work.
 	// then the cross-repo mount will work.
-	return registry == reference.Domain(source.registryRef)
+	return reg == reference.Domain(source.registryRef)
 }
 }

+ 6 - 4
daemon/containerd/progress.go

@@ -71,14 +71,16 @@ func (j *jobs) showProgress(ctx context.Context, out progress.Output, updater pr
 }
 }
 
 
 // Add adds a descriptor to be tracked
 // Add adds a descriptor to be tracked
-func (j *jobs) Add(desc ocispec.Descriptor) {
+func (j *jobs) Add(desc ...ocispec.Descriptor) {
 	j.mu.Lock()
 	j.mu.Lock()
 	defer j.mu.Unlock()
 	defer j.mu.Unlock()
 
 
-	if _, ok := j.descs[desc.Digest]; ok {
-		return
+	for _, d := range desc {
+		if _, ok := j.descs[d.Digest]; ok {
+			continue
+		}
+		j.descs[d.Digest] = d
 	}
 	}
-	j.descs[desc.Digest] = desc
 }
 }
 
 
 // Remove removes a descriptor
 // Remove removes a descriptor