From de39f499490195151012eb3add7d741dbaa3b5a0 Mon Sep 17 00:00:00 2001 From: "Rostislav M. Georgiev" Date: Thu, 16 Aug 2018 15:54:37 +0300 Subject: [PATCH] kubeadm: use ClusterConfiguration in images.go Replace the unnecessary use of InitConfiguration in images.go with ClusterConfiguration. This changes the interfaces of the following functions: - GetKubeControlPlaneImage - GetEtcdImage - GetAllImages Signed-off-by: Rostislav M. Georgiev --- cmd/kubeadm/app/apis/kubeadm/types.go | 2 +- cmd/kubeadm/app/cmd/config.go | 4 +- cmd/kubeadm/app/cmd/upgrade/apply.go | 2 +- cmd/kubeadm/app/images/images.go | 6 +- cmd/kubeadm/app/images/images_test.go | 106 +++++++----------- cmd/kubeadm/app/phases/addons/proxy/proxy.go | 2 +- .../app/phases/controlplane/manifests.go | 6 +- cmd/kubeadm/app/phases/etcd/local.go | 2 +- cmd/kubeadm/app/phases/upgrade/prepull.go | 4 +- cmd/kubeadm/app/preflight/checks.go | 2 +- 10 files changed, 55 insertions(+), 81 deletions(-) diff --git a/cmd/kubeadm/app/apis/kubeadm/types.go b/cmd/kubeadm/app/apis/kubeadm/types.go index 5701d6aa30d..00fdc75b749 100644 --- a/cmd/kubeadm/app/apis/kubeadm/types.go +++ b/cmd/kubeadm/app/apis/kubeadm/types.go @@ -324,7 +324,7 @@ type JoinConfiguration struct { // It will override location with CI registry name in case user requests special // Kubernetes version from CI build area. // (See: kubeadmconstants.DefaultCIImageRepository) -func (cfg *InitConfiguration) GetControlPlaneImageRepository() string { +func (cfg *ClusterConfiguration) GetControlPlaneImageRepository() string { if cfg.CIImageRepository != "" { return cfg.CIImageRepository } diff --git a/cmd/kubeadm/app/cmd/config.go b/cmd/kubeadm/app/cmd/config.go index d3280e0cb1f..f19222004ba 100644 --- a/cmd/kubeadm/app/cmd/config.go +++ b/cmd/kubeadm/app/cmd/config.go @@ -434,7 +434,7 @@ func NewCmdConfigImagesPull() *cobra.Command { kubeadmutil.CheckErr(err) containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.GetCRISocket()) kubeadmutil.CheckErr(err) - imagesPull := NewImagesPull(containerRuntime, images.GetAllImages(internalcfg)) + imagesPull := NewImagesPull(containerRuntime, images.GetAllImages(&internalcfg.ClusterConfiguration)) kubeadmutil.CheckErr(imagesPull.PullAll()) }, } @@ -516,7 +516,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) + imgs := images.GetAllImages(&i.cfg.ClusterConfiguration) for _, img := range imgs { fmt.Fprintln(out, img) } diff --git a/cmd/kubeadm/app/cmd/upgrade/apply.go b/cmd/kubeadm/app/cmd/upgrade/apply.go index 2c52a7e9067..c4d846346c0 100644 --- a/cmd/kubeadm/app/cmd/upgrade/apply.go +++ b/cmd/kubeadm/app/cmd/upgrade/apply.go @@ -193,7 +193,7 @@ func RunApply(flags *applyFlags) error { // Use a prepuller implementation based on creating DaemonSets // and block until all DaemonSets are ready; then we know for sure that all control plane images are cached locally glog.V(1).Infof("[upgrade/apply] creating prepuller") - prepuller := upgrade.NewDaemonSetPrepuller(upgradeVars.client, upgradeVars.waiter, upgradeVars.cfg) + prepuller := upgrade.NewDaemonSetPrepuller(upgradeVars.client, upgradeVars.waiter, &upgradeVars.cfg.ClusterConfiguration) if err := upgrade.PrepullImagesInParallel(prepuller, flags.imagePullTimeout); err != nil { return fmt.Errorf("[upgrade/prepull] Failed prepulled the images for the control plane components error: %v", err) } diff --git a/cmd/kubeadm/app/images/images.go b/cmd/kubeadm/app/images/images.go index 6bea526ad23..2530b8103d1 100644 --- a/cmd/kubeadm/app/images/images.go +++ b/cmd/kubeadm/app/images/images.go @@ -37,7 +37,7 @@ func GetGenericArchImage(prefix, image, tag string) string { } // GetKubeControlPlaneImage generates and returns the image for the core Kubernetes components or returns the unified control plane image if specified -func GetKubeControlPlaneImage(image string, cfg *kubeadmapi.InitConfiguration) string { +func GetKubeControlPlaneImage(image string, cfg *kubeadmapi.ClusterConfiguration) string { if cfg.UnifiedControlPlaneImage != "" { return cfg.UnifiedControlPlaneImage } @@ -47,7 +47,7 @@ func GetKubeControlPlaneImage(image string, cfg *kubeadmapi.InitConfiguration) s } // GetEtcdImage generates and returns the image for etcd or returns cfg.Etcd.Local.Image if specified -func GetEtcdImage(cfg *kubeadmapi.InitConfiguration) string { +func GetEtcdImage(cfg *kubeadmapi.ClusterConfiguration) string { if cfg.Etcd.Local != nil && cfg.Etcd.Local.Image != "" { return cfg.Etcd.Local.Image } @@ -60,7 +60,7 @@ func GetEtcdImage(cfg *kubeadmapi.InitConfiguration) string { } // GetAllImages returns a list of container images kubeadm expects to use on a control plane node -func GetAllImages(cfg *kubeadmapi.InitConfiguration) []string { +func GetAllImages(cfg *kubeadmapi.ClusterConfiguration) []string { imgs := []string{} imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeAPIServer, cfg)) imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeControllerManager, cfg)) diff --git a/cmd/kubeadm/app/images/images_test.go b/cmd/kubeadm/app/images/images_test.go index e1806044e55..4792ff4b471 100644 --- a/cmd/kubeadm/app/images/images_test.go +++ b/cmd/kubeadm/app/images/images_test.go @@ -49,44 +49,36 @@ func TestGetKubeControlPlaneImage(t *testing.T) { var tests = []struct { image string expected string - cfg *kubeadmapi.InitConfiguration + cfg *kubeadmapi.ClusterConfiguration }{ { expected: "override", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - UnifiedControlPlaneImage: "override", - }, + cfg: &kubeadmapi.ClusterConfiguration{ + UnifiedControlPlaneImage: "override", }, }, { image: constants.KubeAPIServer, expected: GetGenericArchImage(gcrPrefix, "kube-apiserver", expected), - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - ImageRepository: gcrPrefix, - KubernetesVersion: testversion, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + ImageRepository: gcrPrefix, + KubernetesVersion: testversion, }, }, { image: constants.KubeControllerManager, expected: GetGenericArchImage(gcrPrefix, "kube-controller-manager", expected), - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - ImageRepository: gcrPrefix, - KubernetesVersion: testversion, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + ImageRepository: gcrPrefix, + KubernetesVersion: testversion, }, }, { image: constants.KubeScheduler, expected: GetGenericArchImage(gcrPrefix, "kube-scheduler", expected), - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - ImageRepository: gcrPrefix, - KubernetesVersion: testversion, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + ImageRepository: gcrPrefix, + KubernetesVersion: testversion, }, }, } @@ -105,27 +97,23 @@ func TestGetKubeControlPlaneImage(t *testing.T) { func TestGetEtcdImage(t *testing.T) { var tests = []struct { expected string - cfg *kubeadmapi.InitConfiguration + cfg *kubeadmapi.ClusterConfiguration }{ { expected: "override", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - Etcd: kubeadmapi.Etcd{ - Local: &kubeadmapi.LocalEtcd{ - Image: "override", - }, + cfg: &kubeadmapi.ClusterConfiguration{ + Etcd: kubeadmapi.Etcd{ + Local: &kubeadmapi.LocalEtcd{ + Image: "override", }, }, }, }, { expected: GetGenericArchImage(gcrPrefix, "etcd", constants.DefaultEtcdVersion), - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - ImageRepository: gcrPrefix, - KubernetesVersion: testversion, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + ImageRepository: gcrPrefix, + KubernetesVersion: testversion, }, }, } @@ -144,78 +132,64 @@ func TestGetEtcdImage(t *testing.T) { func TestGetAllImages(t *testing.T) { testcases := []struct { name string - cfg *kubeadmapi.InitConfiguration expect string + cfg *kubeadmapi.ClusterConfiguration }{ { name: "defined CIImageRepository", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - CIImageRepository: "test.repo", - }, + cfg: &kubeadmapi.ClusterConfiguration{ + CIImageRepository: "test.repo", }, expect: "test.repo", }, { name: "undefined CIImagerRepository should contain the default image prefix", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - ImageRepository: "real.repo", - }, + cfg: &kubeadmapi.ClusterConfiguration{ + ImageRepository: "real.repo", }, expect: "real.repo", }, { name: "test that etcd is returned when it is not external", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - Etcd: kubeadmapi.Etcd{ - Local: &kubeadmapi.LocalEtcd{}, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + Etcd: kubeadmapi.Etcd{ + Local: &kubeadmapi.LocalEtcd{}, }, }, expect: constants.Etcd, }, { name: "CoreDNS image is returned", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - FeatureGates: map[string]bool{ - "CoreDNS": true, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + FeatureGates: map[string]bool{ + "CoreDNS": true, }, }, expect: constants.CoreDNS, }, { name: "main kube-dns image is returned", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - FeatureGates: map[string]bool{ - "CoreDNS": false, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + FeatureGates: map[string]bool{ + "CoreDNS": false, }, }, expect: "k8s-dns-kube-dns", }, { name: "kube-dns sidecar image is returned", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - FeatureGates: map[string]bool{ - "CoreDNS": false, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + FeatureGates: map[string]bool{ + "CoreDNS": false, }, }, expect: "k8s-dns-sidecar", }, { name: "kube-dns dnsmasq-nanny image is returned", - cfg: &kubeadmapi.InitConfiguration{ - ClusterConfiguration: kubeadmapi.ClusterConfiguration{ - FeatureGates: map[string]bool{ - "CoreDNS": false, - }, + cfg: &kubeadmapi.ClusterConfiguration{ + FeatureGates: map[string]bool{ + "CoreDNS": false, }, }, expect: "k8s-dns-dnsmasq-nanny", diff --git a/cmd/kubeadm/app/phases/addons/proxy/proxy.go b/cmd/kubeadm/app/phases/addons/proxy/proxy.go index f8f70f18937..e11763a124a 100644 --- a/cmd/kubeadm/app/phases/addons/proxy/proxy.go +++ b/cmd/kubeadm/app/phases/addons/proxy/proxy.go @@ -76,7 +76,7 @@ func EnsureProxyAddon(cfg *kubeadmapi.InitConfiguration, client clientset.Interf return fmt.Errorf("error when parsing kube-proxy configmap template: %v", err) } proxyDaemonSetBytes, err = kubeadmutil.ParseTemplate(KubeProxyDaemonSet19, struct{ Image, Arch string }{ - Image: images.GetKubeControlPlaneImage(constants.KubeProxy, cfg), + Image: images.GetKubeControlPlaneImage(constants.KubeProxy, &cfg.ClusterConfiguration), Arch: runtime.GOARCH, }) if err != nil { diff --git a/cmd/kubeadm/app/phases/controlplane/manifests.go b/cmd/kubeadm/app/phases/controlplane/manifests.go index 8ad4ddbbcff..ddbf487b45a 100644 --- a/cmd/kubeadm/app/phases/controlplane/manifests.go +++ b/cmd/kubeadm/app/phases/controlplane/manifests.go @@ -73,7 +73,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.InitConfiguration, k8sVersion *version.Ve staticPodSpecs := map[string]v1.Pod{ kubeadmconstants.KubeAPIServer: staticpodutil.ComponentPod(v1.Container{ Name: kubeadmconstants.KubeAPIServer, - Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeAPIServer, cfg), + Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeAPIServer, &cfg.ClusterConfiguration), ImagePullPolicy: v1.PullIfNotPresent, Command: getAPIServerCommand(cfg), VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeAPIServer)), @@ -83,7 +83,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.InitConfiguration, k8sVersion *version.Ve }, mounts.GetVolumes(kubeadmconstants.KubeAPIServer)), kubeadmconstants.KubeControllerManager: staticpodutil.ComponentPod(v1.Container{ Name: kubeadmconstants.KubeControllerManager, - Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeControllerManager, cfg), + Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeControllerManager, &cfg.ClusterConfiguration), ImagePullPolicy: v1.PullIfNotPresent, Command: getControllerManagerCommand(cfg, k8sVersion), VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeControllerManager)), @@ -93,7 +93,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.InitConfiguration, k8sVersion *version.Ve }, mounts.GetVolumes(kubeadmconstants.KubeControllerManager)), kubeadmconstants.KubeScheduler: staticpodutil.ComponentPod(v1.Container{ Name: kubeadmconstants.KubeScheduler, - Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeScheduler, cfg), + Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeScheduler, &cfg.ClusterConfiguration), ImagePullPolicy: v1.PullIfNotPresent, Command: getSchedulerCommand(cfg), VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeScheduler)), diff --git a/cmd/kubeadm/app/phases/etcd/local.go b/cmd/kubeadm/app/phases/etcd/local.go index a1271fbf713..57ecb6dd19f 100644 --- a/cmd/kubeadm/app/phases/etcd/local.go +++ b/cmd/kubeadm/app/phases/etcd/local.go @@ -60,7 +60,7 @@ func GetEtcdPodSpec(cfg *kubeadmapi.InitConfiguration) v1.Pod { return staticpodutil.ComponentPod(v1.Container{ Name: kubeadmconstants.Etcd, Command: getEtcdCommand(cfg), - Image: images.GetEtcdImage(cfg), + Image: images.GetEtcdImage(&cfg.ClusterConfiguration), ImagePullPolicy: v1.PullIfNotPresent, // Mount the etcd datadir path read-write so etcd can store data in a more persistent manner VolumeMounts: []v1.VolumeMount{ diff --git a/cmd/kubeadm/app/phases/upgrade/prepull.go b/cmd/kubeadm/app/phases/upgrade/prepull.go index 1dabd7daaaa..19eb28f61c9 100644 --- a/cmd/kubeadm/app/phases/upgrade/prepull.go +++ b/cmd/kubeadm/app/phases/upgrade/prepull.go @@ -44,12 +44,12 @@ type Prepuller interface { // DaemonSetPrepuller makes sure the control plane images are available on all masters type DaemonSetPrepuller struct { client clientset.Interface - cfg *kubeadmapi.InitConfiguration + cfg *kubeadmapi.ClusterConfiguration waiter apiclient.Waiter } // NewDaemonSetPrepuller creates a new instance of the DaemonSetPrepuller struct -func NewDaemonSetPrepuller(client clientset.Interface, waiter apiclient.Waiter, cfg *kubeadmapi.InitConfiguration) *DaemonSetPrepuller { +func NewDaemonSetPrepuller(client clientset.Interface, waiter apiclient.Waiter, cfg *kubeadmapi.ClusterConfiguration) *DaemonSetPrepuller { return &DaemonSetPrepuller{ client: client, cfg: cfg, diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index 96f5c52a5c5..0c6cd288f0a 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -1014,7 +1014,7 @@ func RunPullImagesCheck(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigur } checks := []Checker{ - ImagePullCheck{runtime: containerRuntime, imageList: images.GetAllImages(cfg)}, + ImagePullCheck{runtime: containerRuntime, imageList: images.GetAllImages(&cfg.ClusterConfiguration)}, } return RunChecks(checks, os.Stderr, ignorePreflightErrors) }