diff --git a/cmd/kubeadm/app/cmd/config.go b/cmd/kubeadm/app/cmd/config.go index eb49713fa3..ec4d705c58 100644 --- a/cmd/kubeadm/app/cmd/config.go +++ b/cmd/kubeadm/app/cmd/config.go @@ -423,8 +423,7 @@ func NewCmdConfigImagesPull() *cobra.Command { kubeadmutil.CheckErr(err) containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.NodeRegistration.CRISocket) kubeadmutil.CheckErr(err) - imagesPull := NewImagesPull(containerRuntime, images.GetAllImages(&internalcfg.ClusterConfiguration)) - kubeadmutil.CheckErr(imagesPull.PullAll()) + PullControlPlaneImages(containerRuntime, &internalcfg.ClusterConfiguration) }, } AddImagesCommonConfigFlags(cmd.PersistentFlags(), externalcfg, &cfgPath, &featureGatesString) @@ -447,10 +446,11 @@ func NewImagesPull(runtime utilruntime.ContainerRuntime, images []string) *Image } } -// PullAll pulls all images that the ImagesPull knows about -func (ip *ImagesPull) PullAll() error { - for _, image := range ip.images { - if err := ip.runtime.PullImage(image); err != nil { +// PullControlPlaneImages pulls all images that the ImagesPull knows about +func PullControlPlaneImages(runtime utilruntime.ContainerRuntime, cfg *kubeadmapi.ClusterConfiguration) error { + images := images.GetControlPlaneImages(cfg) + for _, image := range images { + if err := runtime.PullImage(image); err != nil { return errors.Wrapf(err, "failed to pull image %q", image) } fmt.Printf("[config/images] Pulled %s\n", image) @@ -505,7 +505,7 @@ type ImagesList struct { // Run runs the images command and writes the result to the io.Writer passed in func (i *ImagesList) Run(out io.Writer) error { - imgs := images.GetAllImages(&i.cfg.ClusterConfiguration) + imgs := images.GetControlPlaneImages(&i.cfg.ClusterConfiguration) for _, img := range imgs { fmt.Fprintln(out, img) } diff --git a/cmd/kubeadm/app/cmd/config_test.go b/cmd/kubeadm/app/cmd/config_test.go index c256069f30..75798e579e 100644 --- a/cmd/kubeadm/app/cmd/config_test.go +++ b/cmd/kubeadm/app/cmd/config_test.go @@ -244,11 +244,11 @@ func TestImagesPull(t *testing.T) { } images := []string{"a", "b", "c", "d", "a"} - ip := NewImagesPull(containerRuntime, images) - - err = ip.PullAll() - if err != nil { - t.Fatalf("expected nil but found %v", err) + for _, image := range images { + if err := containerRuntime.PullImage(image); err != nil { + t.Fatalf("expected nil but found %v", err) + } + fmt.Printf("[config/images] Pulled %s\n", image) } if fcmd.CombinedOutputCalls != len(images) { diff --git a/cmd/kubeadm/app/images/images.go b/cmd/kubeadm/app/images/images.go index c988fe0f28..4cbd0e0b31 100644 --- a/cmd/kubeadm/app/images/images.go +++ b/cmd/kubeadm/app/images/images.go @@ -85,8 +85,8 @@ func GetPauseImage(cfg *kubeadmapi.ClusterConfiguration) string { return GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion) } -// GetAllImages returns a list of container images kubeadm expects to use on a control plane node -func GetAllImages(cfg *kubeadmapi.ClusterConfiguration) []string { +// GetControlPlaneImages returns a list of container images kubeadm expects to use on a control plane node +func GetControlPlaneImages(cfg *kubeadmapi.ClusterConfiguration) []string { imgs := []string{} // start with core kubernetes images diff --git a/cmd/kubeadm/app/images/images_test.go b/cmd/kubeadm/app/images/images_test.go index d72ff45854..4714db8f86 100644 --- a/cmd/kubeadm/app/images/images_test.go +++ b/cmd/kubeadm/app/images/images_test.go @@ -254,7 +254,7 @@ func TestGetAllImages(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - imgs := GetAllImages(tc.cfg) + imgs := GetControlPlaneImages(tc.cfg) for _, img := range imgs { if strings.Contains(img, tc.expect) { return diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index baddbe9fb2..9a13eea457 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -1074,7 +1074,7 @@ func RunPullImagesCheck(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigur } checks := []Checker{ - ImagePullCheck{runtime: containerRuntime, imageList: images.GetAllImages(&cfg.ClusterConfiguration)}, + ImagePullCheck{runtime: containerRuntime, imageList: images.GetControlPlaneImages(&cfg.ClusterConfiguration)}, } return RunChecks(checks, os.Stderr, ignorePreflightErrors) }