Skip to content

Commit

Permalink
Add warning when mirroring SchemaVersion:1 images that digests are no…
Browse files Browse the repository at this point in the history
…t preserved.

Also, update TODOs with functions handling schema conversions to drop support for Schema v1 in future release.
  • Loading branch information
sallyom committed Jul 14, 2020
1 parent 9060d2f commit 4fc6c24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/cli/image/manifest/manifest.go
Expand Up @@ -428,7 +428,7 @@ func ManifestsFromList(ctx context.Context, srcDigest digest.Digest, srcManifest
}
}

// TDOO: remove when quay.io switches to v2 schema
// TODO: Remove support for v2 schema in 4.9
func PutManifestInCompatibleSchema(
ctx context.Context,
srcManifest distribution.Manifest,
Expand Down Expand Up @@ -538,7 +538,7 @@ func convertToSchema2(ctx context.Context, blobs distribution.BlobService, srcMa
return b.Build(ctx)
}

// TDOO: remove when quay.io switches to v2 schema
// TODO: Remove support for v2 schema in 4.9
func convertToSchema1(ctx context.Context, blobs distribution.BlobService, configJSON []byte, schema2Manifest *schema2.DeserializedManifest, ref reference.Named) (distribution.Manifest, error) {
if configJSON == nil {
targetDescriptor := schema2Manifest.Target()
Expand Down Expand Up @@ -573,7 +573,7 @@ var (
privateKey libtrust.PrivateKey
)

// TDOO: remove when quay.io switches to v2 schema
// TODO: Remove support for v2 schema in 4.9
func loadPrivateKey() (libtrust.PrivateKey, error) {
privateKeyLock.Lock()
defer privateKeyLock.Unlock()
Expand Down
12 changes: 10 additions & 2 deletions pkg/cli/image/mirror/mirror.go
Expand Up @@ -339,7 +339,7 @@ func (o *MirrorImageOptions) Run() error {
srcDigest := digest
tags := op.digestsToTags[srcDigest].List()
w.Parallel(func() {
if errs := copyManifestToTags(ctx, ref, srcDigest, tags, op, o.Out); len(errs) > 0 {
if errs := copyManifestToTags(ctx, ref, srcDigest, tags, op, o.Out, o.ErrOut); len(errs) > 0 {
phase.ExecutionFailure(errs...)
}
})
Expand All @@ -355,7 +355,7 @@ func (o *MirrorImageOptions) Run() error {

srcDigest := godigest.Digest(digest)
w.Parallel(func() {
if err := copyManifest(ctx, ref, srcDigest, op, o.Out); err != nil {
if err := copyManifest(ctx, ref, srcDigest, op, o.Out, o.ErrOut); err != nil {
phase.ExecutionFailure(err)
}
})
Expand Down Expand Up @@ -720,6 +720,7 @@ func copyManifestToTags(
tags []string,
plan *repositoryManifestPlan,
out io.Writer,
errOut io.Writer,
) []error {
var errs []error
srcManifest, ok := plan.parent.parent.parent.GetManifest(srcDigest)
Expand All @@ -735,6 +736,9 @@ func copyManifestToTags(
for _, desc := range srcManifest.References() {
plan.parent.parent.AssociateBlob(desc.Digest, plan.parent.name)
}
if srcDigest != toDigest {
fmt.Fprintf(errOut, "warning: Digests are not preserved with schema version 1 images. Support for schema version 1 images will be removed in a future release.\n")
}
plan.parent.parent.SavedManifest(srcDigest, toDigest)
fmt.Fprintf(out, "%s %s:%s\n", toDigest, plan.toRef, tag)
}
Expand All @@ -747,6 +751,7 @@ func copyManifest(
srcDigest godigest.Digest,
plan *repositoryManifestPlan,
out io.Writer,
errOut io.Writer,
) error {
srcManifest, ok := plan.parent.parent.parent.GetManifest(srcDigest)
if !ok {
Expand All @@ -759,6 +764,9 @@ func copyManifest(
for _, desc := range srcManifest.References() {
plan.parent.parent.AssociateBlob(desc.Digest, plan.parent.name)
}
if srcDigest != toDigest {
fmt.Fprintf(errOut, "warning: Digests are not preserved with schema version 1 images. Support for schema version 1 images will be removed in a future release.\n")
}
plan.parent.parent.SavedManifest(srcDigest, toDigest)
fmt.Fprintf(out, "%s %s\n", toDigest, plan.toRef)
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/image/mirror/plan.go
Expand Up @@ -341,7 +341,7 @@ func (p *registryPlan) SavedManifest(srcDigest, dstDigest godigest.Digest) {
}
p.lock.Lock()
defer p.lock.Unlock()
klog.V(4).Infof("Associated digest %s with converted digest %s", srcDigest, dstDigest)
klog.V(2).Infof("Associated digest: %s, Converted digest: %s", srcDigest, dstDigest)
p.manifestConversions[srcDigest] = dstDigest
}

Expand Down

0 comments on commit 4fc6c24

Please sign in to comment.