From 1e11576c9acacb424f4e5e698fd6210d7f6b006f Mon Sep 17 00:00:00 2001 From: Kenta Iso Date: Sat, 5 Oct 2019 00:25:49 +0900 Subject: [PATCH 1/4] Add addons flag to 'minikube start' in order to enable specified addons --- cmd/minikube/cmd/start.go | 12 ++++++++++++ test/integration/addons_test.go | 16 +++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 9adf964c34..39be23b5bb 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -99,6 +99,7 @@ const ( imageMirrorCountry = "image-mirror-country" mountString = "mount-string" disableDriverMounts = "disable-driver-mounts" + addons = "addons" cacheImages = "cache-images" uuid = "uuid" vpnkitSock = "hyperkit-vpnkit-sock" @@ -124,6 +125,7 @@ var ( dockerOpt []string insecureRegistry []string apiServerNames []string + addonList []string apiServerIPs []net.IP extraOptions cfg.ExtraOptionSlice enableUpdateNotification = true @@ -162,6 +164,7 @@ func initMinikubeFlags() { startCmd.Flags().String(containerRuntime, "docker", "The container runtime to be used (docker, crio, containerd).") 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(&addonList, addons, nil, "Enable addons. see addon list if you want to check them `minikube addons list`") startCmd.Flags().String(criSocket, "", "The cri socket path to be used.") startCmd.Flags().String(networkPlugin, "", "The name of the network plugin.") startCmd.Flags().Bool(enableDefaultCNI, false, "Enable the default CNI plugin (/etc/cni/net.d/k8s.conf). Used in conjunction with \"--network-plugin=cni\".") @@ -342,6 +345,15 @@ func runStart(cmd *cobra.Command, args []string) { // pull images or restart cluster bootstrapCluster(bs, cr, mRunner, config.KubernetesConfig, preExists, isUpgrade) configureMounts() + + // enable addons with start command + for _, addonName := range addonList { + err = cmdcfg.Set(addonName, "true") + if err != nil { + exit.WithError("addon enable failed", err) + } + } + if err = loadCachedImagesInConfigFile(); err != nil { out.T(out.FailureType, "Unable to load cached images from config file.") } diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index f363de6ef3..2b22e8cad2 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -42,7 +42,7 @@ func TestAddons(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 40*time.Minute) defer CleanupWithLogs(t, profile, cancel) - args := append([]string{"start", "-p", profile, "--wait=false", "--memory=2600", "--alsologtostderr", "-v=1"}, StartArgs()...) + args := append([]string{"start", "-p", profile, "--wait=false", "--memory=2600", "--alsologtostderr", "-v=1", "--addons=ingress", "--addons=registry"}, StartArgs()...) rr, err := Run(t, exec.CommandContext(ctx, Target(), args...)) if err != nil { t.Fatalf("%s failed: %v", rr.Args, err) @@ -72,11 +72,6 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) { t.Skipf("skipping: ssh unsupported by none") } - rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "enable", "ingress")) - if err != nil { - t.Fatalf("%s failed: %v", rr.Args, err) - } - client, err := kapi.Client(profile) if err != nil { t.Fatalf("kubernetes client: %v", client) @@ -89,7 +84,7 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) { t.Fatalf("wait: %v", err) } - rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ing.yaml"))) + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ing.yaml"))) if err != nil { t.Errorf("%s failed: %v", rr.Args, err) } @@ -131,11 +126,6 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) { } func validateRegistryAddon(ctx context.Context, t *testing.T, profile string) { - rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "enable", "registry")) - if err != nil { - t.Fatalf("%s failed: %v", rr.Args, err) - } - client, err := kapi.Client(profile) if err != nil { t.Fatalf("kubernetes client: %v", client) @@ -155,7 +145,7 @@ func validateRegistryAddon(ctx context.Context, t *testing.T, profile string) { } // Test from inside the cluster (no curl available on busybox) - rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "po", "-l", "run=registry-test", "--now")) + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "po", "-l", "run=registry-test", "--now")) if err != nil { t.Logf("pre-cleanup %s failed: %v (not a problem)", rr.Args, err) } From 76e5f7b4cdca907b6c065c7d416839c26474492c Mon Sep 17 00:00:00 2001 From: Kenta Iso Date: Sun, 6 Oct 2019 16:12:41 +0900 Subject: [PATCH 2/4] remove repetitive addon list from command help and add --addons flag explanation to documents --- cmd/minikube/cmd/start.go | 2 +- site/content/en/docs/Reference/Commands/addons.md | 6 ++++++ site/content/en/docs/Tasks/addons.md | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 39be23b5bb..950cead865 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -164,7 +164,7 @@ func initMinikubeFlags() { startCmd.Flags().String(containerRuntime, "docker", "The container runtime to be used (docker, crio, containerd).") 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(&addonList, addons, nil, "Enable addons. see addon list if you want to check them `minikube addons list`") + startCmd.Flags().StringArrayVar(&addonList, addons, nil, "Enable addons. see `minikube addons list` if you want to check") startCmd.Flags().String(criSocket, "", "The cri socket path to be used.") startCmd.Flags().String(networkPlugin, "", "The name of the network plugin.") startCmd.Flags().Bool(enableDefaultCNI, false, "Enable the default CNI plugin (/etc/cni/net.d/k8s.conf). Used in conjunction with \"--network-plugin=cni\".") diff --git a/site/content/en/docs/Reference/Commands/addons.md b/site/content/en/docs/Reference/Commands/addons.md index d15f38173b..a5fb310468 100644 --- a/site/content/en/docs/Reference/Commands/addons.md +++ b/site/content/en/docs/Reference/Commands/addons.md @@ -39,6 +39,12 @@ Enables the addon w/ADDON_NAME within minikube (example: minikube addons enable minikube addons enable ADDON_NAME [flags] ``` +or + +``` +minikube start --addons ADDON_NAME [flags] +``` + ## minikube addons list Lists all available minikube addons as well as their current statuses (enabled/disabled) diff --git a/site/content/en/docs/Tasks/addons.md b/site/content/en/docs/Tasks/addons.md index 0082b19f11..c454360cbc 100644 --- a/site/content/en/docs/Tasks/addons.md +++ b/site/content/en/docs/Tasks/addons.md @@ -55,6 +55,12 @@ Example output: minikube addons enable ``` +or + +```shell +minikube start --addons +``` + ## Interacting with an addon For addons that expose a browser endpoint, use: From bbf69538f5e663dd55040fce568901d84df248c9 Mon Sep 17 00:00:00 2001 From: Kenta Iso Date: Sun, 6 Oct 2019 16:31:28 +0900 Subject: [PATCH 3/4] add --addons flag explanation to Start.md --- site/content/en/docs/Reference/Commands/start.md | 1 + 1 file changed, 1 insertion(+) diff --git a/site/content/en/docs/Reference/Commands/start.md b/site/content/en/docs/Reference/Commands/start.md index 62073d14e1..870e2ef766 100644 --- a/site/content/en/docs/Reference/Commands/start.md +++ b/site/content/en/docs/Reference/Commands/start.md @@ -16,6 +16,7 @@ minikube start [flags] ### Options ``` +--addons Enable addons. see `minikube addons list` if you want to check --apiserver-ips ipSlice A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine (default []) --apiserver-name string The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine (default "minikubeCA") --apiserver-names stringArray A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine From f111f09526d63f7b69e6789ae653c191b24a6163 Mon Sep 17 00:00:00 2001 From: Kenta Iso Date: Thu, 10 Oct 2019 11:28:52 +0900 Subject: [PATCH 4/4] Modify shortlived variable name and improve --addons flag help message --- cmd/minikube/cmd/start.go | 6 +++--- site/content/en/docs/Reference/Commands/start.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 950cead865..f313c94cc9 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -164,7 +164,7 @@ func initMinikubeFlags() { startCmd.Flags().String(containerRuntime, "docker", "The container runtime to be used (docker, crio, containerd).") 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(&addonList, addons, nil, "Enable addons. see `minikube addons list` if you want to check") + startCmd.Flags().StringArrayVar(&addonList, addons, nil, "Enable addons. see `minikube addons list` for a list of valid addon names.") startCmd.Flags().String(criSocket, "", "The cri socket path to be used.") startCmd.Flags().String(networkPlugin, "", "The name of the network plugin.") startCmd.Flags().Bool(enableDefaultCNI, false, "Enable the default CNI plugin (/etc/cni/net.d/k8s.conf). Used in conjunction with \"--network-plugin=cni\".") @@ -347,8 +347,8 @@ func runStart(cmd *cobra.Command, args []string) { configureMounts() // enable addons with start command - for _, addonName := range addonList { - err = cmdcfg.Set(addonName, "true") + for _, a := range addonList { + err = cmdcfg.Set(a, "true") if err != nil { exit.WithError("addon enable failed", err) } diff --git a/site/content/en/docs/Reference/Commands/start.md b/site/content/en/docs/Reference/Commands/start.md index 870e2ef766..6e1c1b13df 100644 --- a/site/content/en/docs/Reference/Commands/start.md +++ b/site/content/en/docs/Reference/Commands/start.md @@ -16,7 +16,7 @@ minikube start [flags] ### Options ``` ---addons Enable addons. see `minikube addons list` if you want to check +--addons Enable addons. see `minikube addons list` for a list of valid addon names. --apiserver-ips ipSlice A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine (default []) --apiserver-name string The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine (default "minikubeCA") --apiserver-names stringArray A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine