From 5da2fdd9224a36954dd8269e33b2cfe5ffc43b9b Mon Sep 17 00:00:00 2001 From: Sunny Beatteay Date: Sun, 28 Jun 2020 18:57:03 -0400 Subject: [PATCH 1/4] enable graceful exit if container runtime is misspelled --- cmd/minikube/cmd/start.go | 16 ++++++++++++++++ cmd/minikube/cmd/start_flags.go | 2 +- pkg/minikube/cruntime/cruntime.go | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 85e705ced311..2ce6033dd1d4 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -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" @@ -853,6 +854,21 @@ func validateFlags(cmd *cobra.Command, drvName string) { } } + if cmd.Flags().Changed(containerRuntime) { + runtime := strings.ToLower(viper.GetString(containerRuntime)) + + var validRuntime bool + for _, option := range cruntime.ValidRuntimes() { + if runtime == option { + validRuntime = true + } + } + + 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}) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 35ff7631eeaf..b0aec3266e51 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -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) (default: docker).", 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.") diff --git a/pkg/minikube/cruntime/cruntime.go b/pkg/minikube/cruntime/cruntime.go index c5df2d1e8a71..eaaafb43fc50 100644 --- a/pkg/minikube/cruntime/cruntime.go +++ b/pkg/minikube/cruntime/cruntime.go @@ -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", "crio", "containerd"} +} + // CommandRunner is the subset of command.Runner this package consumes type CommandRunner interface { RunCmd(cmd *exec.Cmd) (*command.RunResult, error) From 5f40f863a7872830d9d5ed08fe148a9ace502a26 Mon Sep 17 00:00:00 2001 From: Sunny Beatteay Date: Sun, 28 Jun 2020 20:43:12 -0400 Subject: [PATCH 2/4] update docs --- cmd/minikube/cmd/start_flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index b0aec3266e51..157032fd1098 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -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", fmt.Sprintf("The container runtime to be used (%s) (default: docker).", strings.Join(cruntime.ValidRuntimes(), ", "))) + 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.") From 9bcc587defa6ca01018df8031d2e9a6e3929ecb0 Mon Sep 17 00:00:00 2001 From: Sunny Beatteay Date: Mon, 29 Jun 2020 14:11:20 -0400 Subject: [PATCH 3/4] update crio to cri-o in docs and help text --- cmd/minikube/cmd/start.go | 6 +++++- pkg/minikube/cruntime/cruntime.go | 2 +- site/content/en/docs/commands/start.md | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 2ce6033dd1d4..e7962a7eecdb 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -857,8 +857,12 @@ 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, "crio") + var validRuntime bool - for _, option := range cruntime.ValidRuntimes() { + for _, option := range validOptions { if runtime == option { validRuntime = true } diff --git a/pkg/minikube/cruntime/cruntime.go b/pkg/minikube/cruntime/cruntime.go index eaaafb43fc50..c339809eaf86 100644 --- a/pkg/minikube/cruntime/cruntime.go +++ b/pkg/minikube/cruntime/cruntime.go @@ -49,7 +49,7 @@ func (cs ContainerState) String() string { // ValidRuntimes lists the supported container runtimes func ValidRuntimes() []string { - return []string{"docker", "crio", "containerd"} + return []string{"docker", "cri-o", "containerd"} } // CommandRunner is the subset of command.Runner this package consumes diff --git a/site/content/en/docs/commands/start.md b/site/content/en/docs/commands/start.md index 3e38d75656eb..980a82e2612c 100644 --- a/site/content/en/docs/commands/start.md +++ b/site/content/en/docs/commands/start.md @@ -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. From 28238150f595f84ace39a1e439ceddd57aa8c4ac Mon Sep 17 00:00:00 2001 From: Sunny Beatteay Date: Mon, 29 Jun 2020 19:49:38 -0400 Subject: [PATCH 4/4] ensure that 'crio' is used for k8s config --- cmd/minikube/cmd/start.go | 7 ++++++- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 2 +- pkg/minikube/constants/constants.go | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index e7962a7eecdb..38e43316e692 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -859,13 +859,18 @@ func validateFlags(cmd *cobra.Command, drvName string) { validOptions := cruntime.ValidRuntimes() // `crio` is accepted as an alternative spelling to `cri-o` - validOptions = append(validOptions, "crio") + 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 { diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 830344fb4435..dbd4111c364c 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -281,7 +281,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") } diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index ffdb5bad12b6..19d2b73ecdd8 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -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"