未验证 提交 9e35037e 编写于 作者: M Medya Ghazizadeh 提交者: GitHub

Merge pull request #8593 from sunny-b/gracefully-fail-misspelled-runtime

Gracefully exit if container runtime is misspelled
......@@ -46,6 +46,7 @@ import (
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
......@@ -854,6 +855,30 @@ func validateFlags(cmd *cobra.Command, drvName string) {
}
}
if cmd.Flags().Changed(containerRuntime) {
runtime := strings.ToLower(viper.GetString(containerRuntime))
validOptions := cruntime.ValidRuntimes()
// `crio` is accepted as an alternative spelling to `cri-o`
validOptions = append(validOptions, constants.CRIO)
var validRuntime bool
for _, option := range validOptions {
if runtime == option {
validRuntime = true
}
// Convert `cri-o` to `crio` as the K8s config uses the `crio` spelling
if runtime == "cri-o" {
viper.Set(containerRuntime, constants.CRIO)
}
}
if !validRuntime {
exit.UsageT(`Invalid Container Runtime: "{{.runtime}}". Valid runtimes are: {{.validOptions}}`, out.V{"runtime": runtime, "validOptions": strings.Join(cruntime.ValidRuntimes(), ", ")})
}
}
if driver.BareMetal(drvName) {
if ClusterFlagValue() != constants.DefaultClusterName {
exit.WithCodeT(exit.Config, "The '{{.name}} driver does not support multiple profiles: https://minikube.sigs.k8s.io/docs/reference/drivers/none/", out.V{"name": drvName})
......
......@@ -127,7 +127,7 @@ func initMinikubeFlags() {
startCmd.Flags().String(kicBaseImage, kic.BaseImage, "The base image to use for docker/podman drivers. Intended for local development.")
startCmd.Flags().Bool(keepContext, false, "This will keep the existing kubectl context and will create a minikube context.")
startCmd.Flags().Bool(embedCerts, false, "if true, will embed the certs in kubeconfig.")
startCmd.Flags().String(containerRuntime, "docker", "The container runtime to be used (docker, crio, containerd).")
startCmd.Flags().String(containerRuntime, "docker", fmt.Sprintf("The container runtime to be used (%s).", strings.Join(cruntime.ValidRuntimes(), ", ")))
startCmd.Flags().Bool(createMount, false, "This will start the mount daemon and automatically mount files into minikube.")
startCmd.Flags().String(mountString, constants.DefaultMountDir+":/minikube-host", "The argument to pass the minikube mount command on start.")
startCmd.Flags().StringArrayVar(&config.AddonList, "addons", nil, "Enable addons. see `minikube addons list` for a list of valid addon names.")
......
......@@ -284,7 +284,7 @@ func (k *Bootstrapper) applyCNI(cfg config.ClusterConfig) error {
return errors.Wrap(err, "cni apply")
}
if cfg.KubernetesConfig.ContainerRuntime == "crio" {
if cfg.KubernetesConfig.ContainerRuntime == constants.CRIO {
if err := cruntime.UpdateCRIONet(k.c, cnm.CIDR()); err != nil {
return errors.Wrap(err, "update crio")
}
......
......@@ -42,6 +42,8 @@ const (
SSHPort = 22
// RegistryAddonPort os the default registry addon port
RegistryAddonPort = 5000
// CRIO is the default name and spelling for the cri-o container runtime
CRIO = "crio"
// APIServerName is the default API server name
APIServerName = "minikubeCA"
......
......@@ -47,6 +47,11 @@ func (cs ContainerState) String() string {
return [...]string{"all", "running", "paused"}[cs]
}
// ValidRuntimes lists the supported container runtimes
func ValidRuntimes() []string {
return []string{"docker", "cri-o", "containerd"}
}
// CommandRunner is the subset of command.Runner this package consumes
type CommandRunner interface {
RunCmd(cmd *exec.Cmd) (*command.RunResult, error)
......
......@@ -30,7 +30,7 @@ minikube start [flags]
--base-image string The base image to use for docker/podman drivers. Intended for local development. (default "gcr.io/k8s-minikube/kicbase:v0.0.10@sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438")
--cache-images If true, cache docker images for the current bootstrapper and load them into the machine. Always false with --driver=none. (default true)
--cni string CNI plug-in to use. Valid options: auto, bridge, flannel, kindnet, or path to a CNI manifest (default: auto)
--container-runtime string The container runtime to be used (docker, crio, containerd). (default "docker")
--container-runtime string The container runtime to be used (docker, cri-o, containerd). (default "docker")
--cpus int Number of CPUs allocated to Kubernetes. (default 2)
--cri-socket string The cri socket path to be used.
--delete-on-failure If set, delete the current cluster if start fails and try again. Defaults to false.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册