Skip to content

Commit

Permalink
Merge branch 'openshift:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
lmzuccarelli committed Apr 28, 2023
2 parents 2424727 + 90ac82c commit 7210f5c
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .ci-operator.yaml
@@ -1,4 +1,4 @@
build_root_image:
name: release
namespace: openshift
tag: rhel-8-release-golang-1.19-openshift-4.14
tag: rhel-8-release-golang-1.20-openshift-4.14
2 changes: 1 addition & 1 deletion images/cli/Dockerfile.ci
@@ -1,5 +1,5 @@
# This Dockerfile is used by CI to publish the oc-mirror image.
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.19-openshift-4.14 AS builder
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.20-openshift-4.14 AS builder
WORKDIR /go/src/github.com/openshift/oc-mirror
COPY . .
RUN make build
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/mirror/catalog_images.go
Expand Up @@ -176,7 +176,7 @@ func (o *MirrorOptions) processCatalogRefs(ctx context.Context, catalogsByImage
containertools.ConfigsLocationLabel: "/configs",
}
cfg.Config.Labels = labels
cfg.Config.Cmd = []string{"serve", "/configs", "--cache-dir", "/tmp/cache"}
cfg.Config.Cmd = []string{"serve", "/configs"}
cfg.Config.Entrypoint = []string{"/bin/opm"}
}
if err := imgBuilder.Run(ctx, refExact, layoutPath, update, layers...); err != nil {
Expand Down
26 changes: 17 additions & 9 deletions pkg/cli/mirror/mirror.go
Expand Up @@ -255,11 +255,11 @@ func (o *MirrorOptions) Validate() error {
mirrorToMirror := len(o.ToMirror) > 0 && len(o.ConfigPath) > 0

// mirrorToDisk workflow is not supported with the oci feature
if o.UseOCIFeature && mirrorToDisk {
if o.IncludeLocalOCICatalogs && mirrorToDisk {
return fmt.Errorf("oci feature cannot be used when mirroring to local archive")
}
// diskToMirror workflow is not supported with the oci feature
if o.UseOCIFeature && diskToMirror {
if o.IncludeLocalOCICatalogs && diskToMirror {
return fmt.Errorf("oci feature cannot be used when publishing from a local archive to a registry")
}
// mirrorToMirror workflow using the oci feature must have at least on operator set with oci:// prefix
Expand All @@ -274,15 +274,15 @@ func (o *MirrorOptions) Validate() error {
bIsFBOCI = true
}
}
if o.UseOCIFeature && !bIsFBOCI {
return fmt.Errorf("no operator found with OCI FBC catalog prefix (oci://) in configuration file, please execute without the --use-oci-feature flag")
if o.IncludeLocalOCICatalogs && !bIsFBOCI {
return fmt.Errorf("no operator found with OCI FBC catalog prefix (oci://) in configuration file, please execute without the --include-local-oci-catalogs flag")
}
if !o.UseOCIFeature && bIsFBOCI {
return fmt.Errorf("use of OCI FBC catalogs (prefix oci://) in configuration file is authorized only with flag --use-oci-feature")
if !o.IncludeLocalOCICatalogs && bIsFBOCI {
return fmt.Errorf("use of OCI FBC catalogs (prefix oci://) in configuration file is authorized only with flag --include-local-oci-catalogs")
}
}
if !o.UseOCIFeature && len(o.OCIRegistriesConfig) > 0 {
return fmt.Errorf("oci-registries-config flag can only be used with the --use-oci-feature flag")
if !o.IncludeLocalOCICatalogs && len(o.OCIRegistriesConfig) > 0 {
return fmt.Errorf("oci-registries-config flag can only be used with the --include-local-oci-catalog flag")
}

if o.SkipPruning {
Expand Down Expand Up @@ -632,7 +632,7 @@ func (o *MirrorOptions) mirrorToMirrorWrapper(ctx context.Context, cfg v1alpha2.
if err != nil {
return err
}
if !o.UseOCIFeature {
if !o.IncludeLocalOCICatalogs {
var curr v1alpha2.Metadata
berr := targetBackend.ReadMetadata(ctx, &curr, config.MetadataBasePath)
if err := o.checkSequence(meta, curr, berr); err != nil {
Expand Down Expand Up @@ -858,8 +858,16 @@ func (o *MirrorOptions) diskToMirrorWrapper(ctx context.Context, cleanup cleanup
// Publish from disk to registry
// this takes care of syncing the metadata to the
// registry backends.

mapping, err := o.Publish(ctx)
if err != nil {
// OCPBUGS-4959 for automation processes to end gracefully
// when we have the same sequence - i.e nothing to do
msqErr := &ErrMirrorSequence{}
if errors.As(err, &msqErr) {
klog.Info("No diff from previous mirror (sequence is the same), nothing to do")
return cleanup()
}
serr := &ErrInvalidSequence{}
if errors.As(err, &serr) {
return fmt.Errorf("error during publishing, expecting imageset with prefix mirror_seq%d: %v", serr.wantSeq, err)
Expand Down
28 changes: 14 additions & 14 deletions pkg/cli/mirror/mirror_test.go
Expand Up @@ -291,38 +291,38 @@ func TestMirrorValidate(t *testing.T) {
{
name: "Invalid/MirrortoDisk/OCIFlag",
opts: &MirrorOptions{
OutputDir: t.TempDir(),
ConfigPath: "foo",
UseOCIFeature: true,
OutputDir: t.TempDir(),
ConfigPath: "foo",
IncludeLocalOCICatalogs: true,
},
expError: "oci feature cannot be used when mirroring to local archive",
},
{
name: "Invalid/DisktoMirror/OCIFlag",
opts: &MirrorOptions{
From: t.TempDir(),
ToMirror: u.Host,
UseOCIFeature: true,
From: t.TempDir(),
ToMirror: u.Host,
IncludeLocalOCICatalogs: true,
},
expError: "oci feature cannot be used when publishing from a local archive to a registry",
},
{
name: "Invalid/MirrorToMirror/ImageSetConfigWithOCI",
opts: &MirrorOptions{
ConfigPath: "testdata/configs/iscfg_oci_ops.yaml",
ToMirror: u.Host,
UseOCIFeature: false,
ConfigPath: "testdata/configs/iscfg_oci_ops.yaml",
ToMirror: u.Host,
IncludeLocalOCICatalogs: false,
},
expError: "use of OCI FBC catalogs (prefix oci://) in configuration file is authorized only with flag --use-oci-feature",
expError: "use of OCI FBC catalogs (prefix oci://) in configuration file is authorized only with flag --include-local-oci-catalogs",
},
{
name: "Invalid/MirrorToMirror/ImageSetConfigWithoutOCI",
opts: &MirrorOptions{
ConfigPath: "testdata/configs/iscfg.yaml",
ToMirror: u.Host,
UseOCIFeature: true,
ConfigPath: "testdata/configs/iscfg.yaml",
ToMirror: u.Host,
IncludeLocalOCICatalogs: true,
},
expError: "no operator found with OCI FBC catalog prefix (oci://) in configuration file, please execute without the --use-oci-feature flag",
expError: "no operator found with OCI FBC catalog prefix (oci://) in configuration file, please execute without the --include-local-oci-catalogs flag",
},
{
name: "Valid/ManifestOnlyWithFakeMirror",
Expand Down
7 changes: 4 additions & 3 deletions pkg/cli/mirror/options.go
Expand Up @@ -34,7 +34,7 @@ type MirrorOptions struct {
ContinueOnError bool
IgnoreHistory bool
MaxPerRegistry int
UseOCIFeature bool
IncludeLocalOCICatalogs bool
OCIRegistriesConfig string
OCIInsecureSignaturePolicy bool
MaxNestedPaths int
Expand Down Expand Up @@ -68,12 +68,13 @@ func (o *MirrorOptions) BindFlags(fs *pflag.FlagSet) {
"404/NotFound errors encountered while pulling images explicitly specified in the config "+
"will not be skipped")
fs.IntVar(&o.MaxPerRegistry, "max-per-registry", 6, "Number of concurrent requests allowed per registry")
fs.BoolVar(&o.UseOCIFeature, "use-oci-feature", o.UseOCIFeature, "Use the new oci feature for oc mirror (oci formatted copy")
fs.BoolVar(&o.IncludeLocalOCICatalogs, "use-oci-feature", o.IncludeLocalOCICatalogs, "Deprecated, use --include-local-oci-catalog instead")
fs.BoolVar(&o.IncludeLocalOCICatalogs, "include-local-oci-catalogs", o.IncludeLocalOCICatalogs, "If set, enables including local OCI-formatted catalogs (prefix oci://) in the list of operator catalogs defined in ImageSetConfig, so that these local catalogs are mirrored from the disk directly")
fs.StringVar(&o.OCIRegistriesConfig, "oci-registries-config", o.OCIRegistriesConfig, "Registries config file location (used only with --use-oci-feature flag)")
fs.BoolVar(&o.OCIInsecureSignaturePolicy, "oci-insecure-signature-policy", o.OCIInsecureSignaturePolicy, "If set, OCI catalog push will not try to push signatures")
fs.BoolVar(&o.SkipPruning, "skip-pruning", o.SkipPruning, "If set, will disable pruning globally")
fs.IntVar(&o.MaxNestedPaths, "max-nested-paths", 2, "Number of nested paths, for destination registries that limit nested paths")

fs.MarkDeprecated("use-oci-feature", "Use --include-local-oci-catalogs instead")
}

func (o *MirrorOptions) init() {
Expand Down
12 changes: 12 additions & 0 deletions pkg/cli/mirror/sequence.go
Expand Up @@ -17,10 +17,18 @@ type ErrInvalidSequence struct {
gotSeq int
}

type ErrMirrorSequence struct {
msg string
}

func (s *ErrInvalidSequence) Error() string {
return fmt.Sprintf("invalid mirror sequence order, want %v, got %v", s.wantSeq, s.gotSeq)
}

func (s *ErrMirrorSequence) Error() string {
return fmt.Sprintf(s.msg)
}

func (o *MirrorOptions) checkSequence(incoming, current v1alpha2.Metadata, backendErr error) error {
switch {
case backendErr != nil && !errors.Is(backendErr, storage.ErrMetadataNotExist):
Expand All @@ -40,6 +48,10 @@ func (o *MirrorOptions) checkSequence(incoming, current v1alpha2.Metadata, backe
klog.V(3).Info("Checking metadata sequence number")
currRun := current.PastMirror
incomingRun := incoming.PastMirror
// OCPBUGS-4959
if incomingRun.Sequence == currRun.Sequence {
return &ErrMirrorSequence{msg: "mirror sequence is the same"}
}
if incomingRun.Sequence != (currRun.Sequence + 1) {
return &ErrInvalidSequence{currRun.Sequence + 1, incomingRun.Sequence}
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/operator/diff/internal/diff.go
Expand Up @@ -405,6 +405,12 @@ func addAllDependencies(newModel, oldModel, outputModel model.Model) error {

head := heads[newCh.Name]
graph := makeUpgradeGraph(newCh)

//OCPBUGS-11371 - bundles in skips field should not be considered since they are not part of upgradeGraph
if isToSkip(*b, *head) {
continue
}

intersectingBundles, intersectionFound := findIntersectingBundles(newCh, b, head, graph)
if !intersectionFound {
// This should never happen, since b and head are from the same model.
Expand Down Expand Up @@ -494,6 +500,7 @@ func getBundlesThatProvide(pkg *model.Package, reqGVKs map[property.GVK]struct{}
if isPkgRequired {
bundlesByRange = make([][]*model.Bundle, len(ranges))
}

// Collect package bundles that provide a GVK or are in a range.
bundlesProvidingGVK := make(map[property.GVK][]*model.Bundle)
for _, ch := range pkg.Channels {
Expand Down Expand Up @@ -563,6 +570,17 @@ func getBundlesThatProvide(pkg *model.Package, reqGVKs map[property.GVK]struct{}
return providingBundles
}

// isToSkip detects if the bundle is skipped by the head of the channel
func isToSkip(b model.Bundle, head model.Bundle) bool {
for _, versionToSkip := range head.Skips {
if versionToSkip == b.Name {
return true
}
}

return false
}

func convertFromModelBundle(b *model.Bundle) declcfg.Bundle {
return declcfg.Bundle{
Schema: declcfg.SchemaBundle,
Expand Down

0 comments on commit 7210f5c

Please sign in to comment.