
Up until now UnifiedControlPlaneImage existed as a string value as part of the ClusterConfiguration. This provided an override for the Kubernetes core component images with a single custom image. It is mostly used to override the control plane images with the hyperkube image. This saves both bandwith and disk space on the control plane nodes. Unfortunately, this specified an entire image string (complete with its prefix, image name and tag). This disables upgrades of setups that use hyperkube. Therefore, to enable upgrades on hyperkube setups and to make configuration more convenient, the UnifiedControlPlaneImage option is replaced with a boolean option, called UseHyperKubeImage. If set to true, this option replaces the image name of any Kubernetes core components with hyperkube, thus allowing for upgrades and respecting the image repository and version, specified in the ClusterConfiguration. Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
89 lines
3.5 KiB
Go
89 lines
3.5 KiB
Go
/*
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package images
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
|
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
|
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
)
|
|
|
|
// GetGenericImage generates and returns a platform agnostic image (backed by manifest list)
|
|
func GetGenericImage(prefix, image, tag string) string {
|
|
return fmt.Sprintf("%s/%s:%s", prefix, image, tag)
|
|
}
|
|
|
|
// 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.ClusterConfiguration) string {
|
|
if cfg.UseHyperKubeImage {
|
|
image = constants.HyperKube
|
|
}
|
|
repoPrefix := cfg.GetControlPlaneImageRepository()
|
|
kubernetesImageTag := kubeadmutil.KubernetesVersionToImageTag(cfg.KubernetesVersion)
|
|
return GetGenericImage(repoPrefix, image, kubernetesImageTag)
|
|
}
|
|
|
|
// GetEtcdImage generates and returns the image for etcd or returns cfg.Etcd.Local.Image if specified
|
|
func GetEtcdImage(cfg *kubeadmapi.ClusterConfiguration) string {
|
|
if cfg.Etcd.Local != nil && cfg.Etcd.Local.Image != "" {
|
|
return cfg.Etcd.Local.Image
|
|
}
|
|
etcdImageTag := constants.DefaultEtcdVersion
|
|
etcdImageVersion, err := constants.EtcdSupportedVersion(cfg.KubernetesVersion)
|
|
if err == nil {
|
|
etcdImageTag = etcdImageVersion.String()
|
|
}
|
|
return GetGenericImage(cfg.ImageRepository, constants.Etcd, etcdImageTag)
|
|
}
|
|
|
|
// GetAllImages returns a list of container images kubeadm expects to use on a control plane node
|
|
func GetAllImages(cfg *kubeadmapi.ClusterConfiguration) []string {
|
|
imgs := []string{}
|
|
|
|
// start with core kubernetes images
|
|
if cfg.UseHyperKubeImage {
|
|
imgs = append(imgs, GetKubeControlPlaneImage(constants.HyperKube, cfg))
|
|
} else {
|
|
imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeAPIServer, cfg))
|
|
imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeControllerManager, cfg))
|
|
imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeScheduler, cfg))
|
|
imgs = append(imgs, GetKubeControlPlaneImage(constants.KubeProxy, cfg))
|
|
}
|
|
|
|
// pause, etcd and kube-dns are not available on the ci image repository so use the default image repository.
|
|
imgs = append(imgs, GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion))
|
|
|
|
// if etcd is not external then add the image as it will be required
|
|
if cfg.Etcd.Local != nil {
|
|
imgs = append(imgs, GetEtcdImage(cfg))
|
|
}
|
|
|
|
// Append the appropriate DNS images
|
|
if features.Enabled(cfg.FeatureGates, features.CoreDNS) {
|
|
imgs = append(imgs, GetGenericImage(cfg.ImageRepository, constants.CoreDNS, constants.CoreDNSVersion))
|
|
} else {
|
|
imgs = append(imgs, GetGenericImage(cfg.ImageRepository, "k8s-dns-kube-dns", constants.KubeDNSVersion))
|
|
imgs = append(imgs, GetGenericImage(cfg.ImageRepository, "k8s-dns-sidecar", constants.KubeDNSVersion))
|
|
imgs = append(imgs, GetGenericImage(cfg.ImageRepository, "k8s-dns-dnsmasq-nanny", constants.KubeDNSVersion))
|
|
}
|
|
|
|
return imgs
|
|
}
|