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

Fix regression from #9481 about defaulting prune images arguments #11552

Merged
merged 1 commit into from Oct 26, 2016
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
3 changes: 3 additions & 0 deletions pkg/build/prune/prune.go
Expand Up @@ -47,6 +47,9 @@ type PrunerOptions struct {

// NewPruner returns a Pruner over specified data using specified options.
func NewPruner(options PrunerOptions) Pruner {
glog.V(1).Infof("Creating build pruner with keepYoungerThan=%v, orphans=%v, keepComplete=%v, keepFailed=%v",
options.KeepYoungerThan, options.Orphans, options.KeepComplete, options.KeepFailed)

filter := &andFilter{
filterPredicates: []FilterPredicate{NewFilterBeforePredicate(options.KeepYoungerThan)},
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/cmd/admin/prune/images.go
Expand Up @@ -120,14 +120,15 @@ func (o *PruneImagesOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
return kcmdutil.UsageError(cmd, "no arguments are allowed to this command")
}

if !cmd.Flags().Lookup("keep-younger-than").Changed {
o.KeepYoungerThan = nil
}
if !cmd.Flags().Lookup("keep-tag-revisions").Changed {
o.KeepTagRevisions = nil
}
if !cmd.Flags().Lookup("prune-over-size-limit").Changed {
o.PruneOverSizeLimit = nil
} else {
if !cmd.Flags().Lookup("keep-younger-than").Changed {
o.KeepYoungerThan = nil
}
if !cmd.Flags().Lookup("keep-tag-revisions").Changed {
o.KeepTagRevisions = nil
}
}
o.Namespace = kapi.NamespaceAll
if cmd.Flags().Lookup("namespace").Changed {
Expand Down
3 changes: 3 additions & 0 deletions pkg/deploy/prune/prune.go
Expand Up @@ -50,6 +50,9 @@ type PrunerOptions struct {
// NewPruner returns a Pruner over specified data using specified options.
// deploymentConfigs, deployments, opts.KeepYoungerThan, opts.Orphans, opts.KeepComplete, opts.KeepFailed, deploymentPruneFunc
func NewPruner(options PrunerOptions) Pruner {
glog.V(1).Infof("Creating deployment pruner with keepYoungerThan=%v, orphans=%v, keepComplete=%v, keepFailed=%v",
options.KeepYoungerThan, options.Orphans, options.KeepComplete, options.KeepFailed)

filter := &andFilter{
filterPredicates: []FilterPredicate{
FilterDeploymentsPredicate,
Expand Down
15 changes: 11 additions & 4 deletions pkg/image/prune/prune.go
Expand Up @@ -244,10 +244,16 @@ func (*dryRunRegistryPinger) ping(registry string) error {
// Also automatically remove any image layer that is no longer referenced by any
// images.
func NewPruner(options PrunerOptions) Pruner {
g := graph.New()

glog.V(1).Infof("Creating image pruner with keepYoungerThan=%v, keepTagRevisions=%v, pruneOverSizeLimit=%v",
options.KeepYoungerThan, options.KeepTagRevisions, options.PruneOverSizeLimit)
keepTagRevisions := "<nil>"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"<nil>" reveals an implementation detail. To a regular user, it may look like a magic. Would it be perhaps better not to print unset parameters at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's consistent with what we have in other places. I wouldn't worry about this exposing implementation details ;)

if options.KeepTagRevisions != nil {
keepTagRevisions = fmt.Sprintf("%d", *options.KeepTagRevisions)
}
pruneOverSizeLimit := "<nil>"
if options.PruneOverSizeLimit != nil {
pruneOverSizeLimit = fmt.Sprintf("%v", *options.PruneOverSizeLimit)
}
glog.V(1).Infof("Creating image pruner with keepYoungerThan=%v, keepTagRevisions=%s, pruneOverSizeLimit=%s",
options.KeepYoungerThan, keepTagRevisions, pruneOverSizeLimit)

algorithm := pruneAlgorithm{}
if options.KeepYoungerThan != nil {
Expand All @@ -261,6 +267,7 @@ func NewPruner(options PrunerOptions) Pruner {
}
algorithm.namespace = options.Namespace

g := graph.New()
addImagesToGraph(g, options.Images, algorithm)
addImageStreamsToGraph(g, options.Streams, options.LimitRanges, algorithm)
addPodsToGraph(g, options.Pods, algorithm)
Expand Down