Skip to content

Commit 1852589

Browse files
kebe7junaojea
andcommitted
Setting the default hostIP for get kubeconfig
Update pkg/cluster/internal/providers/podman/provider.go Co-authored-by: Antonio Ojea <[email protected]>
1 parent 1a8f047 commit 1852589

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/cluster/internal/providers/podman/provider.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ func (p *provider) DeleteNodes(n []nodes.Node) error {
171171
return deleteVolumes(nodeVolumes)
172172
}
173173

174+
// getHostIPOrDefault defaults HostIP to localhost if is not set
175+
// xref: https://github.com/kubernetes-sigs/kind/issues/3777
176+
func getHostIPOrDefault(hostIP string) string {
177+
if hostIP == "" {
178+
return "127.0.0.1"
179+
}
180+
return hostIP
181+
}
182+
174183
// GetAPIServerEndpoint is part of the providers.Provider interface
175184
func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
176185
// locate the node that hosts this
@@ -266,7 +275,7 @@ func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
266275
}
267276
for _, pm := range v {
268277
if containerPort == common.APIServerInternalPort && protocol == "tcp" {
269-
return net.JoinHostPort(pm.HostIP, pm.HostPort), nil
278+
return net.JoinHostPort(getHostIPOrDefault(pm.HostIP), pm.HostPort), nil
270279
}
271280
}
272281
}
@@ -278,7 +287,7 @@ func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
278287
}
279288
for _, pm := range portMappings19 {
280289
if pm.ContainerPort == common.APIServerInternalPort && pm.Protocol == "tcp" {
281-
return net.JoinHostPort(pm.HostIP, strconv.Itoa(int(pm.HostPort))), nil
290+
return net.JoinHostPort(getHostIPOrDefault(pm.HostIP), strconv.Itoa(int(pm.HostPort))), nil
282291
}
283292
}
284293

0 commit comments

Comments
 (0)