提交 8b7aaba6 编写于 作者: T Thomas Stromberg

Sync correct Kubernetes versions from kubeadm constants

上级 434648c6
......@@ -673,7 +673,7 @@ func selectImageRepository(mirrorCountry string, k8sVersion string) (bool, strin
}
checkRepository := func(repo string) error {
pauseImage := images.PauseImage(repo, k8sVersion)
pauseImage := images.Pause(repo)
ref, err := name.ParseReference(pauseImage, name.WeakValidation)
if err != nil {
return err
......@@ -1108,7 +1108,7 @@ func tryRegistry(r command.Runner) {
repo := viper.GetString(imageRepository)
if repo == "" {
repo = images.DefaultImageRepo
repo = images.DefaultKubernetesRepo
}
opts = append(opts, fmt.Sprintf("https://%s/", repo))
......
......@@ -64,12 +64,11 @@ func GetCachedBinaryList(bootstrapper string) []string {
}
// GetCachedImageList returns the list of images for a version
func GetCachedImageList(imageRepository string, version string, bootstrapper string) []string {
func GetCachedImageList(imageRepository string, version string, bootstrapper string) ([]string, error) {
switch bootstrapper {
case BootstrapperTypeKubeadm:
images := images.CachedImages(imageRepository, version)
return images
return images.Kubeadm(imageRepository, version)
default:
return []string{}
return []string{}, nil
}
}
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Copyright 2019 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -14,188 +14,63 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Package images implements helpers for getting image names
package images
import (
"path"
"runtime"
"strings"
"github.com/blang/semver"
"github.com/golang/glog"
minikubeVersion "k8s.io/minikube/pkg/version"
)
const (
// DefaultImageRepo is the default repository for images
DefaultImageRepo = "k8s.gcr.io"
// DefaultMinikubeRepo is the default repository for minikube
DefaultMinikubeRepo = "gcr.io/k8s-minikube"
)
// getImageRepositories returns either the k8s image registry on GCR or a mirror if specified
func getImageRepository(imageRepository string) string {
if imageRepository == "" {
imageRepository = DefaultImageRepo
}
if !strings.HasSuffix(imageRepository, "/") {
imageRepository += "/"
// ArchTag returns a CPU architecture suffix for images
func ArchTag(hasTag bool) string {
if runtime.GOARCH == "amd64" && !hasTag {
return ":"
}
return imageRepository
return "-" + runtime.GOARCH + ":"
}
// getMinikubeRepository returns either the minikube image registry on GCR or a mirror if specified
func getMinikubeRepository(imageRepository string) string {
minikubeRepository := imageRepository
if minikubeRepository == "" {
minikubeRepository = DefaultMinikubeRepo
}
if !strings.HasSuffix(minikubeRepository, "/") {
minikubeRepository += "/"
// Auxiliary returns images that are helpful for running minikube
func Auxiliary(mirror string) []string {
return []string{
addonManager(mirror),
storageProvisioner(mirror),
dashboardFrontend(mirror),
dashboardMetrics(mirror),
}
return minikubeRepository
}
// CachedImages gets the images to cache for kubeadm for a version
func CachedImages(imageRepositoryStr string, kubernetesVersionStr string) []string {
imageRepository := getImageRepository(imageRepositoryStr)
minikubeRepository := getMinikubeRepository(imageRepositoryStr)
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")
v1_12plus := semver.MustParseRange(">=1.12.0")
kubernetesVersion, err := semver.Make(strings.TrimPrefix(kubernetesVersionStr, minikubeVersion.VersionPrefix))
if err != nil {
glog.Errorln("Error parsing version semver: ", err)
}
var images []string
if v1_12plus(kubernetesVersion) {
images = append(images, []string{
imageRepository + "kube-proxy" + ArchTag(false) + kubernetesVersionStr,
imageRepository + "kube-scheduler" + ArchTag(false) + kubernetesVersionStr,
imageRepository + "kube-controller-manager" + ArchTag(false) + kubernetesVersionStr,
imageRepository + "kube-apiserver" + ArchTag(false) + kubernetesVersionStr,
}...)
} else {
images = append(images, []string{
imageRepository + "kube-proxy" + ArchTag(true) + kubernetesVersionStr,
imageRepository + "kube-scheduler" + ArchTag(true) + kubernetesVersionStr,
imageRepository + "kube-controller-manager" + ArchTag(true) + kubernetesVersionStr,
imageRepository + "kube-apiserver" + ArchTag(true) + kubernetesVersionStr,
}...)
}
podInfraContainerImage := PauseImage(imageRepository, kubernetesVersionStr)
if v1_16plus(kubernetesVersion) {
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.13",
imageRepository + "k8s-dns-dnsmasq-nanny" + ArchTag(true) + "1.14.13",
imageRepository + "k8s-dns-sidecar" + ArchTag(true) + "1.14.13",
imageRepository + "etcd" + ArchTag(false) + "3.3.15-0",
imageRepository + "coredns" + ArchTag(false) + "1.6.2",
}...)
} else if v1_14plus(kubernetesVersion) {
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.13",
imageRepository + "k8s-dns-dnsmasq-nanny" + ArchTag(true) + "1.14.13",
imageRepository + "k8s-dns-sidecar" + ArchTag(true) + "1.14.13",
imageRepository + "etcd" + ArchTag(false) + "3.3.10",
imageRepository + "coredns" + ArchTag(false) + "1.3.1",
}...)
} else if v1_13(kubernetesVersion) {
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
imageRepository + "k8s-dns-dnsmasq-nanny" + ArchTag(true) + "1.14.8",
imageRepository + "k8s-dns-sidecar" + ArchTag(true) + "1.14.8",
imageRepository + "etcd" + ArchTag(false) + "3.2.24",
imageRepository + "coredns:1.2.6",
}...)
} else if v1_12(kubernetesVersion) {
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
imageRepository + "k8s-dns-dnsmasq-nanny" + ArchTag(true) + "1.14.8",
imageRepository + "k8s-dns-sidecar" + ArchTag(true) + "1.14.8",
imageRepository + "etcd" + ArchTag(false) + "3.2.24",
imageRepository + "coredns:1.2.2",
}...)
} else if v1_11(kubernetesVersion) {
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
imageRepository + "k8s-dns-dnsmasq-nanny" + ArchTag(true) + "1.14.8",
imageRepository + "k8s-dns-sidecar" + ArchTag(true) + "1.14.8",
imageRepository + "etcd" + ArchTag(true) + "3.2.18",
imageRepository + "coredns:1.1.3",
}...)
}
images = append(images, []string{
// This must match deploy/addons/dashboard/dashboard-dp.yaml
"kubernetesui/dashboard:v2.0.0-beta8",
imageRepository + "kube-addon-manager" + ArchTag(false) + "v9.0",
minikubeRepository + "storage-provisioner" + ArchTag(false) + "v1.8.1",
}...)
return images
// Pause returns the image name for the pause image
func Pause(mirror string) string {
// Should match `PauseVersion` in:
// https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants.go
return path.Join(KubernetesRepo(mirror), "pause"+ArchTag(false)+"3.1")
}
// PauseImage returns the image name for pause image (for pod infra)
func PauseImage(imageRepositoryStr string, kubernetesVersionStr string) string {
imageRepository := getImageRepository(imageRepositoryStr)
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
switch {
case v1_16plus(kubernetesVersion):
podInfraContainerImage = imageRepository + "pause:3.1"
case v1_14plus(kubernetesVersion):
podInfraContainerImage = imageRepository + "pause:3.1"
case v1_13(kubernetesVersion):
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
case v1_12(kubernetesVersion):
podInfraContainerImage = imageRepository + "pause:3.1"
// storageProvisioner returns the minikube storage provisioner image
func storageProvisioner(mirror string) string {
return path.Join(minikubeRepo(mirror), "storage-provisioner"+ArchTag(false)+"v1.8.1")
}
case v1_11(kubernetesVersion):
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
// addonManager returns the Kubernetes addon manager image
func addonManager(mirror string) string {
return path.Join(KubernetesRepo(mirror), "kube-addon-manager"+ArchTag(false)+"v9.0.2")
}
default:
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.0"
// dashboardFrontend returns the image used for the dashboard frontend
func dashboardFrontend(repo string) string {
if repo == "" {
repo = "kubernetesui"
}
return podInfraContainerImage
// See 'kubernetes-dashboard' in deploy/addons/dashboard/dashboard-dp.yaml
return path.Join(repo, "dashboard:v2.0.0-beta8")
}
// ArchTag returns the archtag for images
func ArchTag(hasTag bool) string {
if runtime.GOARCH == "amd64" && !hasTag {
return ":"
// dashboardMetrics returns the image used for the dashboard metrics scraper
func dashboardMetrics(repo string) string {
if repo == "" {
repo = "kubernetesui"
}
return "-" + runtime.GOARCH + ":"
// See 'dashboard-metrics-scraper' in deploy/addons/dashboard/dashboard-dp.yaml
return path.Join(repo, "metrics-scraper:v1.0.2")
}
/*
Copyright 2019 The Kubernetes Authors All rights reserved.
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
// DefaultKubernetesRepo is the default Kubernetes repository
const DefaultKubernetesRepo = "k8s.gcr.io"
// KubernetesRepo returns the official Kubernetes repository, or an alternate
func KubernetesRepo(mirror string) string {
if mirror != "" {
return mirror
}
return DefaultKubernetesRepo
}
// minikubeRepo returns the official minikube repository, or an alternate
func minikubeRepo(mirror string) string {
if mirror != "" {
return mirror
}
return "gcr.io/k8s-minikube"
}
......@@ -596,7 +596,7 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte,
extraOpts["node-ip"] = k8s.NodeIP
}
pauseImage := images.PauseImage(k8s.ImageRepository, k8s.KubernetesVersion)
pauseImage := images.Pause(k8s.ImageRepository)
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && pauseImage != "" && k8s.ContainerRuntime != remoteContainerRuntime {
extraOpts["pod-infra-container-image"] = pauseImage
}
......@@ -630,7 +630,10 @@ 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, err := images.Kubeadm(cfg.ImageRepository, cfg.KubernetesVersion)
if err != nil {
return errors.Wrap(err, "kubeadm images")
}
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})
......
......@@ -175,7 +175,7 @@ func generateContainerdConfig(cr CommandRunner, imageRepository string, k8sVersi
if err != nil {
return err
}
pauseImage := images.PauseImage(imageRepository, k8sVersion)
pauseImage := images.Pause(imageRepository)
opts := struct{ PodInfraContainerImage string }{PodInfraContainerImage: pauseImage}
var b bytes.Buffer
if err := t.Execute(&b, opts); err != nil {
......
......@@ -413,7 +413,7 @@ func generateCRIOConfig(cr CommandRunner, imageRepository string, k8sVersion str
if err != nil {
return err
}
pauseImage := images.PauseImage(imageRepository, k8sVersion)
pauseImage := images.Pause(imageRepository)
opts := struct{ PodInfraContainerImage string }{PodInfraContainerImage: pauseImage}
var b bytes.Buffer
if err := t.Execute(&b, opts); err != nil {
......
......@@ -55,7 +55,10 @@ var loadImageLock sync.Mutex
// CacheImagesForBootstrapper will cache images for a bootstrapper
func CacheImagesForBootstrapper(imageRepository string, version string, clusterBootstrapper string) error {
images := bootstrapper.GetCachedImageList(imageRepository, version, clusterBootstrapper)
images, err := bootstrapper.GetCachedImageList(imageRepository, version, clusterBootstrapper)
if err != nil {
return errors.Wrap(err, "cached images list")
}
if err := CacheImages(images, constants.ImageCacheDir); err != nil {
return errors.Wrapf(err, "Caching images for %s", clusterBootstrapper)
......
......@@ -67,7 +67,11 @@ func TestDownloadOnly(t *testing.T) {
t.Errorf("%s failed: %v", args, err)
}
imgs := images.CachedImages("", v)
imgs, err := images.Kubeadm("", v)
if err != nil {
t.Errorf("kubeadm images: %v", 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册