Merge pull request #67503 from rosti/kubeadm_clusterconfig_images

Automatic merge from submit-queue (batch tested with PRs 67776, 67503, 67679, 67786, 67830). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

 kubeadm: use ClusterConfiguration in images.go

**What this PR does / why we need it**:

This PR is the first in a series, targeting the replacement of InitConfiguration with ClusterConfiguration, when the former is not needed. Please, review only the last commit.

Replace the unnecessary use of InitConfiguration in images.go with ClusterConfiguration. This changes the interfaces of the following functions:

- GetKubeControlPlaneImage
- GetEtcdImage
- GetAllImages

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
refs kubernetes/kubeadm#963

**Special notes for your reviewer**:

/cc @kubernetes/sig-cluster-lifecycle-pr-reviews
/area kubeadm
/kind enhancement
/assign @luxas
/assign @timothysc
/assign @fabriziopandini

Depends on:
- [X] #67441

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-08-24 16:50:00 -07:00 committed by GitHub
commit de80c824bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 81 deletions

View File

@ -324,7 +324,7 @@ type JoinConfiguration struct {
// It will override location with CI registry name in case user requests special // It will override location with CI registry name in case user requests special
// Kubernetes version from CI build area. // Kubernetes version from CI build area.
// (See: kubeadmconstants.DefaultCIImageRepository) // (See: kubeadmconstants.DefaultCIImageRepository)
func (cfg *InitConfiguration) GetControlPlaneImageRepository() string { func (cfg *ClusterConfiguration) GetControlPlaneImageRepository() string {
if cfg.CIImageRepository != "" { if cfg.CIImageRepository != "" {
return cfg.CIImageRepository return cfg.CIImageRepository
} }

View File

@ -434,7 +434,7 @@ func NewCmdConfigImagesPull() *cobra.Command {
kubeadmutil.CheckErr(err) kubeadmutil.CheckErr(err)
containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.GetCRISocket()) containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.GetCRISocket())
kubeadmutil.CheckErr(err) kubeadmutil.CheckErr(err)
imagesPull := NewImagesPull(containerRuntime, images.GetAllImages(internalcfg)) imagesPull := NewImagesPull(containerRuntime, images.GetAllImages(&internalcfg.ClusterConfiguration))
kubeadmutil.CheckErr(imagesPull.PullAll()) 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 // Run runs the images command and writes the result to the io.Writer passed in
func (i *ImagesList) Run(out io.Writer) error { func (i *ImagesList) Run(out io.Writer) error {
imgs := images.GetAllImages(i.cfg) imgs := images.GetAllImages(&i.cfg.ClusterConfiguration)
for _, img := range imgs { for _, img := range imgs {
fmt.Fprintln(out, img) fmt.Fprintln(out, img)
} }

View File

@ -193,7 +193,7 @@ func RunApply(flags *applyFlags) error {
// Use a prepuller implementation based on creating DaemonSets // 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 // 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") 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 { 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) return fmt.Errorf("[upgrade/prepull] Failed prepulled the images for the control plane components error: %v", err)
} }

View File

@ -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 // 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 != "" { if cfg.UnifiedControlPlaneImage != "" {
return 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 // 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 != "" { if cfg.Etcd.Local != nil && cfg.Etcd.Local.Image != "" {
return 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 // 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 := []string{}
imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeAPIServer, cfg)) imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeAPIServer, cfg))
imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeControllerManager, cfg)) imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeControllerManager, cfg))

View File

@ -49,44 +49,36 @@ func TestGetKubeControlPlaneImage(t *testing.T) {
var tests = []struct { var tests = []struct {
image string image string
expected string expected string
cfg *kubeadmapi.InitConfiguration cfg *kubeadmapi.ClusterConfiguration
}{ }{
{ {
expected: "override", expected: "override",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ UnifiedControlPlaneImage: "override",
UnifiedControlPlaneImage: "override",
},
}, },
}, },
{ {
image: constants.KubeAPIServer, image: constants.KubeAPIServer,
expected: GetGenericArchImage(gcrPrefix, "kube-apiserver", expected), expected: GetGenericArchImage(gcrPrefix, "kube-apiserver", expected),
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ImageRepository: gcrPrefix,
ImageRepository: gcrPrefix, KubernetesVersion: testversion,
KubernetesVersion: testversion,
},
}, },
}, },
{ {
image: constants.KubeControllerManager, image: constants.KubeControllerManager,
expected: GetGenericArchImage(gcrPrefix, "kube-controller-manager", expected), expected: GetGenericArchImage(gcrPrefix, "kube-controller-manager", expected),
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ImageRepository: gcrPrefix,
ImageRepository: gcrPrefix, KubernetesVersion: testversion,
KubernetesVersion: testversion,
},
}, },
}, },
{ {
image: constants.KubeScheduler, image: constants.KubeScheduler,
expected: GetGenericArchImage(gcrPrefix, "kube-scheduler", expected), expected: GetGenericArchImage(gcrPrefix, "kube-scheduler", expected),
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ImageRepository: gcrPrefix,
ImageRepository: gcrPrefix, KubernetesVersion: testversion,
KubernetesVersion: testversion,
},
}, },
}, },
} }
@ -105,27 +97,23 @@ func TestGetKubeControlPlaneImage(t *testing.T) {
func TestGetEtcdImage(t *testing.T) { func TestGetEtcdImage(t *testing.T) {
var tests = []struct { var tests = []struct {
expected string expected string
cfg *kubeadmapi.InitConfiguration cfg *kubeadmapi.ClusterConfiguration
}{ }{
{ {
expected: "override", expected: "override",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ Etcd: kubeadmapi.Etcd{
Etcd: kubeadmapi.Etcd{ Local: &kubeadmapi.LocalEtcd{
Local: &kubeadmapi.LocalEtcd{ Image: "override",
Image: "override",
},
}, },
}, },
}, },
}, },
{ {
expected: GetGenericArchImage(gcrPrefix, "etcd", constants.DefaultEtcdVersion), expected: GetGenericArchImage(gcrPrefix, "etcd", constants.DefaultEtcdVersion),
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ImageRepository: gcrPrefix,
ImageRepository: gcrPrefix, KubernetesVersion: testversion,
KubernetesVersion: testversion,
},
}, },
}, },
} }
@ -144,78 +132,64 @@ func TestGetEtcdImage(t *testing.T) {
func TestGetAllImages(t *testing.T) { func TestGetAllImages(t *testing.T) {
testcases := []struct { testcases := []struct {
name string name string
cfg *kubeadmapi.InitConfiguration
expect string expect string
cfg *kubeadmapi.ClusterConfiguration
}{ }{
{ {
name: "defined CIImageRepository", name: "defined CIImageRepository",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ CIImageRepository: "test.repo",
CIImageRepository: "test.repo",
},
}, },
expect: "test.repo", expect: "test.repo",
}, },
{ {
name: "undefined CIImagerRepository should contain the default image prefix", name: "undefined CIImagerRepository should contain the default image prefix",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ImageRepository: "real.repo",
ImageRepository: "real.repo",
},
}, },
expect: "real.repo", expect: "real.repo",
}, },
{ {
name: "test that etcd is returned when it is not external", name: "test that etcd is returned when it is not external",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ Etcd: kubeadmapi.Etcd{
Etcd: kubeadmapi.Etcd{ Local: &kubeadmapi.LocalEtcd{},
Local: &kubeadmapi.LocalEtcd{},
},
}, },
}, },
expect: constants.Etcd, expect: constants.Etcd,
}, },
{ {
name: "CoreDNS image is returned", name: "CoreDNS image is returned",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ FeatureGates: map[string]bool{
FeatureGates: map[string]bool{ "CoreDNS": true,
"CoreDNS": true,
},
}, },
}, },
expect: constants.CoreDNS, expect: constants.CoreDNS,
}, },
{ {
name: "main kube-dns image is returned", name: "main kube-dns image is returned",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ FeatureGates: map[string]bool{
FeatureGates: map[string]bool{ "CoreDNS": false,
"CoreDNS": false,
},
}, },
}, },
expect: "k8s-dns-kube-dns", expect: "k8s-dns-kube-dns",
}, },
{ {
name: "kube-dns sidecar image is returned", name: "kube-dns sidecar image is returned",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ FeatureGates: map[string]bool{
FeatureGates: map[string]bool{ "CoreDNS": false,
"CoreDNS": false,
},
}, },
}, },
expect: "k8s-dns-sidecar", expect: "k8s-dns-sidecar",
}, },
{ {
name: "kube-dns dnsmasq-nanny image is returned", name: "kube-dns dnsmasq-nanny image is returned",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.ClusterConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ FeatureGates: map[string]bool{
FeatureGates: map[string]bool{ "CoreDNS": false,
"CoreDNS": false,
},
}, },
}, },
expect: "k8s-dns-dnsmasq-nanny", expect: "k8s-dns-dnsmasq-nanny",

View File

@ -76,7 +76,7 @@ func EnsureProxyAddon(cfg *kubeadmapi.InitConfiguration, client clientset.Interf
return fmt.Errorf("error when parsing kube-proxy configmap template: %v", err) return fmt.Errorf("error when parsing kube-proxy configmap template: %v", err)
} }
proxyDaemonSetBytes, err = kubeadmutil.ParseTemplate(KubeProxyDaemonSet19, struct{ Image, Arch string }{ 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, Arch: runtime.GOARCH,
}) })
if err != nil { if err != nil {

View File

@ -73,7 +73,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.InitConfiguration, k8sVersion *version.Ve
staticPodSpecs := map[string]v1.Pod{ staticPodSpecs := map[string]v1.Pod{
kubeadmconstants.KubeAPIServer: staticpodutil.ComponentPod(v1.Container{ kubeadmconstants.KubeAPIServer: staticpodutil.ComponentPod(v1.Container{
Name: kubeadmconstants.KubeAPIServer, Name: kubeadmconstants.KubeAPIServer,
Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeAPIServer, cfg), Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeAPIServer, &cfg.ClusterConfiguration),
ImagePullPolicy: v1.PullIfNotPresent, ImagePullPolicy: v1.PullIfNotPresent,
Command: getAPIServerCommand(cfg), Command: getAPIServerCommand(cfg),
VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeAPIServer)), VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeAPIServer)),
@ -83,7 +83,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.InitConfiguration, k8sVersion *version.Ve
}, mounts.GetVolumes(kubeadmconstants.KubeAPIServer)), }, mounts.GetVolumes(kubeadmconstants.KubeAPIServer)),
kubeadmconstants.KubeControllerManager: staticpodutil.ComponentPod(v1.Container{ kubeadmconstants.KubeControllerManager: staticpodutil.ComponentPod(v1.Container{
Name: kubeadmconstants.KubeControllerManager, Name: kubeadmconstants.KubeControllerManager,
Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeControllerManager, cfg), Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeControllerManager, &cfg.ClusterConfiguration),
ImagePullPolicy: v1.PullIfNotPresent, ImagePullPolicy: v1.PullIfNotPresent,
Command: getControllerManagerCommand(cfg, k8sVersion), Command: getControllerManagerCommand(cfg, k8sVersion),
VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeControllerManager)), VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeControllerManager)),
@ -93,7 +93,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.InitConfiguration, k8sVersion *version.Ve
}, mounts.GetVolumes(kubeadmconstants.KubeControllerManager)), }, mounts.GetVolumes(kubeadmconstants.KubeControllerManager)),
kubeadmconstants.KubeScheduler: staticpodutil.ComponentPod(v1.Container{ kubeadmconstants.KubeScheduler: staticpodutil.ComponentPod(v1.Container{
Name: kubeadmconstants.KubeScheduler, Name: kubeadmconstants.KubeScheduler,
Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeScheduler, cfg), Image: images.GetKubeControlPlaneImage(kubeadmconstants.KubeScheduler, &cfg.ClusterConfiguration),
ImagePullPolicy: v1.PullIfNotPresent, ImagePullPolicy: v1.PullIfNotPresent,
Command: getSchedulerCommand(cfg), Command: getSchedulerCommand(cfg),
VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeScheduler)), VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeScheduler)),

View File

@ -60,7 +60,7 @@ func GetEtcdPodSpec(cfg *kubeadmapi.InitConfiguration) v1.Pod {
return staticpodutil.ComponentPod(v1.Container{ return staticpodutil.ComponentPod(v1.Container{
Name: kubeadmconstants.Etcd, Name: kubeadmconstants.Etcd,
Command: getEtcdCommand(cfg), Command: getEtcdCommand(cfg),
Image: images.GetEtcdImage(cfg), Image: images.GetEtcdImage(&cfg.ClusterConfiguration),
ImagePullPolicy: v1.PullIfNotPresent, ImagePullPolicy: v1.PullIfNotPresent,
// Mount the etcd datadir path read-write so etcd can store data in a more persistent manner // Mount the etcd datadir path read-write so etcd can store data in a more persistent manner
VolumeMounts: []v1.VolumeMount{ VolumeMounts: []v1.VolumeMount{

View File

@ -44,12 +44,12 @@ type Prepuller interface {
// DaemonSetPrepuller makes sure the control plane images are available on all masters // DaemonSetPrepuller makes sure the control plane images are available on all masters
type DaemonSetPrepuller struct { type DaemonSetPrepuller struct {
client clientset.Interface client clientset.Interface
cfg *kubeadmapi.InitConfiguration cfg *kubeadmapi.ClusterConfiguration
waiter apiclient.Waiter waiter apiclient.Waiter
} }
// NewDaemonSetPrepuller creates a new instance of the DaemonSetPrepuller struct // 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{ return &DaemonSetPrepuller{
client: client, client: client,
cfg: cfg, cfg: cfg,

View File

@ -1014,7 +1014,7 @@ func RunPullImagesCheck(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigur
} }
checks := []Checker{ checks := []Checker{
ImagePullCheck{runtime: containerRuntime, imageList: images.GetAllImages(cfg)}, ImagePullCheck{runtime: containerRuntime, imageList: images.GetAllImages(&cfg.ClusterConfiguration)},
} }
return RunChecks(checks, os.Stderr, ignorePreflightErrors) return RunChecks(checks, os.Stderr, ignorePreflightErrors)
} }