Browse code

Fix regression from #9481 about defaulting prune images arguments

Currently oadm prune images has no default arguments, but
keepTagRevisions should be 3 and keepYoungerThan should be 60 mins. Upon
adding pruneOverSizeLimit that was broken, this commit fixes that
problem. Additionally, I've added logs about what the parameters are set
to other prune commands.

Maciej Szulik authored on 2016/10/25 18:26:39
Showing 4 changed files
... ...
@@ -47,6 +47,9 @@ type PrunerOptions struct {
47 47
 
48 48
 // NewPruner returns a Pruner over specified data using specified options.
49 49
 func NewPruner(options PrunerOptions) Pruner {
50
+	glog.V(1).Infof("Creating build pruner with keepYoungerThan=%v, orphans=%v, keepComplete=%v, keepFailed=%v",
51
+		options.KeepYoungerThan, options.Orphans, options.KeepComplete, options.KeepFailed)
52
+
50 53
 	filter := &andFilter{
51 54
 		filterPredicates: []FilterPredicate{NewFilterBeforePredicate(options.KeepYoungerThan)},
52 55
 	}
... ...
@@ -120,14 +120,15 @@ func (o *PruneImagesOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
120 120
 		return kcmdutil.UsageError(cmd, "no arguments are allowed to this command")
121 121
 	}
122 122
 
123
-	if !cmd.Flags().Lookup("keep-younger-than").Changed {
124
-		o.KeepYoungerThan = nil
125
-	}
126
-	if !cmd.Flags().Lookup("keep-tag-revisions").Changed {
127
-		o.KeepTagRevisions = nil
128
-	}
129 123
 	if !cmd.Flags().Lookup("prune-over-size-limit").Changed {
130 124
 		o.PruneOverSizeLimit = nil
125
+	} else {
126
+		if !cmd.Flags().Lookup("keep-younger-than").Changed {
127
+			o.KeepYoungerThan = nil
128
+		}
129
+		if !cmd.Flags().Lookup("keep-tag-revisions").Changed {
130
+			o.KeepTagRevisions = nil
131
+		}
131 132
 	}
132 133
 	o.Namespace = kapi.NamespaceAll
133 134
 	if cmd.Flags().Lookup("namespace").Changed {
... ...
@@ -50,6 +50,9 @@ type PrunerOptions struct {
50 50
 // NewPruner returns a Pruner over specified data using specified options.
51 51
 // deploymentConfigs, deployments, opts.KeepYoungerThan, opts.Orphans, opts.KeepComplete, opts.KeepFailed, deploymentPruneFunc
52 52
 func NewPruner(options PrunerOptions) Pruner {
53
+	glog.V(1).Infof("Creating deployment pruner with keepYoungerThan=%v, orphans=%v, keepComplete=%v, keepFailed=%v",
54
+		options.KeepYoungerThan, options.Orphans, options.KeepComplete, options.KeepFailed)
55
+
53 56
 	filter := &andFilter{
54 57
 		filterPredicates: []FilterPredicate{
55 58
 			FilterDeploymentsPredicate,
... ...
@@ -244,10 +244,16 @@ func (*dryRunRegistryPinger) ping(registry string) error {
244 244
 // Also automatically remove any image layer that is no longer referenced by any
245 245
 // images.
246 246
 func NewPruner(options PrunerOptions) Pruner {
247
-	g := graph.New()
248
-
249
-	glog.V(1).Infof("Creating image pruner with keepYoungerThan=%v, keepTagRevisions=%v, pruneOverSizeLimit=%v",
250
-		options.KeepYoungerThan, options.KeepTagRevisions, options.PruneOverSizeLimit)
247
+	keepTagRevisions := "<nil>"
248
+	if options.KeepTagRevisions != nil {
249
+		keepTagRevisions = fmt.Sprintf("%d", *options.KeepTagRevisions)
250
+	}
251
+	pruneOverSizeLimit := "<nil>"
252
+	if options.PruneOverSizeLimit != nil {
253
+		pruneOverSizeLimit = fmt.Sprintf("%v", *options.PruneOverSizeLimit)
254
+	}
255
+	glog.V(1).Infof("Creating image pruner with keepYoungerThan=%v, keepTagRevisions=%s, pruneOverSizeLimit=%s",
256
+		options.KeepYoungerThan, keepTagRevisions, pruneOverSizeLimit)
251 257
 
252 258
 	algorithm := pruneAlgorithm{}
253 259
 	if options.KeepYoungerThan != nil {
... ...
@@ -261,6 +267,7 @@ func NewPruner(options PrunerOptions) Pruner {
261 261
 	}
262 262
 	algorithm.namespace = options.Namespace
263 263
 
264
+	g := graph.New()
264 265
 	addImagesToGraph(g, options.Images, algorithm)
265 266
 	addImageStreamsToGraph(g, options.Streams, options.LimitRanges, algorithm)
266 267
 	addPodsToGraph(g, options.Pods, algorithm)