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

Setting the default hostIP for get kubeconfig #3778

Merged
merged 1 commit into from
Nov 7, 2024
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
13 changes: 11 additions & 2 deletions pkg/cluster/internal/providers/podman/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ func (p *provider) DeleteNodes(n []nodes.Node) error {
return deleteVolumes(nodeVolumes)
}

// getHostIPOrDefault defaults HostIP to localhost if is not set
// xref: https://github.com/kubernetes-sigs/kind/issues/3777
func getHostIPOrDefault(hostIP string) string {
aojea marked this conversation as resolved.
Show resolved Hide resolved
kebe7jun marked this conversation as resolved.
Show resolved Hide resolved
if hostIP == "" {
return "127.0.0.1"
}
return hostIP
}

// GetAPIServerEndpoint is part of the providers.Provider interface
func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
// locate the node that hosts this
Expand Down Expand Up @@ -266,7 +275,7 @@ func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
}
for _, pm := range v {
if containerPort == common.APIServerInternalPort && protocol == "tcp" {
return net.JoinHostPort(pm.HostIP, pm.HostPort), nil
return net.JoinHostPort(getHostIPOrDefault(pm.HostIP), pm.HostPort), nil
}
}
}
Expand All @@ -278,7 +287,7 @@ func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
}
for _, pm := range portMappings19 {
if pm.ContainerPort == common.APIServerInternalPort && pm.Protocol == "tcp" {
return net.JoinHostPort(pm.HostIP, strconv.Itoa(int(pm.HostPort))), nil
return net.JoinHostPort(getHostIPOrDefault(pm.HostIP), strconv.Itoa(int(pm.HostPort))), nil
}
}

Expand Down