Skip to content

Commit

Permalink
Add k8s version check
Browse files Browse the repository at this point in the history
Signed-off-by: Ling Samuel <lingsamuelgrace@gmail.com>
  • Loading branch information
lingsamuel committed Jan 13, 2021
1 parent 8fa3ccf commit fb46e42
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/minikube/cmd/node_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/minikube/pkg/minikube/out/register"
"k8s.io/minikube/pkg/minikube/reason"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/util"
)

var (
Expand Down Expand Up @@ -67,6 +68,10 @@ var nodeAddCmd = &cobra.Command{
}

if n.ControlPlane {
err := util.CheckMultiControlPlaneVersion(cc.KubernetesConfig.KubernetesVersion)
if err != nil {
exit.Error(reason.KubernetesTooOld, "target kubernetes version too old", err)
}
n.Port = cc.KubernetesConfig.NodePort
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ func runStart(cmd *cobra.Command, args []string) {
out.WarningT(fmt.Sprintf("control planes number %v larger than nodes number %v, enlarge nodes to %v.", controlPlanesNum, nodesNum, controlPlanesNum))
viper.Set(nodes, controlPlanesNum)
}
k8sVersion := viper.GetString(kubernetesVersion)
if controlPlanesNum > 1 {
err := util.CheckMultiControlPlaneVersion(k8sVersion)
if err != nil {
exit.Error(reason.KubernetesTooOld, "target kubernetes version too old", err)
}
}

out.SetJSON(outputFormat == "json")
if err := pkgtrace.Initialize(viper.GetString(trace)); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
ctx, cancel := context.WithTimeout(context.Background(), initTimeoutMinutes*time.Minute)
defer cancel()
kr, kw := io.Pipe()
c := exec.CommandContext(ctx, "/bin/bash", "-c", fmt.Sprintf("%s init --config %s %s --ignore-preflight-errors=%s --upload-certs",
c := exec.CommandContext(ctx, "/bin/bash", "-c", fmt.Sprintf("%s init --config %s %s --ignore-preflight-errors=%s",
bsutil.InvokeKubeadm(cfg.KubernetesConfig.KubernetesVersion), conf, extraFlags, strings.Join(ignore, ",")))
c.Stdout = kw
c.Stderr = kw
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,14 @@ func MaybeChownDirRecursiveToMinikubeUser(dir string) error {
func ParseKubernetesVersion(version string) (semver.Version, error) {
return semver.Make(version[1:])
}

func CheckMultiControlPlaneVersion(version string) error {
ver, err := ParseKubernetesVersion(version)
if err != nil {
return err
}
if ver.Minor < 15 {
return errors.Errorf("Multi control plane requires Kubernetes 1.15+, current version %s is not supported.", version)
}
return nil
}

0 comments on commit fb46e42

Please sign in to comment.