Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Do not override hostIP when hostPort is missing (#693, @lukaszo) #693

Merged
merged 1 commit into from
Aug 16, 2021
Merged
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
12 changes: 9 additions & 3 deletions cmd/cluster/clusterCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"fmt"
"os"
"runtime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -390,10 +391,15 @@ func applyCLIOverrides(cfg conf.SimpleConfig) (conf.SimpleConfig, error) {

// Set to random port if port is empty string
if len(exposeAPI.Binding.HostPort) == 0 {
exposeAPI, err = cliutil.ParsePortExposureSpec("random", k3d.DefaultAPIPort)
if err != nil {
return cfg, err
var freePort string
port, err := cliutil.GetFreePort()
freePort = strconv.Itoa(port)
if err != nil || port == 0 {
log.Warnf("Failed to get random free port: %+v", err)
log.Warnf("Falling back to internal port %s (may be blocked though)...", k3d.DefaultAPIPort)
freePort = k3d.DefaultAPIPort
}
exposeAPI.Binding.HostPort = freePort
}

cfg.ExposeAPI = conf.SimpleExposureOpts{
Expand Down