Skip to content

Commit 5765b08

Browse files
kpiljoongspowelljr
authored andcommitted
Fix to prevent accepting addons flag when no kubernetes
1 parent 7481115 commit 5765b08

File tree

11 files changed

+33
-6
lines changed

11 files changed

+33
-6
lines changed

cmd/minikube/cmd/config/enable.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"k8s.io/minikube/pkg/addons"
2525
"k8s.io/minikube/pkg/minikube/assets"
2626
"k8s.io/minikube/pkg/minikube/config"
27+
"k8s.io/minikube/pkg/minikube/constants"
2728
"k8s.io/minikube/pkg/minikube/exit"
2829
"k8s.io/minikube/pkg/minikube/out"
2930
"k8s.io/minikube/pkg/minikube/reason"
@@ -39,6 +40,14 @@ var addonsEnableCmd = &cobra.Command{
3940
if len(args) != 1 {
4041
exit.Message(reason.Usage, "usage: minikube addons enable ADDON_NAME")
4142
}
43+
cc, err := config.Load(ClusterFlagValue())
44+
if err != nil && !config.IsNotExist(err) {
45+
out.ErrT(style.Sad, `Unable to load config: {{.error}}`, out.V{"error": err})
46+
}
47+
if cc.KubernetesConfig.KubernetesVersion == constants.NoKubernetesVersion {
48+
exit.Message(reason.Usage, "Cannot enable addons without Kubernetes")
49+
}
50+
4251
addon := args[0]
4352
isDeprecated, replacement, msg := addons.Deprecations(addon)
4453
if isDeprecated && replacement == "" {
@@ -72,7 +81,7 @@ You can view the list of minikube maintainers at: https://github.com/kubernetes/
7281
if registries != "" {
7382
viper.Set(config.AddonRegistries, registries)
7483
}
75-
err := addons.SetAndSave(ClusterFlagValue(), addon, "true")
84+
err = addons.SetAndSave(ClusterFlagValue(), addon, "true")
7685
if err != nil && !errors.Is(err, addons.ErrSkipThisAddon) {
7786
exit.Error(reason.InternalAddonEnable, "enable failed", err)
7887
}

cmd/minikube/cmd/start.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,19 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
309309
validateDockerStorageDriver(driverName)
310310
}
311311

312+
k8sVersion, err := getKubernetesVersion(existing)
313+
if err != nil {
314+
klog.Warningf("failed getting Kubernetes version: %v", err)
315+
}
316+
317+
// Disallow accepting addons flag without Kubernetes
318+
// It places here because cluster config is required to get the old version.
319+
if cmd.Flags().Changed(config.AddonListFlag) {
320+
if k8sVersion == constants.NoKubernetesVersion || viper.GetBool(noKubernetes) {
321+
exit.Message(reason.Usage, "Cannot enable addons without Kubernetes")
322+
}
323+
}
324+
312325
// Download & update the driver, even in --download-only mode
313326
if !viper.GetBool(dryRun) {
314327
updateDriver(driverName)
@@ -320,10 +333,6 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
320333
stopk8s = true
321334
}
322335

323-
k8sVersion, err := getKubernetesVersion(existing)
324-
if err != nil {
325-
klog.Warningf("failed getting Kubernetes version: %v", err)
326-
}
327336
rtime := getContainerRuntime(existing)
328337
cc, n, err := generateClusterConfig(cmd, existing, k8sVersion, rtime, driverName)
329338
if err != nil {

translations/de.json

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

translations/es.json

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

translations/fr.json

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

translations/ja.json

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

translations/ko.json

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

translations/pl.json

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

translations/ru.json

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"Cache image from remote registry": "",
9090
"Cache image to docker daemon": "",
9191
"Cache image to remote registry": "",
92+
"Cannot enable addons without Kubernetes": "",
9293
"Cannot find directory {{.path}} for copy": "",
9394
"Cannot find directory {{.path}} for mount": "",
9495
"Cannot use both --output and --format options": "",

translations/strings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"Cache image from remote registry": "",
9090
"Cache image to docker daemon": "",
9191
"Cache image to remote registry": "",
92+
"Cannot enable addons without Kubernetes": "",
9293
"Cannot find directory {{.path}} for copy": "",
9394
"Cannot find directory {{.path}} for mount": "",
9495
"Cannot use both --output and --format options": "",

translations/zh-CN.json

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

0 commit comments

Comments
 (0)