diff --git a/README.md b/README.md index 97aad2b..2a02341 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,12 @@ kn quickstart minikube Note: for Windows/Mac users, after the above command completes, you will need to run the following in a separate terminal window: ``` bash -minikube tunnel --profile minikube-knative +minikube tunnel --profile knative ``` +If you selected a custom cluster name with `--name` or passed a Minikube +`--profile` after `--`, use that profile name instead of `knative`. + ## Building from Source You must [set up your development environment](https://github.com/knative/client/blob/main/DEVELOPMENT.md#prerequisites) before you build `kn-plugin-quickstart`. diff --git a/pkg/minikube/minikube.go b/pkg/minikube/minikube.go index 0411b2a..49a8cef 100644 --- a/pkg/minikube/minikube.go +++ b/pkg/minikube/minikube.go @@ -62,25 +62,9 @@ func SetUp(name, kVersion string, installServing, installEventing bool, minikube os.Exit(1) } - clusterName = name + clusterName = profileName(name, minikubeArgs) if len(minikubeArgs) > 0 { customMinikubeArgs = minikubeArgs - // check custom flags for name, as that takes precedent and affects functionality the most (most recent) - for i, arg := range slices.Backward(minikubeArgs) { - customArg, value := parseArg(arg) - if customArg == "-p" || customArg == "--profile" { - // use value from equal sign if it is there - if value != "" { - clusterName = value - } else if i+1 >= len(customMinikubeArgs) { - // edge case, but continue if not filled in and let minikube throw an error for empty arg - continue - } else { - clusterName = customMinikubeArgs[i+1] - } - break - } - } } if kVersion != "" { @@ -93,7 +77,7 @@ func SetUp(name, kVersion string, installServing, installEventing bool, minikube } fmt.Print("\n") fmt.Println("To finish setting up networking for minikube, run the following command in a separate terminal window:") - fmt.Println(" minikube tunnel --profile knative") + fmt.Printf(" minikube tunnel --profile %s\n", clusterName) fmt.Println("The tunnel command must be running in a terminal window any time when using the knative quickstart environment.") fmt.Println("\nPress the Enter key to continue") fmt.Scanln() @@ -310,6 +294,25 @@ func recreateCluster() error { return nil } +// profileName resolves the name used by both cluster setup and tunnel instructions. +// The last passthrough profile flag takes precedence over quickstart's --name. +func profileName(name string, args []string) string { + for index, arg := range slices.Backward(args) { + flag, value := parseArg(arg) + if flag != "-p" && flag != "--profile" { + continue + } + if value != "" { + return value + } + if index+1 < len(args) { + return args[index+1] + } + // Leave a missing value for minikube to report as an error. + } + return name +} + func parseArg(arg string) (string, string) { if strings.Contains(arg, "=") { parts := strings.Split(arg, "=")