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
Bug 1902299: catalog mirror improvements #673
Merged
openshift-merge-robot
merged 4 commits into
openshift:master
from
ecordell:catalog-mirror-namespaceless-fix
Jan 16, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
38e14d6
properly handle mirroring namespaceless images
ecordell 128660e
mirroring catalog contents forces mirroring the entire manifestlist
ecordell 8a62892
Add an `index-filter-by-os` flag so that it is clearer that filtering
ecordell c615889
validation on destination of catalog mirror should minimally check host
ecordell File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"text/tabwriter" | ||
"time" | ||
|
@@ -123,9 +124,18 @@ func NewMirrorCatalog(f kcmdutil.Factory, streams genericclioptions.IOStreams) * | |
flags := cmd.Flags() | ||
|
||
o.SecurityOptions.Bind(flags) | ||
o.FilterOptions.Bind(flags) | ||
o.ParallelOptions.Bind(flags) | ||
|
||
// Images referenced by catalogs must have all variants mirrored. FilterByOs will only apply to the initial index | ||
// image, to indicate which arch should be used to extract the catalog db (the database inside should be the same | ||
// for all arches, so this flag should never need to be set explicitly for standard workflows). | ||
// this flag is renamed to make it clear that the underlying images are not filtered | ||
flags.StringVar(&o.FilterOptions.FilterByOS, "index-filter-by-os", o.FilterOptions.FilterByOS, "A regular expression to control which index image is picked when multiple variants are available. Images will be passed as '<platform>/<architecture>[/<variant>]'. This does not apply to images referenced by the index.") | ||
|
||
// the old flag name is kept for backwards-compatibility. | ||
// if both old and new are specified, the value of the flag coming later will be used. | ||
flags.StringVar(&o.FilterOptions.FilterByOS, "filter-by-os", o.FilterOptions.FilterByOS, "Use --index-filter-by-os instead. A regular expression to control which index image is picked when multiple variants are available. Images will be passed as '<platform>/<architecture>[/<variant>]'. This does not apply to images referenced by the index.") | ||
|
||
flags.StringVar(&o.ManifestDir, "to-manifests", "", "Local path to store manifests.") | ||
flags.StringVar(&o.DatabasePath, "path", "", "Specify an in-container to local path mapping for the database.") | ||
flags.BoolVar(&o.DryRun, "dry-run", o.DryRun, "Print the actions that would be taken and exit without writing to the destinations.") | ||
|
@@ -144,8 +154,10 @@ func (o *MirrorCatalogOptions) Complete(cmd *cobra.Command, args []string) error | |
src := args[0] | ||
dest := args[1] | ||
|
||
if err := o.FilterOptions.Complete(cmd.Flags()); err != nil { | ||
return err | ||
// default to linux/arm64 for index image, which we generally expect to exist | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: comment says default to |
||
pattern := o.FilterOptions.FilterByOS | ||
if len(pattern) == 0 { | ||
o.FilterOptions.FilterByOS = regexp.QuoteMeta(fmt.Sprintf("%s/%s", "linux", "amd64")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is excessive, just pass |
||
} | ||
if err := o.FilterOptions.Validate(); err != nil { | ||
return err | ||
|
@@ -176,6 +188,11 @@ func (o *MirrorCatalogOptions) Complete(cmd *cobra.Command, args []string) error | |
o.ManifestDir = fmt.Sprintf("manifests-%s-%d", o.SourceRef.Ref.Name, time.Now().Unix()) | ||
} | ||
|
||
allmanifests := imagemanifest.FilterOptions{FilterByOS: ".*"} | ||
if err := allmanifests.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
if err := os.MkdirAll(o.ManifestDir, os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
@@ -260,7 +277,11 @@ func (o *MirrorCatalogOptions) Complete(cmd *cobra.Command, args []string) error | |
a.ContinueOnError = true | ||
a.DryRun = o.DryRun | ||
a.SecurityOptions = o.SecurityOptions | ||
a.FilterOptions = o.FilterOptions | ||
// because images in the catalog are statically referenced by digest, | ||
// we do not allow filtering for mirroring. this may change if sparse manifestlists are allowed | ||
// by registries, or if multi-arch management moves into images that can be rewritten on mirror (i.e. the bundle | ||
// images themselves, not the images referenced inside of the bundle images). | ||
a.FilterOptions = allmanifests | ||
a.ParallelOptions = o.ParallelOptions | ||
a.KeepManifestList = true | ||
a.Mappings = mappings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest deprecating this flag, not to confuse users. Can be done in a follow-up.