@@ -260,21 +260,6 @@ func addImagesToGraph(g graph.Graph, images *imageapi.ImageList, algorithm prune
260
260
for i := range images .Items {
261
261
image := & images .Items [i ]
262
262
263
- glog .V (4 ).Infof ("Examining image %q" , image .Name )
264
-
265
- if ! algorithm .allImages {
266
- if image .Annotations [imageapi .ManagedByOpenShiftAnnotation ] != "true" {
267
- glog .V (4 ).Infof ("Image %q with DockerImageReference %q belongs to an external registry - skipping" , image .Name , image .DockerImageReference )
268
- continue
269
- }
270
- }
271
-
272
- age := metav1 .Now ().Sub (image .CreationTimestamp .Time )
273
- if ! algorithm .pruneOverSizeLimit && age < algorithm .keepYoungerThan {
274
- glog .V (4 ).Infof ("Image %q is younger than minimum pruning age, skipping (age=%v)" , image .Name , age )
275
- continue
276
- }
277
-
278
263
glog .V (4 ).Infof ("Adding image %q to graph" , image .Name )
279
264
imageNode := imagegraph .EnsureImageNode (g , image )
280
265
@@ -596,12 +581,26 @@ func edgeKind(g graph.Graph, from, to gonum.Node, desiredKind string) bool {
596
581
return kinds .Has (desiredKind )
597
582
}
598
583
599
- // imageIsPrunable returns true iff the image node only has weak references
584
+ // imageIsPrunable returns true if the image node only has weak references
600
585
// from its predecessors to it. A weak reference to an image is a reference
601
586
// from an image stream to an image where the image is not the current image
602
587
// for a tag and the image stream is at least as old as the minimum pruning
603
588
// age.
604
- func imageIsPrunable (g graph.Graph , imageNode * imagegraph.ImageNode ) bool {
589
+ func imageIsPrunable (g graph.Graph , imageNode * imagegraph.ImageNode , algorithm pruneAlgorithm ) bool {
590
+ if ! algorithm .allImages {
591
+ if imageNode .Image .Annotations [imageapi .ManagedByOpenShiftAnnotation ] != "true" {
592
+ glog .V (4 ).Infof ("Image %q with DockerImageReference %q belongs to an external registry - skipping" ,
593
+ imageNode .Image .Name , imageNode .Image .DockerImageReference )
594
+ return false
595
+ }
596
+ }
597
+
598
+ age := metav1 .Now ().Sub (imageNode .Image .CreationTimestamp .Time )
599
+ if ! algorithm .pruneOverSizeLimit && age < algorithm .keepYoungerThan {
600
+ glog .V (4 ).Infof ("Image %q is younger than minimum pruning age, skipping (age=%v)" , imageNode .Image .Name , age )
601
+ return false
602
+ }
603
+
605
604
for _ , n := range g .To (imageNode ) {
606
605
glog .V (4 ).Infof ("Examining predecessor %#v" , n )
607
606
if edgeKind (g , n , imageNode , ReferencedImageEdgeKind ) {
@@ -615,14 +614,14 @@ func imageIsPrunable(g graph.Graph, imageNode *imagegraph.ImageNode) bool {
615
614
616
615
// calculatePrunableImages returns the list of prunable images and a
617
616
// graph.NodeSet containing the image node IDs.
618
- func calculatePrunableImages (g graph.Graph , imageNodes []* imagegraph.ImageNode ) ([]* imagegraph.ImageNode , graph.NodeSet ) {
617
+ func calculatePrunableImages (g graph.Graph , imageNodes []* imagegraph.ImageNode , algorithm pruneAlgorithm ) ([]* imagegraph.ImageNode , graph.NodeSet ) {
619
618
prunable := []* imagegraph.ImageNode {}
620
619
ids := make (graph.NodeSet )
621
620
622
621
for _ , imageNode := range imageNodes {
623
622
glog .V (4 ).Infof ("Examining image %q" , imageNode .Image .Name )
624
623
625
- if imageIsPrunable (g , imageNode ) {
624
+ if imageIsPrunable (g , imageNode , algorithm ) {
626
625
glog .V (4 ).Infof ("Image %q is prunable" , imageNode .Image .Name )
627
626
prunable = append (prunable , imageNode )
628
627
ids .Add (imageNode .ID ())
@@ -765,7 +764,7 @@ func (p *pruner) Prune(
765
764
return nil
766
765
}
767
766
768
- prunableImageNodes , prunableImageIDs := calculatePrunableImages (p .g , imageNodes )
767
+ prunableImageNodes , prunableImageIDs := calculatePrunableImages (p .g , imageNodes , p . algorithm )
769
768
770
769
errs := []error {}
771
770
errs = append (errs , pruneStreams (p .g , prunableImageNodes , streamPruner )... )
0 commit comments