diff --git a/pkg/minikube/bootstrapper/images/kubeadm.go b/pkg/minikube/bootstrapper/images/kubeadm.go index 2c3ea23b62..49a351786c 100644 --- a/pkg/minikube/bootstrapper/images/kubeadm.go +++ b/pkg/minikube/bootstrapper/images/kubeadm.go @@ -17,6 +17,7 @@ limitations under the License. package images import ( + "fmt" "strings" "github.com/blang/semver" @@ -29,6 +30,12 @@ func Kubeadm(mirror string, version string) ([]string, error) { if err != nil { return nil, errors.Wrap(err, "semver") } + if v.Major > 1 { + return nil, fmt.Errorf("version too new: %v", v) + } + if semver.MustParseRange("<1.11.0-alpha.0")(v) { + return nil, fmt.Errorf("version too old: %v", v) + } imgs := essentials(mirror, v) imgs = append(imgs, auxiliary(mirror)...) return imgs, nil diff --git a/pkg/minikube/bootstrapper/images/kubeadm_test.go b/pkg/minikube/bootstrapper/images/kubeadm_test.go index 238c068d38..17098145af 100644 --- a/pkg/minikube/bootstrapper/images/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/images/kubeadm_test.go @@ -28,9 +28,13 @@ func TestKubeadmImages(t *testing.T) { tests := []struct { version string mirror string + invalid bool want []string }{ - {"v1.17.0", "", []string{ + {"invalid", "", true, nil}, + {"v0.0.1", "", true, nil}, // too old + {"v2.0.0", "", true, nil}, // too new + {"v1.17.0", "", false, []string{ "k8s.gcr.io/kube-proxy:v1.17.0", "k8s.gcr.io/kube-scheduler:v1.17.0", "k8s.gcr.io/kube-controller-manager:v1.17.0", @@ -42,7 +46,7 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.1.0", "docker.io/kubernetesui/metrics-scraper:v1.0.4", }}, - {"v1.16.1", "mirror.k8s.io", []string{ + {"v1.16.1", "mirror.k8s.io", false, []string{ "mirror.k8s.io/kube-proxy:v1.16.1", "mirror.k8s.io/kube-scheduler:v1.16.1", "mirror.k8s.io/kube-controller-manager:v1.16.1", @@ -54,7 +58,7 @@ func TestKubeadmImages(t *testing.T) { "mirror.k8s.io/dashboard:v2.1.0", "mirror.k8s.io/metrics-scraper:v1.0.4", }}, - {"v1.15.0", "", []string{ + {"v1.15.0", "", false, []string{ "k8s.gcr.io/kube-proxy:v1.15.0", "k8s.gcr.io/kube-scheduler:v1.15.0", "k8s.gcr.io/kube-controller-manager:v1.15.0", @@ -66,7 +70,7 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.1.0", "docker.io/kubernetesui/metrics-scraper:v1.0.4", }}, - {"v1.14.0", "", []string{ + {"v1.14.0", "", false, []string{ "k8s.gcr.io/kube-proxy:v1.14.0", "k8s.gcr.io/kube-scheduler:v1.14.0", "k8s.gcr.io/kube-controller-manager:v1.14.0", @@ -78,7 +82,7 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.1.0", "docker.io/kubernetesui/metrics-scraper:v1.0.4", }}, - {"v1.13.0", "", []string{ + {"v1.13.0", "", false, []string{ "k8s.gcr.io/kube-proxy:v1.13.0", "k8s.gcr.io/kube-scheduler:v1.13.0", "k8s.gcr.io/kube-controller-manager:v1.13.0", @@ -90,7 +94,7 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.1.0", "docker.io/kubernetesui/metrics-scraper:v1.0.4", }}, - {"v1.12.0", "", []string{ + {"v1.12.0", "", false, []string{ "k8s.gcr.io/kube-proxy:v1.12.0", "k8s.gcr.io/kube-scheduler:v1.12.0", "k8s.gcr.io/kube-controller-manager:v1.12.0", @@ -102,11 +106,27 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.1.0", "docker.io/kubernetesui/metrics-scraper:v1.0.4", }}, + {"v1.11.0", "", false, []string{ + "k8s.gcr.io/kube-proxy:v1.11.0", + "k8s.gcr.io/kube-scheduler:v1.11.0", + "k8s.gcr.io/kube-controller-manager:v1.11.0", + "k8s.gcr.io/kube-apiserver:v1.11.0", + "k8s.gcr.io/coredns:1.1.3", + "k8s.gcr.io/etcd:3.2.18", + "k8s.gcr.io/pause:3.1", + "gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(), + "docker.io/kubernetesui/dashboard:v2.1.0", + "docker.io/kubernetesui/metrics-scraper:v1.0.4", + }}, + {"v1.10.0", "", true, nil}, } for _, tc := range tests { got, err := Kubeadm(tc.mirror, tc.version) - if err != nil { - t.Fatalf("unexpected err: %v", err) + if err == nil && tc.invalid { + t.Fatalf("expected err (%s): %v", tc.version, got) + } + if err != nil && !tc.invalid { + t.Fatalf("unexpected err (%s): %v", tc.version, err) } sort.Strings(got) sort.Strings(tc.want)