Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
39 changes: 21 additions & 18 deletions pkg/minikube/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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()
Expand Down Expand Up @@ -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, "=")
Expand Down
Loading