Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.6] Bug 1942818: when mirroring to a file destination, mount images under the index location #892

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/cli/admin/catalog/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package catalog
import (
"bytes"
"fmt"
"github.com/openshift/oc/pkg/cli/admin/catalog/internal"
"io"
"io/ioutil"
"os"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/spf13/cobra"

operatorv1alpha1 "github.com/openshift/api/operator/v1alpha1"
"github.com/openshift/oc/pkg/cli/admin/catalog/internal"
imgextract "github.com/openshift/oc/pkg/cli/image/extract"
"github.com/openshift/oc/pkg/cli/image/imagesource"
"github.com/openshift/oc/pkg/cli/image/info"
Expand Down Expand Up @@ -163,7 +163,7 @@ func (o *MirrorCatalogOptions) Complete(cmd *cobra.Command, args []string) error
return err
}

srcRef, err := imagesource.ParseReference(src)
srcRef, err := internal.ParseTargetReference(src)
if err != nil {
return err
}
Expand Down
32 changes: 22 additions & 10 deletions pkg/cli/admin/catalog/mirrorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/alicebob/sqlittle"
"k8s.io/apimachinery/pkg/util/errors"

"github.com/openshift/oc/pkg/cli/admin/catalog/internal"
"github.com/openshift/oc/pkg/cli/image/imagesource"
)

Expand Down Expand Up @@ -129,11 +130,21 @@ func imagesFromDb(file string) (map[string]struct{}, error) {
}

func mappingForImages(images map[string]struct{}, src, dest imagesource.TypedImageReference, maxComponents int) (mapping map[imagesource.TypedImageReference]imagesource.TypedImageReference, errs []error) {
// don't do any name mangling when not mirroring to a real registry
// this allows us to assume the names are preserved when doing multi-hop mirrors that use a file or s3 as an
// intermediate step
if dest.Type != imagesource.DestinationRegistry {
// don't do any name mangling when not mirroring to a real registry
// this allows us to assume the names are preserved when doing multi-hop mirrors that use a file or s3 as an
// intermediate step
maxComponents = 0

// if mirroring a source (like quay.io/my/index:1) to a file location like file://local/store
// we will remount all of the content in the file store under the catalog name
// i.e. file://local/store/my/index
var err error
dest, err = mount(src, dest, 0)
if err != nil {
errs = []error{err}
return
}
}

mapping = map[imagesource.TypedImageReference]imagesource.TypedImageReference{}
Expand All @@ -142,7 +153,7 @@ func mappingForImages(images map[string]struct{}, src, dest imagesource.TypedIma
continue
}

parsed, err := imagesource.ParseReference(img)
parsed, err := internal.ParseTargetReference(img)
if err != nil {
errs = append(errs, fmt.Errorf("couldn't parse image for mirroring (%s), skipping mirror: %v", img, err))
continue
Expand All @@ -154,6 +165,13 @@ func mappingForImages(images map[string]struct{}, src, dest imagesource.TypedIma
continue
}

// set docker defaults, but don't set default tag for digest refs
s := parsed
parsed.Ref = parsed.Ref.DockerClientDefaults()
if len(s.Ref.Tag) == 0 && len(s.Ref.ID) > 0 {
parsed.Ref.Tag = ""
}

// if src is a file store, assume all other references are in the same location on disk
if src.Type != imagesource.DestinationRegistry {
srcRef, err := mount(parsed, src, 0)
Expand All @@ -168,12 +186,6 @@ func mappingForImages(images map[string]struct{}, src, dest imagesource.TypedIma
continue
}

// set docker defaults, but don't set default tag for digest refs
s := parsed
parsed.Ref = parsed.Ref.DockerClientDefaults()
if len(s.Ref.Tag) == 0 && len(s.Ref.ID) > 0 {
parsed.Ref.Tag = ""
}
mapping[parsed] = targetRef
}
return
Expand Down