Setting the default hostIP for get kubeconfig

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

Co-authored-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
This commit is contained in:
Kebe
2024-11-06 10:01:38 +08:00
parent 1a8f0473a0
commit 1852589dd7

View File

@@ -171,6 +171,15 @@ func (p *provider) DeleteNodes(n []nodes.Node) error {
return deleteVolumes(nodeVolumes) 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 {
if hostIP == "" {
return "127.0.0.1"
}
return hostIP
}
// GetAPIServerEndpoint is part of the providers.Provider interface // GetAPIServerEndpoint is part of the providers.Provider interface
func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) { func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
// locate the node that hosts this // locate the node that hosts this
@@ -266,7 +275,7 @@ func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
} }
for _, pm := range v { for _, pm := range v {
if containerPort == common.APIServerInternalPort && protocol == "tcp" { if containerPort == common.APIServerInternalPort && protocol == "tcp" {
return net.JoinHostPort(pm.HostIP, pm.HostPort), nil return net.JoinHostPort(getHostIPOrDefault(pm.HostIP), pm.HostPort), nil
} }
} }
} }
@@ -278,7 +287,7 @@ func (p *provider) GetAPIServerEndpoint(cluster string) (string, error) {
} }
for _, pm := range portMappings19 { for _, pm := range portMappings19 {
if pm.ContainerPort == common.APIServerInternalPort && pm.Protocol == "tcp" { 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
} }
} }