Skip to content

Update code to cache correct images for different k8s versions #2849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 59 additions & 21 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/blang/semver"
"github.com/golang/glog"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"k8s.io/kubernetes/pkg/version"
Expand Down Expand Up @@ -215,33 +218,68 @@ var LocalkubeCachedImages = []string{
"gcr.io/k8s-minikube/storage-provisioner:v1.8.0",
}

func GetKubeadmCachedImages(version string) []string {
return []string{
// Dashboard
"k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1",

// Addon Manager
"k8s.gcr.io/kube-addon-manager:v8.6",
func GetKubeadmCachedImages(kubernetesVersionStr string) []string {

// Pause
"k8s.gcr.io/pause-amd64:3.1",
var images = []string{
"k8s.gcr.io/kube-proxy-amd64:" + kubernetesVersionStr,
"k8s.gcr.io/kube-scheduler-amd64:" + kubernetesVersionStr,
"k8s.gcr.io/kube-controller-manager-amd64:" + kubernetesVersionStr,
"k8s.gcr.io/kube-apiserver-amd64:" + kubernetesVersionStr,
}

// DNS
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8",
v1_10 := semver.MustParseRange(">=1.10.0 <1.11.0")
v1_9 := semver.MustParseRange(">=1.9.0 <1.10.0")
v1_8 := semver.MustParseRange(">=1.8.0 <1.9.0")

// etcd
"k8s.gcr.io/etcd-amd64:3.1.12",
kubernetesVersion, err := semver.Make(strings.TrimPrefix(kubernetesVersionStr, minikubeVersion.VersionPrefix))
if err != nil {
glog.Errorln("Error parsing version semver: ", err)
}

"k8s.gcr.io/kube-proxy-amd64:" + version,
"k8s.gcr.io/kube-scheduler-amd64:" + version,
"k8s.gcr.io/kube-controller-manager-amd64:" + version,
"k8s.gcr.io/kube-apiserver-amd64:" + version,
if v1_10(kubernetesVersion) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I usually prefer a switch statement to a long list of if elses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. With the multiple booleans though I'm not sure how I could structure this more cleanly so settled on that code structure as being clean and understandable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, SGTM then. I'll think on this a bit and see if I can come up with a way to make it more declarative longer term.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last nit, it might be a bit more clear if this first if statement is something like:

if v_10 || greater_than_v_10

that makes it clearer that versions outside the range (but higher) get the same images as the latest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Updated.

images = append(images, []string{
"k8s.gcr.io/pause-amd64:3.1",
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8",
"k8s.gcr.io/etcd-amd64:3.1.12",
}...)

} else if v1_9(kubernetesVersion) {
images = append(images, []string{
"k8s.gcr.io/pause-amd64:3.0",
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.7",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.7",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.7",
"k8s.gcr.io/etcd-amd64:3.1.10",
}...)

} else if v1_8(kubernetesVersion) {
images = append(images, []string{
"k8s.gcr.io/pause-amd64:3.0",
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.5",
"k8s.gcr.io/etcd-amd64:3.0.17",
}...)

} else {
images = append(images, []string{
"k8s.gcr.io/pause-amd64:3.1",
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8",
"k8s.gcr.io/etcd-amd64:3.1.12",
}...)
}

//Storage Provisioner
images = append(images, []string{
"k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1",
"k8s.gcr.io/kube-addon-manager:v8.6",
"gcr.io/k8s-minikube/storage-provisioner:v1.8.1",
}
}...)

return images
}

var ImageCacheDir = MakeMiniPath("cache", "images")