Fix to prevent accepting addons flag when no kubernetes

pull/15003/head
piljoong 2022-09-23 00:56:59 +09:00 committed by Steven Powell
parent 748111556a
commit 5765b08ae3
11 changed files with 33 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import (
"k8s.io/minikube/pkg/addons"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/reason"
@ -39,6 +40,14 @@ var addonsEnableCmd = &cobra.Command{
if len(args) != 1 {
exit.Message(reason.Usage, "usage: minikube addons enable ADDON_NAME")
}
cc, err := config.Load(ClusterFlagValue())
if err != nil && !config.IsNotExist(err) {
out.ErrT(style.Sad, `Unable to load config: {{.error}}`, out.V{"error": err})
}
if cc.KubernetesConfig.KubernetesVersion == constants.NoKubernetesVersion {
exit.Message(reason.Usage, "Cannot enable addons without Kubernetes")
}
addon := args[0]
isDeprecated, replacement, msg := addons.Deprecations(addon)
if isDeprecated && replacement == "" {
@ -72,7 +81,7 @@ You can view the list of minikube maintainers at: https://github.com/kubernetes/
if registries != "" {
viper.Set(config.AddonRegistries, registries)
}
err := addons.SetAndSave(ClusterFlagValue(), addon, "true")
err = addons.SetAndSave(ClusterFlagValue(), addon, "true")
if err != nil && !errors.Is(err, addons.ErrSkipThisAddon) {
exit.Error(reason.InternalAddonEnable, "enable failed", err)
}

View File

@ -309,6 +309,19 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
validateDockerStorageDriver(driverName)
}
k8sVersion, err := getKubernetesVersion(existing)
if err != nil {
klog.Warningf("failed getting Kubernetes version: %v", err)
}
// Disallow accepting addons flag without Kubernetes
// It places here because cluster config is required to get the old version.
if cmd.Flags().Changed(config.AddonListFlag) {
if k8sVersion == constants.NoKubernetesVersion || viper.GetBool(noKubernetes) {
exit.Message(reason.Usage, "Cannot enable addons without Kubernetes")
}
}
// Download & update the driver, even in --download-only mode
if !viper.GetBool(dryRun) {
updateDriver(driverName)
@ -320,10 +333,6 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
stopk8s = true
}
k8sVersion, err := getKubernetesVersion(existing)
if err != nil {
klog.Warningf("failed getting Kubernetes version: %v", err)
}
rtime := getContainerRuntime(existing)
cc, n, err := generateClusterConfig(cmd, existing, k8sVersion, rtime, driverName)
if err != nil {

View File

@ -95,6 +95,7 @@
"Cache image from remote registry": "Image von entfernter Registry cachen",
"Cache image to docker daemon": "Image zum Docker Daemon cachen",
"Cache image to remote registry": "Image in entfernter Docker Registry cachen",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "Kann das Verzeichnis {{.path}} fürs Kopieren nicht finden.",
"Cannot find directory {{.path}} for mount": "Kann das Verzeichnis {{.path}} fürs Einhängen nicht finden.",
"Cannot use both --output and --format options": "--output und --format können nicht gleichzeitig verwendet werden",

View File

@ -97,6 +97,7 @@
"Cache image from remote registry": "",
"Cache image to docker daemon": "",
"Cache image to remote registry": "",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "",
"Cannot find directory {{.path}} for mount": "No se pudo encontrar el directorio {{.path}} para montar",
"Cannot use both --output and --format options": "No se pueden usar ambas opciones (--output y --path)",

View File

@ -97,6 +97,7 @@
"Cache image from remote registry": "Cacher l'image du registre distant",
"Cache image to docker daemon": "Cacher l'image dans le démon docker",
"Cache image to remote registry": "Cacher l'image dans le registre distant",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "Impossible de trouver le répertoire {{.path}} pour la copie",
"Cannot find directory {{.path}} for mount": "Impossible de trouver le répertoire {{.path}} pour le montage",
"Cannot use both --output and --format options": "Impossible d'utiliser à la fois les options --output et --format",

View File

@ -91,6 +91,7 @@
"Cache image from remote registry": "リモートレジストリーからイメージをキャッシュします",
"Cache image to docker daemon": "Docker デーモンへイメージをキャッシュします",
"Cache image to remote registry": "リモートレジストリーへイメージをキャッシュします",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "コピーするためのディレクトリー {{.path}} が見つかりません",
"Cannot find directory {{.path}} for mount": "マウントするためのディレクトリー {{.path}} が見つかりません",
"Cannot use both --output and --format options": "--output と --format オプションの両方を使用することはできません",

View File

@ -100,6 +100,7 @@
"Cache image from remote registry": "원격 레지스트리의 캐시 이미지",
"Cache image to docker daemon": "",
"Cache image to remote registry": "",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "복사하기 위한 디렉토리 {{.path}} 를 찾을 수 없습니다.",
"Cannot find directory {{.path}} for mount": "마운트하기 위한 디렉토리 {{.path}} 를 찾을 수 없습니다",
"Cannot use both --output and --format options": "--output 과 --format 옵션을 함께 사용할 수 없습니다",

View File

@ -97,6 +97,7 @@
"Cache image from remote registry": "",
"Cache image to docker daemon": "",
"Cache image to remote registry": "",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "Nie znaleziono katalogu {{.path}} do skopiowania",
"Cannot find directory {{.path}} for mount": "Nie można odnaleźć folderu {{.path}} do zamontowania",
"Cannot use both --output and --format options": "Nie można użyć obydwu opcji --output i --format jednocześnie",

View File

@ -89,6 +89,7 @@
"Cache image from remote registry": "",
"Cache image to docker daemon": "",
"Cache image to remote registry": "",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "",
"Cannot find directory {{.path}} for mount": "",
"Cannot use both --output and --format options": "",

View File

@ -89,6 +89,7 @@
"Cache image from remote registry": "",
"Cache image to docker daemon": "",
"Cache image to remote registry": "",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "",
"Cannot find directory {{.path}} for mount": "",
"Cannot use both --output and --format options": "",

View File

@ -111,6 +111,7 @@
"Cache image from remote registry": "远程仓库中缓存镜像",
"Cache image to docker daemon": "缓存镜像到 docker daemon",
"Cache image to remote registry": "缓存镜像到远程仓库",
"Cannot enable addons without Kubernetes": "",
"Cannot find directory {{.path}} for copy": "找不到用来复制的 {{.path}} 目录",
"Cannot find directory {{.path}} for mount": "找不到用来挂载的 {{.path}} 目录",
"Cannot use both --output and --format options": "不能同时使用 --output 和 --format 选项",
@ -1216,4 +1217,4 @@
"{{.profile}} profile is not valid: {{.err}}": "",
"{{.type}} is not yet a supported filesystem. We will try anyways!": "",
"{{.url}} is not accessible: {{.error}}": ""
}
}