Skip to content

Commit d139781

Browse files
authored
Merge pull request #5543 from govargo/feature/start-with-addons-flag
Add ability to enable addon through 'minikube start' flag
2 parents 4916c04 + f111f09 commit d139781

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

cmd/minikube/cmd/start.go

+12
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const (
9999
imageMirrorCountry = "image-mirror-country"
100100
mountString = "mount-string"
101101
disableDriverMounts = "disable-driver-mounts"
102+
addons = "addons"
102103
cacheImages = "cache-images"
103104
uuid = "uuid"
104105
vpnkitSock = "hyperkit-vpnkit-sock"
@@ -124,6 +125,7 @@ var (
124125
dockerOpt []string
125126
insecureRegistry []string
126127
apiServerNames []string
128+
addonList []string
127129
apiServerIPs []net.IP
128130
extraOptions cfg.ExtraOptionSlice
129131
enableUpdateNotification = true
@@ -162,6 +164,7 @@ func initMinikubeFlags() {
162164
startCmd.Flags().String(containerRuntime, "docker", "The container runtime to be used (docker, crio, containerd).")
163165
startCmd.Flags().Bool(createMount, false, "This will start the mount daemon and automatically mount files into minikube.")
164166
startCmd.Flags().String(mountString, constants.DefaultMountDir+":/minikube-host", "The argument to pass the minikube mount command on start.")
167+
startCmd.Flags().StringArrayVar(&addonList, addons, nil, "Enable addons. see `minikube addons list` for a list of valid addon names.")
165168
startCmd.Flags().String(criSocket, "", "The cri socket path to be used.")
166169
startCmd.Flags().String(networkPlugin, "", "The name of the network plugin.")
167170
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) {
342345
// pull images or restart cluster
343346
bootstrapCluster(bs, cr, mRunner, config.KubernetesConfig, preExists, isUpgrade)
344347
configureMounts()
348+
349+
// enable addons with start command
350+
for _, a := range addonList {
351+
err = cmdcfg.Set(a, "true")
352+
if err != nil {
353+
exit.WithError("addon enable failed", err)
354+
}
355+
}
356+
345357
if err = loadCachedImagesInConfigFile(); err != nil {
346358
out.T(out.FailureType, "Unable to load cached images from config file.")
347359
}

site/content/en/docs/Reference/Commands/addons.md

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ Enables the addon w/ADDON_NAME within minikube (example: minikube addons enable
3939
minikube addons enable ADDON_NAME [flags]
4040
```
4141

42+
or
43+
44+
```
45+
minikube start --addons ADDON_NAME [flags]
46+
```
47+
4248
## minikube addons list
4349

4450
Lists all available minikube addons as well as their current statuses (enabled/disabled)

site/content/en/docs/Reference/Commands/start.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ minikube start [flags]
1616
### Options
1717

1818
```
19+
--addons Enable addons. see `minikube addons list` for a list of valid addon names.
1920
--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 [])
2021
--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")
2122
--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

site/content/en/docs/Tasks/addons.md

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ Example output:
5555
minikube addons enable <name>
5656
```
5757

58+
or
59+
60+
```shell
61+
minikube start --addons <name>
62+
```
63+
5864
## Interacting with an addon
5965

6066
For addons that expose a browser endpoint, use:

test/integration/addons_test.go

+3-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestAddons(t *testing.T) {
4242
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Minute)
4343
defer CleanupWithLogs(t, profile, cancel)
4444

45-
args := append([]string{"start", "-p", profile, "--wait=false", "--memory=2600", "--alsologtostderr", "-v=1"}, StartArgs()...)
45+
args := append([]string{"start", "-p", profile, "--wait=false", "--memory=2600", "--alsologtostderr", "-v=1", "--addons=ingress", "--addons=registry"}, StartArgs()...)
4646
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
4747
if err != nil {
4848
t.Fatalf("%s failed: %v", rr.Args, err)
@@ -72,11 +72,6 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
7272
t.Skipf("skipping: ssh unsupported by none")
7373
}
7474

75-
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "enable", "ingress"))
76-
if err != nil {
77-
t.Fatalf("%s failed: %v", rr.Args, err)
78-
}
79-
8075
client, err := kapi.Client(profile)
8176
if err != nil {
8277
t.Fatalf("kubernetes client: %v", client)
@@ -89,7 +84,7 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
8984
t.Fatalf("wait: %v", err)
9085
}
9186

92-
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ing.yaml")))
87+
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "nginx-ing.yaml")))
9388
if err != nil {
9489
t.Errorf("%s failed: %v", rr.Args, err)
9590
}
@@ -131,11 +126,6 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
131126
}
132127

133128
func validateRegistryAddon(ctx context.Context, t *testing.T, profile string) {
134-
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "enable", "registry"))
135-
if err != nil {
136-
t.Fatalf("%s failed: %v", rr.Args, err)
137-
}
138-
139129
client, err := kapi.Client(profile)
140130
if err != nil {
141131
t.Fatalf("kubernetes client: %v", client)
@@ -155,7 +145,7 @@ func validateRegistryAddon(ctx context.Context, t *testing.T, profile string) {
155145
}
156146

157147
// Test from inside the cluster (no curl available on busybox)
158-
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "po", "-l", "run=registry-test", "--now"))
148+
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "po", "-l", "run=registry-test", "--now"))
159149
if err != nil {
160150
t.Logf("pre-cleanup %s failed: %v (not a problem)", rr.Args, err)
161151
}

0 commit comments

Comments
 (0)