From 1e11576c9acacb424f4e5e698fd6210d7f6b006f Mon Sep 17 00:00:00 2001 From: Kenta Iso Date: Sat, 5 Oct 2019 00:25:49 +0900 Subject: [PATCH] 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) }