@@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "time"
1313
14+ "github.com/golang/glog"
1415 "github.com/spf13/cobra"
1516
1617 "k8s.io/kubernetes/pkg/kubectl/cmd/templates"
@@ -142,7 +143,7 @@ func parseDockerTimestamp(s string) (time.Time, error) {
142143}
143144
144145func doGarbageCollection (ctx context.Context , client * dockerapi.Client , options * dockerGCConfigCmdOptions , rootDir string ) error {
145- fmt . Println ("gathering disk usage data" )
146+ glog . Infof ("gathering disk usage data" )
146147 capacityBytes , usageBytes , err := getRootDirInfo (rootDir )
147148 if err != nil {
148149 return err
@@ -151,13 +152,13 @@ func doGarbageCollection(ctx context.Context, client *dockerapi.Client, options
151152 highThresholdBytes := capacityBytes * int64 (options .ImageGCHighThresholdPercent ) / 100
152153 lowThresholdBytes := capacityBytes * int64 (options .ImageGCLowThresholdPercent ) / 100
153154 if usageBytes < highThresholdBytes {
154- fmt . Printf ("usage is under high threshold (%vMB < %vMB)\n " , bytesToMB (usageBytes ), bytesToMB (highThresholdBytes ))
155+ glog . Infof ("usage is under high threshold (%vMB < %vMB)" , bytesToMB (usageBytes ), bytesToMB (highThresholdBytes ))
155156 return nil
156157 }
157158
158159 attemptToFreeBytes := usageBytes - lowThresholdBytes
159160 freedBytes := int64 (0 )
160- fmt . Printf ("usage exceeds high threshold (%vMB > %vMB), attempting to free %vMB\n " , bytesToMB (usageBytes ), bytesToMB (highThresholdBytes ), bytesToMB (attemptToFreeBytes ))
161+ glog . Infof ("usage exceeds high threshold (%vMB > %vMB), attempting to free %vMB" , bytesToMB (usageBytes ), bytesToMB (highThresholdBytes ), bytesToMB (attemptToFreeBytes ))
161162
162163 // conatiners
163164 exitedFilter := dockerfilters .NewArgs ()
@@ -169,22 +170,22 @@ func doGarbageCollection(ctx context.Context, client *dockerapi.Client, options
169170 if err != nil {
170171 return err
171172 }
172- fmt . Println ( len ( containers ), " exited containers found" )
173+ glog . Infof ( "%d exited containers found", len ( containers ) )
173174 sort .Sort (oldestContainersFirst (containers ))
174175 for _ , c := range containers {
175176 if freedBytes > attemptToFreeBytes {
176- fmt . Printf ("usage is below low threshold, freed %vMB\n " , bytesToMB (freedBytes ))
177+ glog . Infof ("usage is below low threshold, freed %vMB" , bytesToMB (freedBytes ))
177178 return nil
178179 }
179180 age := time .Now ().Sub (time .Unix (c .Created , 0 ))
180181 if age < options .MinimumGCAge .Duration {
181- fmt . Println ("remaining containers are too young" )
182+ glog . Infof ("remaining containers are too young" )
182183 break
183184 }
184- fmt . Printf ("removing container %v (size: %v, age: %v)\n " , c .ID , c .SizeRw , age )
185+ glog . Infof ("removing container %v (size: %v, age: %v)" , c .ID , c .SizeRw , age )
185186 err := client .ContainerRemove (ctx , c .ID , dockertypes.ContainerRemoveOptions {RemoveVolumes : true })
186187 if err != nil {
187- fmt . Printf ("unable to remove container: %v" , err )
188+ glog . Infof ("unable to remove container: %v" , err )
188189 } else {
189190 freedBytes += c .SizeRw
190191 }
@@ -201,27 +202,27 @@ func doGarbageCollection(ctx context.Context, client *dockerapi.Client, options
201202 sort .Sort (oldestImagesFirst (images ))
202203 for _ , i := range images {
203204 if freedBytes > attemptToFreeBytes {
204- fmt . Printf ("usage is below low threshold, freed %vMB\n " , bytesToMB (freedBytes ))
205+ glog . Infof ("usage is below low threshold, freed %vMB" , bytesToMB (freedBytes ))
205206 return nil
206207 }
207208 // filter openshift infra images
208209 if len (i .RepoTags ) > 0 {
209210 if strings .HasPrefix (i .RepoTags [0 ], "registry.ops.openshift.com/openshift3" ) ||
210211 strings .HasPrefix (i .RepoTags [0 ], "docker.io/openshift" ) {
211- fmt . Println ("skipping infra image" , i .RepoTags [0 ])
212+ glog . Infof ("skipping infra image: %v " , i .RepoTags [0 ])
212213 continue
213214 }
214215 }
215216 // filter young images
216217 age := time .Now ().Sub (time .Unix (i .Created , 0 ))
217218 if age < options .MinimumGCAge .Duration {
218- fmt . Println ("remaining images are too young" )
219+ glog . Infof ("remaining images are too young" )
219220 break
220221 }
221- fmt . Printf ("removing image %v (size: %v, age: %v)\n " , i .ID , i .Size , age )
222+ glog . Infof ("removing image %v (size: %v, age: %v)" , i .ID , i .Size , age )
222223 _ , err := client .ImageRemove (ctx , i .ID , dockertypes.ImageRemoveOptions {PruneChildren : true })
223224 if err != nil {
224- fmt . Printf ("unable to remove image: %v" , err )
225+ glog . Infof ("unable to remove image: %v" , err )
225226 } else {
226227 freedBytes += i .Size
227228 }
@@ -232,8 +233,8 @@ func doGarbageCollection(ctx context.Context, client *dockerapi.Client, options
232233
233234// Run runs the dockergc command.
234235func Run (f * clientcmd.Factory , options * dockerGCConfigCmdOptions , cmd * cobra.Command , args []string ) error {
235- fmt . Println ("docker build garbage collection daemon" )
236- fmt . Printf ("MinimumGCAge: %v, ImageGCHighThresholdPercent: %v, ImageGCLowThresholdPercent: %v\n " , options .MinimumGCAge , options .ImageGCHighThresholdPercent , options .ImageGCLowThresholdPercent )
236+ glog . Infof ("docker build garbage collection daemon" )
237+ glog . Infof ("MinimumGCAge: %v, ImageGCHighThresholdPercent: %v, ImageGCLowThresholdPercent: %v" , options .MinimumGCAge , options .ImageGCHighThresholdPercent , options .ImageGCLowThresholdPercent )
237238 client , err := dockerapi .NewEnvClient ()
238239 if err != nil {
239240 return err
0 commit comments