@@ -294,6 +294,87 @@ func transferAndLoadImage(cr command.Runner, k8s config.KubernetesConfig, src st
294294 return nil
295295}
296296
297+ // pullImages pulls images to the container run time
298+ func pullImages (cruntime cruntime.Manager , images []string ) error {
299+ klog .Infof ("PullImages start: %s" , images )
300+ start := time .Now ()
301+
302+ defer func () {
303+ klog .Infof ("PullImages completed in %s" , time .Since (start ))
304+ }()
305+
306+ var g errgroup.Group
307+
308+ for _ , image := range images {
309+ image := image
310+ g .Go (func () error {
311+ return cruntime .PullImage (image )
312+ })
313+ }
314+ if err := g .Wait (); err != nil {
315+ return errors .Wrap (err , "error pulling images" )
316+ }
317+ klog .Infoln ("Successfully pulled images" )
318+ return nil
319+ }
320+
321+ // PullImages pulls images to all nodes in profile
322+ func PullImages (images []string , profile * config.Profile ) error {
323+ api , err := NewAPIClient ()
324+ if err != nil {
325+ return errors .Wrap (err , "error creating api client" )
326+ }
327+ defer api .Close ()
328+
329+ succeeded := []string {}
330+ failed := []string {}
331+
332+ pName := profile .Name
333+
334+ c , err := config .Load (pName )
335+ if err != nil {
336+ klog .Errorf ("Failed to load profile %q: %v" , pName , err )
337+ return errors .Wrapf (err , "error loading config for profile :%v" , pName )
338+ }
339+
340+ for _ , n := range c .Nodes {
341+ m := config .MachineName (* c , n )
342+
343+ status , err := Status (api , m )
344+ if err != nil {
345+ klog .Warningf ("error getting status for %s: %v" , m , err )
346+ continue
347+ }
348+
349+ if status == state .Running .String () {
350+ h , err := api .Load (m )
351+ if err != nil {
352+ klog .Warningf ("Failed to load machine %q: %v" , m , err )
353+ continue
354+ }
355+ runner , err := CommandRunner (h )
356+ if err != nil {
357+ return err
358+ }
359+ cruntime , err := cruntime .New (cruntime.Config {Type : c .KubernetesConfig .ContainerRuntime , Runner : runner })
360+ if err != nil {
361+ return errors .Wrap (err , "error creating container runtime" )
362+ }
363+ err = pullImages (cruntime , images )
364+ if err != nil {
365+ failed = append (failed , m )
366+ klog .Warningf ("Failed to pull images for profile %s %v" , pName , err .Error ())
367+ continue
368+ }
369+ succeeded = append (succeeded , m )
370+ }
371+ }
372+
373+ klog .Infof ("succeeded pulling to: %s" , strings .Join (succeeded , " " ))
374+ klog .Infof ("failed pulling to: %s" , strings .Join (failed , " " ))
375+ return nil
376+ }
377+
297378// removeImages removes images from the container run time
298379func removeImages (cruntime cruntime.Manager , images []string ) error {
299380 klog .Infof ("RemovingImages start: %s" , images )
@@ -318,6 +399,7 @@ func removeImages(cruntime cruntime.Manager, images []string) error {
318399 return nil
319400}
320401
402+ // RemoveImages removes images from all nodes in profile
321403func RemoveImages (images []string , profile * config.Profile ) error {
322404 api , err := NewAPIClient ()
323405 if err != nil {
@@ -374,6 +456,7 @@ func RemoveImages(images []string, profile *config.Profile) error {
374456 return nil
375457}
376458
459+ // ListImages lists images on all nodes in profile
377460func ListImages (profile * config.Profile ) error {
378461 api , err := NewAPIClient ()
379462 if err != nil {
0 commit comments