@@ -6,15 +6,18 @@ import (
6
6
"net/http"
7
7
"reflect"
8
8
"sort"
9
+ "strings"
9
10
"time"
10
11
11
12
"github.com/docker/distribution/manifest/schema2"
12
13
"github.com/docker/distribution/registry/api/errcode"
13
14
"github.com/golang/glog"
14
15
gonum "github.com/gonum/graph"
15
16
17
+ kmeta "k8s.io/apimachinery/pkg/api/meta"
16
18
"k8s.io/apimachinery/pkg/api/resource"
17
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
+ "k8s.io/apimachinery/pkg/runtime"
18
21
kerrors "k8s.io/apimachinery/pkg/util/errors"
19
22
"k8s.io/apimachinery/pkg/util/sets"
20
23
kapi "k8s.io/kubernetes/pkg/api"
@@ -377,7 +380,7 @@ func addImageStreamsToGraph(g graph.Graph, streams *imageapi.ImageStreamList, li
377
380
for i := range streams .Items {
378
381
stream := & streams .Items [i ]
379
382
380
- glog .V (4 ).Infof ("Examining ImageStream %s/%s " , stream . Namespace , stream . Name )
383
+ glog .V (4 ).Infof ("Examining ImageStream %s" , getName ( stream ) )
381
384
382
385
// use a weak reference for old image revisions by default
383
386
oldImageRevisionReferenceKind := WeakReferencedImageEdgeKind
@@ -388,7 +391,7 @@ func addImageStreamsToGraph(g graph.Graph, streams *imageapi.ImageStreamList, li
388
391
oldImageRevisionReferenceKind = ReferencedImageEdgeKind
389
392
}
390
393
391
- glog .V (4 ).Infof ("Adding ImageStream %s/%s to graph" , stream . Namespace , stream . Name )
394
+ glog .V (4 ).Infof ("Adding ImageStream %s to graph" , getName ( stream ) )
392
395
isNode := imagegraph .EnsureImageStreamNode (g , stream )
393
396
imageStreamNode := isNode .(* imagegraph.ImageStreamNode )
394
397
@@ -415,7 +418,7 @@ func addImageStreamsToGraph(g graph.Graph, streams *imageapi.ImageStreamList, li
415
418
}
416
419
}
417
420
418
- glog .V (4 ).Infof ("Checking for existing strong reference from stream %s/%s to image %s" , stream . Namespace , stream . Name , imageNode .Image .Name )
421
+ glog .V (4 ).Infof ("Checking for existing strong reference from stream %s to image %s" , getName ( stream ) , imageNode .Image .Name )
419
422
if edge := g .Edge (imageStreamNode , imageNode ); edge != nil && g .EdgeKinds (edge ).Has (ReferencedImageEdgeKind ) {
420
423
glog .V (4 ).Infof ("Strong reference found" )
421
424
continue
@@ -432,7 +435,7 @@ func addImageStreamsToGraph(g graph.Graph, streams *imageapi.ImageStreamList, li
432
435
continue
433
436
}
434
437
435
- glog .V (4 ).Infof ("Adding reference from stream %q to %s" , stream . Name , cn .Describe ())
438
+ glog .V (4 ).Infof ("Adding reference from stream %s to %s" , getName ( stream ) , cn .Describe ())
436
439
if cn .Type == imagegraph .ImageComponentTypeConfig {
437
440
g .AddEdge (imageStreamNode , s , ReferencedImageConfigEdgeKind )
438
441
} else {
@@ -447,10 +450,7 @@ func addImageStreamsToGraph(g graph.Graph, streams *imageapi.ImageStreamList, li
447
450
// exceedsLimits checks if given image exceeds LimitRanges defined in ImageStream's namespace.
448
451
func exceedsLimits (is * imageapi.ImageStream , image * imageapi.Image , limits map [string ][]* kapi.LimitRange ) bool {
449
452
limitRanges , ok := limits [is .Namespace ]
450
- if ! ok {
451
- return false
452
- }
453
- if len (limitRanges ) == 0 {
453
+ if ! ok || len (limitRanges ) == 0 {
454
454
return false
455
455
}
456
456
@@ -470,8 +470,8 @@ func exceedsLimits(is *imageapi.ImageStream, image *imageapi.Image, limits map[s
470
470
}
471
471
if limitQuantity .Cmp (* imageSize ) < 0 {
472
472
// image size is larger than the permitted limit range max size
473
- glog .V (4 ).Infof ("Image %s in stream %s/%s exceeds limit %s: %v vs %v" ,
474
- image .Name , is . Namespace , is . Name , limitRange .Name , * imageSize , limitQuantity )
473
+ glog .V (4 ).Infof ("Image %s in stream %s exceeds limit %s: %v vs %v" ,
474
+ image .Name , getName ( is ) , limitRange .Name , * imageSize , limitQuantity )
475
475
return true
476
476
}
477
477
}
@@ -481,28 +481,26 @@ func exceedsLimits(is *imageapi.ImageStream, image *imageapi.Image, limits map[s
481
481
482
482
// addPodsToGraph adds pods to the graph.
483
483
//
484
- // A pod is only *excluded* from being added to the graph if its phase is not
485
- // pending or running and it is at least as old as the minimum age threshold
486
- // defined by algorithm.
487
- //
488
484
// Edges are added to the graph from each pod to the images specified by that
489
485
// pod's list of containers, as long as the image is managed by OpenShift.
490
486
func addPodsToGraph (g graph.Graph , pods * kapi.PodList , algorithm pruneAlgorithm ) {
491
487
for i := range pods .Items {
492
488
pod := & pods .Items [i ]
493
489
494
- glog .V (4 ).Infof ("Examining pod %s/%s " , pod . Namespace , pod . Name )
490
+ glog .V (4 ).Infof ("Examining pod %s" , getName ( pod ) )
495
491
492
+ // A pod is only *excluded* from being added to the graph if its phase is not
493
+ // pending or running. Additionally, it has to be at least as old as the minimum
494
+ // age threshold defined by the algorithm.
496
495
if pod .Status .Phase != kapi .PodRunning && pod .Status .Phase != kapi .PodPending {
497
496
age := metav1 .Now ().Sub (pod .CreationTimestamp .Time )
498
497
if age >= algorithm .keepYoungerThan {
499
- glog .V (4 ).Infof ("Pod %s/%s is not running or pending and age is at least minimum pruning age - skipping" , pod .Namespace , pod .Name )
500
- // not pending or running, age is at least minimum pruning age, skip
498
+ glog .V (4 ).Infof ("Pod %s is not running nor pending and age exceeds keepYoungerThan (%v) - skipping" , getName (pod ), age )
501
499
continue
502
500
}
503
501
}
504
502
505
- glog .V (4 ).Infof ("Adding pod %s/%s to graph" , pod . Namespace , pod . Name )
503
+ glog .V (4 ).Infof ("Adding pod %s to graph" , getName ( pod ) )
506
504
podNode := kubegraph .EnsurePodNode (g , pod )
507
505
508
506
addPodSpecToGraph (g , & pod .Spec , podNode )
@@ -548,7 +546,7 @@ func addPodSpecToGraph(g graph.Graph, spec *kapi.PodSpec, predecessor gonum.Node
548
546
func addReplicationControllersToGraph (g graph.Graph , rcs * kapi.ReplicationControllerList ) {
549
547
for i := range rcs .Items {
550
548
rc := & rcs .Items [i ]
551
- glog .V (4 ).Infof ("Examining replication controller %s/%s " , rc . Namespace , rc . Name )
549
+ glog .V (4 ).Infof ("Examining replication controller %s" , getName ( rc ) )
552
550
rcNode := kubegraph .EnsureReplicationControllerNode (g , rc )
553
551
addPodSpecToGraph (g , & rc .Spec .Template .Spec , rcNode )
554
552
}
@@ -562,7 +560,7 @@ func addReplicationControllersToGraph(g graph.Graph, rcs *kapi.ReplicationContro
562
560
func addDeploymentConfigsToGraph (g graph.Graph , dcs * deployapi.DeploymentConfigList ) {
563
561
for i := range dcs .Items {
564
562
dc := & dcs .Items [i ]
565
- glog .V (4 ).Infof ("Examining DeploymentConfig %s/%s " , dc . Namespace , dc . Name )
563
+ glog .V (4 ).Infof ("Examining DeploymentConfig %s" , getName ( dc ) )
566
564
dcNode := deploygraph .EnsureDeploymentConfigNode (g , dc )
567
565
addPodSpecToGraph (g , & dc .Spec .Template .Spec , dcNode )
568
566
}
@@ -574,7 +572,7 @@ func addDeploymentConfigsToGraph(g graph.Graph, dcs *deployapi.DeploymentConfigL
574
572
func addBuildConfigsToGraph (g graph.Graph , bcs * buildapi.BuildConfigList ) {
575
573
for i := range bcs .Items {
576
574
bc := & bcs .Items [i ]
577
- glog .V (4 ).Infof ("Examining BuildConfig %s/%s " , bc . Namespace , bc . Name )
575
+ glog .V (4 ).Infof ("Examining BuildConfig %s" , getName ( bc ) )
578
576
bcNode := buildgraph .EnsureBuildConfigNode (g , bc )
579
577
addBuildStrategyImageReferencesToGraph (g , bc .Spec .Strategy , bcNode )
580
578
}
@@ -586,7 +584,7 @@ func addBuildConfigsToGraph(g graph.Graph, bcs *buildapi.BuildConfigList) {
586
584
func addBuildsToGraph (g graph.Graph , builds * buildapi.BuildList ) {
587
585
for i := range builds .Items {
588
586
build := & builds .Items [i ]
589
- glog .V (4 ).Infof ("Examining build %s/%s " , build . Namespace , build . Name )
587
+ glog .V (4 ).Infof ("Examining build %s" , getName ( build ) )
590
588
buildNode := buildgraph .EnsureBuildNode (g , build )
591
589
addBuildStrategyImageReferencesToGraph (g , build .Spec .Strategy , buildNode )
592
590
}
@@ -761,7 +759,7 @@ func pruneStreams(g graph.Graph, imageNodes []*imagegraph.ImageNode, streamPrune
761
759
stream := streamNode .ImageStream
762
760
updatedTags := sets .NewString ()
763
761
764
- glog .V (4 ).Infof ("Checking if ImageStream %s/%s has references to image %s in status.tags" , stream . Namespace , stream . Name , imageNode .Image .Name )
762
+ glog .V (4 ).Infof ("Checking if ImageStream %s has references to image %s in status.tags" , getName ( stream ) , imageNode .Image .Name )
765
763
766
764
for tag , history := range stream .Status .Tags {
767
765
glog .V (4 ).Infof ("Checking tag %q" , tag )
@@ -780,7 +778,7 @@ func pruneStreams(g graph.Graph, imageNodes []*imagegraph.ImageNode, streamPrune
780
778
}
781
779
}
782
780
if len (newHistory .Items ) == 0 {
783
- glog .V (4 ).Infof ("Removing tag %q from status.tags of ImageStream %s/%s " , tag , stream . Namespace , stream . Name )
781
+ glog .V (4 ).Infof ("Removing tag %q from status.tags of ImageStream %s" , tag , getName ( stream ) )
784
782
delete (stream .Status .Tags , tag )
785
783
} else {
786
784
stream .Status .Tags [tag ] = newHistory
@@ -789,7 +787,8 @@ func pruneStreams(g graph.Graph, imageNodes []*imagegraph.ImageNode, streamPrune
789
787
790
788
updatedStream , err := streamPruner .DeleteImageStream (stream , imageNode .Image , updatedTags .List ())
791
789
if err != nil {
792
- errs = append (errs , fmt .Errorf ("error pruning image from stream: %v" , err ))
790
+ errs = append (errs , fmt .Errorf ("error removing image %s from stream %s: %v" ,
791
+ imageNode .Image .Name , getName (stream ), err ))
793
792
continue
794
793
}
795
794
@@ -806,7 +805,7 @@ func pruneImages(g graph.Graph, imageNodes []*imagegraph.ImageNode, imagePruner
806
805
807
806
for _ , imageNode := range imageNodes {
808
807
if err := imagePruner .DeleteImage (imageNode .Image ); err != nil {
809
- errs = append (errs , fmt .Errorf ("error pruning image %q: %v" , imageNode .Image .Name , err ))
808
+ errs = append (errs , fmt .Errorf ("error removing image %q: %v" , imageNode .Image .Name , err ))
810
809
}
811
810
}
812
811
@@ -904,7 +903,7 @@ func (p *pruner) Prune(
904
903
glog .V (1 ).Infof ("Using registry: %s" , registryURL )
905
904
906
905
if err := p .registryPinger .ping (registryURL ); err != nil {
907
- return fmt .Errorf ("error communicating with registry: %v" , err )
906
+ return fmt .Errorf ("error communicating with registry %s : %v" , registryURL , err )
908
907
}
909
908
910
909
prunableImageNodes , prunableImageIDs := calculatePrunableImages (p .g , imageNodes )
@@ -1001,9 +1000,9 @@ func pruneBlobs(
1001
1000
errs := []error {}
1002
1001
1003
1002
for _ , cn := range componentNodes {
1004
- glog .V (4 ).Infof ("Pruning registry=%q, blob=%q" , registryURL , cn .Component )
1005
1003
if err := blobPruner .DeleteBlob (registryClient , registryURL , cn .Component ); err != nil {
1006
- errs = append (errs , fmt .Errorf ("error pruning blob %q: %v" , cn .Component , err ))
1004
+ errs = append (errs , fmt .Errorf ("error removing blob from registry %s: blob %q: %v" ,
1005
+ registryURL , cn .Component , err ))
1007
1006
}
1008
1007
}
1009
1008
@@ -1069,7 +1068,7 @@ func NewImageStreamDeleter(streams client.ImageStreamsNamespacer) ImageStreamDel
1069
1068
}
1070
1069
1071
1070
func (p * imageStreamDeleter ) DeleteImageStream (stream * imageapi.ImageStream , image * imageapi.Image , updatedTags []string ) (* imageapi.ImageStream , error ) {
1072
- glog .V (4 ).Infof ("Updating ImageStream %s/%s " , stream . Namespace , stream . Name )
1071
+ glog .V (4 ).Infof ("Updating ImageStream %s" , getName ( stream ) )
1073
1072
glog .V (5 ).Infof ("Updated stream: %#v" , stream )
1074
1073
return p .streams .ImageStreams (stream .Namespace ).UpdateStatus (stream )
1075
1074
}
@@ -1081,14 +1080,16 @@ func deleteFromRegistry(registryClient *http.Client, url string) error {
1081
1080
deleteFunc := func (proto , url string ) error {
1082
1081
req , err := http .NewRequest ("DELETE" , url , nil )
1083
1082
if err != nil {
1084
- glog .Errorf ("Error creating request: %v" , err )
1085
- return fmt .Errorf ("error creating request: %v" , err )
1083
+ return err
1086
1084
}
1087
1085
1088
1086
glog .V (4 ).Infof ("Sending request to registry" )
1089
1087
resp , err := registryClient .Do (req )
1090
1088
if err != nil {
1091
- return fmt .Errorf ("error sending request: %v" , err )
1089
+ if proto != "https" && strings .Contains (err .Error (), "malformed HTTP response" ) {
1090
+ return fmt .Errorf ("%v.\n * Are you trying to connect to a TLS-enabled registry without TLS?" , err )
1091
+ }
1092
+ return err
1092
1093
}
1093
1094
defer resp .Body .Close ()
1094
1095
@@ -1147,7 +1148,7 @@ func NewLayerLinkDeleter() LayerLinkDeleter {
1147
1148
}
1148
1149
1149
1150
func (p * layerLinkDeleter ) DeleteLayerLink (registryClient * http.Client , registryURL , repoName , linkName string ) error {
1150
- glog .V (4 ).Infof ("Pruning registry %q, repo %q, layer link %q" , registryURL , repoName , linkName )
1151
+ glog .V (4 ).Infof ("Deleting layer link from registry %q: repo %q, layer link %q" , registryURL , repoName , linkName )
1151
1152
return deleteFromRegistry (registryClient , fmt .Sprintf ("%s/v2/%s/blobs/%s" , registryURL , repoName , linkName ))
1152
1153
}
1153
1154
@@ -1162,7 +1163,7 @@ func NewBlobDeleter() BlobDeleter {
1162
1163
}
1163
1164
1164
1165
func (p * blobDeleter ) DeleteBlob (registryClient * http.Client , registryURL , blob string ) error {
1165
- glog .V (4 ).Infof ("Pruning registry %q, blob %q" , registryURL , blob )
1166
+ glog .V (4 ).Infof ("Deleting blob from registry %q: blob %q" , registryURL , blob )
1166
1167
return deleteFromRegistry (registryClient , fmt .Sprintf ("%s/admin/blobs/%s" , registryURL , blob ))
1167
1168
}
1168
1169
@@ -1177,6 +1178,15 @@ func NewManifestDeleter() ManifestDeleter {
1177
1178
}
1178
1179
1179
1180
func (p * manifestDeleter ) DeleteManifest (registryClient * http.Client , registryURL , repoName , manifest string ) error {
1180
- glog .V (4 ).Infof ("Pruning manifest for registry %q, repo %q, manifest %q" , registryURL , repoName , manifest )
1181
+ glog .V (4 ).Infof ("Deleting manifest from registry %q: repo %q, manifest %q" , registryURL , repoName , manifest )
1181
1182
return deleteFromRegistry (registryClient , fmt .Sprintf ("%s/v2/%s/manifests/%s" , registryURL , repoName , manifest ))
1182
1183
}
1184
+
1185
+ func getName (obj runtime.Object ) string {
1186
+ accessor , err := kmeta .Accessor (obj )
1187
+ if err != nil {
1188
+ glog .V (4 ).Infof ("Error getting accessor for %#v" , obj )
1189
+ return "<unknown>"
1190
+ }
1191
+ return fmt .Sprintf ("%s/%s" , accessor .GetNamespace (), accessor .GetName ())
1192
+ }
0 commit comments