Adds PauseImage to get pause image names
Signed-off-by: Zhongcheng Lao <Zhongcheng.Lao@microsoft.com>pull/5447/head
parent
29a3d27247
commit
08161722b0
|
@ -552,9 +552,8 @@ func selectImageRepository(mirrorCountry string, k8sVersion string) (bool, strin
|
|||
}
|
||||
|
||||
checkRepository := func(repo string) error {
|
||||
podInfraContainerImage, _ := images.CachedImages(repo, k8sVersion)
|
||||
|
||||
ref, err := name.ParseReference(podInfraContainerImage, name.WeakValidation)
|
||||
pauseImage := images.PauseImage(repo, k8sVersion)
|
||||
ref, err := name.ParseReference(pauseImage, name.WeakValidation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func GetCachedBinaryList(bootstrapper string) []string {
|
|||
func GetCachedImageList(imageRepository string, version string, bootstrapper string) []string {
|
||||
switch bootstrapper {
|
||||
case BootstrapperTypeKubeadm:
|
||||
_, images := images.CachedImages(imageRepository, version)
|
||||
images := images.CachedImages(imageRepository, version)
|
||||
return images
|
||||
default:
|
||||
return []string{}
|
||||
|
|
|
@ -25,19 +25,35 @@ import (
|
|||
minikubeVersion "k8s.io/minikube/pkg/version"
|
||||
)
|
||||
|
||||
// CachedImages gets the images to cache for kubeadm for a version
|
||||
func CachedImages(imageRepository string, kubernetesVersionStr string) (string, []string) {
|
||||
minikubeRepository := imageRepository
|
||||
// getImageRepositories returns either the k8s image registry on GCR or a mirror if specified
|
||||
func getImageRepository(imageRepository string) string {
|
||||
if imageRepository == "" {
|
||||
imageRepository = "k8s.gcr.io"
|
||||
minikubeRepository = "gcr.io/k8s-minikube"
|
||||
}
|
||||
if !strings.HasSuffix(imageRepository, "/") {
|
||||
imageRepository += "/"
|
||||
}
|
||||
|
||||
return imageRepository
|
||||
}
|
||||
|
||||
func getMinikubeRepository(imageRepository string) string {
|
||||
minikubeRepository := imageRepository
|
||||
if minikubeRepository == "" {
|
||||
minikubeRepository = "gcr.io/k8s-minikube"
|
||||
}
|
||||
if !strings.HasSuffix(minikubeRepository, "/") {
|
||||
minikubeRepository += "/"
|
||||
}
|
||||
|
||||
return minikubeRepository
|
||||
}
|
||||
|
||||
// CachedImages gets the images to cache for kubeadm for a version
|
||||
func CachedImages(imageRepository string, kubernetesVersionStr string) []string {
|
||||
imageRepository = getImageRepository(imageRepository)
|
||||
minikubeRepository := getMinikubeRepository(imageRepository)
|
||||
|
||||
v1_16plus := semver.MustParseRange(">=1.16.0")
|
||||
v1_14plus := semver.MustParseRange(">=1.14.0 <1.16.0")
|
||||
v1_13 := semver.MustParseRange(">=1.13.0 <1.14.0")
|
||||
|
@ -67,9 +83,8 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
|
|||
}...)
|
||||
}
|
||||
|
||||
var podInfraContainerImage string
|
||||
podInfraContainerImage := PauseImage(imageRepository, kubernetesVersionStr)
|
||||
if v1_16plus(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause:3.1"
|
||||
images = append(images, []string{
|
||||
podInfraContainerImage,
|
||||
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.13",
|
||||
|
@ -80,7 +95,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
|
|||
}...)
|
||||
|
||||
} else if v1_14plus(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause:3.1"
|
||||
images = append(images, []string{
|
||||
podInfraContainerImage,
|
||||
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.13",
|
||||
|
@ -91,7 +105,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
|
|||
}...)
|
||||
|
||||
} else if v1_13(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
|
||||
images = append(images, []string{
|
||||
podInfraContainerImage,
|
||||
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
|
||||
|
@ -102,7 +115,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
|
|||
}...)
|
||||
|
||||
} else if v1_12(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause:3.1"
|
||||
images = append(images, []string{
|
||||
podInfraContainerImage,
|
||||
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
|
||||
|
@ -113,7 +125,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
|
|||
}...)
|
||||
|
||||
} else if v1_11(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
|
||||
images = append(images, []string{
|
||||
podInfraContainerImage,
|
||||
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
|
||||
|
@ -122,8 +133,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
|
|||
imageRepository + "etcd" + ArchTag(true) + "3.2.18",
|
||||
imageRepository + "coredns:1.1.3",
|
||||
}...)
|
||||
} else {
|
||||
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.0"
|
||||
}
|
||||
|
||||
images = append(images, []string{
|
||||
|
@ -132,7 +141,38 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
|
|||
minikubeRepository + "storage-provisioner" + ArchTag(false) + "v1.8.1",
|
||||
}...)
|
||||
|
||||
return podInfraContainerImage, images
|
||||
return images
|
||||
}
|
||||
|
||||
func PauseImage(imageRepository string, kubernetesVersionStr string) string {
|
||||
imageRepository = getImageRepository(imageRepository)
|
||||
|
||||
v1_16plus := semver.MustParseRange(">=1.16.0")
|
||||
v1_14plus := semver.MustParseRange(">=1.14.0 <1.16.0")
|
||||
v1_13 := semver.MustParseRange(">=1.13.0 <1.14.0")
|
||||
v1_12 := semver.MustParseRange(">=1.12.0 <1.13.0")
|
||||
v1_11 := semver.MustParseRange(">=1.11.0 <1.12.0")
|
||||
|
||||
kubernetesVersion, err := semver.Make(strings.TrimPrefix(kubernetesVersionStr, minikubeVersion.VersionPrefix))
|
||||
if err != nil {
|
||||
glog.Errorln("Error parsing version semver: ", err)
|
||||
}
|
||||
|
||||
var podInfraContainerImage string
|
||||
if v1_16plus(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause:3.1"
|
||||
} else if v1_14plus(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause:3.1"
|
||||
} else if v1_13(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
|
||||
} else if v1_12(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause:3.1"
|
||||
} else if v1_11(kubernetesVersion) {
|
||||
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
|
||||
} else {
|
||||
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.0"
|
||||
}
|
||||
return podInfraContainerImage
|
||||
}
|
||||
|
||||
// ArchTag returns the archtag for images
|
||||
|
|
|
@ -552,9 +552,9 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte,
|
|||
extraOpts["node-ip"] = k8s.NodeIP
|
||||
}
|
||||
|
||||
podInfraContainerImage, _ := images.CachedImages(k8s.ImageRepository, k8s.KubernetesVersion)
|
||||
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && podInfraContainerImage != "" && k8s.ContainerRuntime != constants.RemoteContainerRuntime {
|
||||
extraOpts["pod-infra-container-image"] = podInfraContainerImage
|
||||
pauseImage := images.PauseImage(k8s.ImageRepository, k8s.KubernetesVersion)
|
||||
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && pauseImage != "" && k8s.ContainerRuntime != constants.RemoteContainerRuntime {
|
||||
extraOpts["pod-infra-container-image"] = pauseImage
|
||||
}
|
||||
|
||||
// parses a map of the feature gates for kubelet
|
||||
|
@ -586,7 +586,7 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte,
|
|||
|
||||
// UpdateCluster updates the cluster
|
||||
func (k *Bootstrapper) UpdateCluster(cfg config.KubernetesConfig) error {
|
||||
_, images := images.CachedImages(cfg.ImageRepository, cfg.KubernetesVersion)
|
||||
images := images.CachedImages(cfg.ImageRepository, cfg.KubernetesVersion)
|
||||
if cfg.ShouldLoadCachedImages {
|
||||
if err := machine.LoadImages(k.c, images, constants.ImageCacheDir); err != nil {
|
||||
out.FailureT("Unable to load cached images: {{.error}}", out.V{"error": err})
|
||||
|
|
|
@ -165,8 +165,8 @@ func generateContainerdConfig(cr CommandRunner, k8s config.KubernetesConfig) err
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
podInfraContainerImage, _ := images.CachedImages(k8s.ImageRepository, k8s.KubernetesVersion)
|
||||
opts := struct{ PodInfraContainerImage string }{PodInfraContainerImage: podInfraContainerImage}
|
||||
pauseImage := images.PauseImage(k8s.ImageRepository, k8s.KubernetesVersion)
|
||||
opts := struct{ PodInfraContainerImage string }{PodInfraContainerImage: pauseImage}
|
||||
var b bytes.Buffer
|
||||
if err := t.Execute(&b, opts); err != nil {
|
||||
return err
|
||||
|
|
|
@ -391,8 +391,8 @@ func generateCRIOConfig(cr CommandRunner, k8s config.KubernetesConfig) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
podInfraContainerImage, _ := images.CachedImages(k8s.ImageRepository, k8s.KubernetesVersion)
|
||||
opts := struct{ PodInfraContainerImage string }{PodInfraContainerImage: podInfraContainerImage}
|
||||
pauseImage := images.PauseImage(k8s.ImageRepository, k8s.KubernetesVersion)
|
||||
opts := struct{ PodInfraContainerImage string }{PodInfraContainerImage: pauseImage}
|
||||
var b bytes.Buffer
|
||||
if err := t.Execute(&b, opts); err != nil {
|
||||
return err
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestDownloadOnly(t *testing.T) {
|
|||
|
||||
// None driver does not cache images, so this test will fail
|
||||
if !NoneDriver() {
|
||||
_, imgs := images.CachedImages("", v)
|
||||
imgs := images.CachedImages("", v)
|
||||
for _, img := range imgs {
|
||||
img = strings.Replace(img, ":", "_", 1) // for example kube-scheduler:v1.15.2 --> kube-scheduler_v1.15.2
|
||||
fp := filepath.Join(localpath.MiniPath(), "cache", "images", img)
|
||||
|
|
Loading…
Reference in New Issue