Skip to content

Commit

Permalink
[release-4.12] OCPBUGS-863: Add skip pruning flag and logic (#591)
Browse files Browse the repository at this point in the history
* Remove "unsupported" wording from info on console

* Add skip pruning flag and logic

* Update for suggestion made in review

* Fixed failing unit test
  • Loading branch information
lmzuccarelli committed Mar 29, 2023
1 parent 8ee9d19 commit 7635353
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/mirror/manifests_test.go
Expand Up @@ -458,7 +458,7 @@ func TestICSPGeneration(t *testing.T) {
// for loop replaces require.Equal(test.expected, icsps): order elements in Spec.RepositoryDigestMirrors
// was making the test fail
for ind, icsp := range test.expected {
require.Equal(t, icsp.Spec.RepositoryDigestMirrors, icsps[ind].Spec.RepositoryDigestMirrors)
require.ElementsMatch(t, icsp.Spec.RepositoryDigestMirrors, icsps[ind].Spec.RepositoryDigestMirrors)
require.Equal(t, icsp.Labels, icsps[ind].Labels)
require.Equal(t, icsp.Name, icsps[ind].Name)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/mirror/mirror.go
Expand Up @@ -262,6 +262,10 @@ func (o *MirrorOptions) Validate() error {
}
}

if o.SkipPruning {
klog.Infof("using --skip-pruning flag - pruning will be skipped")
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/mirror/options.go
Expand Up @@ -30,6 +30,7 @@ type MirrorOptions struct {
SkipCleanup bool
SkipMissing bool
SkipMetadataCheck bool
SkipPruning bool
ContinueOnError bool
IgnoreHistory bool
MaxPerRegistry int
Expand Down Expand Up @@ -73,6 +74,7 @@ func (o *MirrorOptions) BindFlags(fs *pflag.FlagSet) {
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.IntVar(&o.MaxNestedPaths, "max-nested-paths", 2, "Number of nested paths, for destination registries that limit nested paths")
fs.BoolVar(&o.SkipPruning, "skip-pruning", o.SkipPruning, "If set, will disable pruning globally")
}

func (o *MirrorOptions) init() {
Expand Down
17 changes: 11 additions & 6 deletions pkg/cli/mirror/prune.go
Expand Up @@ -26,13 +26,18 @@ import (

// pruneRegistry plans and executes registry pruning based on current and previous Associations.
func (o *MirrorOptions) pruneRegistry(ctx context.Context, prev, curr image.AssociationSet) error {
deleter, toRemove, err := o.planImagePruning(ctx, curr, prev)
if err != nil {
return err
//CFE-739
if !o.SkipPruning {
deleter, toRemove, err := o.planImagePruning(ctx, curr, prev)
if err != nil {
return err
}
// We can use MaxPerRegistry for maxWorkers because
// we only prune from one registry
return o.pruneImages(deleter, toRemove, o.MaxPerRegistry)
}
// We can use MaxPerRegistry for maxWorkers because
// we only prune from one registry
return o.pruneImages(deleter, toRemove, o.MaxPerRegistry)
klog.Info("skipped pruning")
return nil
}

// planImagePruning creates a ManifestDeleter and map of manifests scheduled for deletion.
Expand Down

0 comments on commit 7635353

Please sign in to comment.