From dbf2bd368813131feee4777c1fafe6c197e91e01 Mon Sep 17 00:00:00 2001 From: Kebe Date: Wed, 6 Nov 2024 10:01:38 +0800 Subject: [PATCH] Setting the default hostIP for `get kubeconfig` --- pkg/cluster/internal/providers/podman/provider.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/cluster/internal/providers/podman/provider.go b/pkg/cluster/internal/providers/podman/provider.go index 856b07b046..4091f4b00a 100644 --- a/pkg/cluster/internal/providers/podman/provider.go +++ b/pkg/cluster/internal/providers/podman/provider.go @@ -171,6 +171,13 @@ func (p *provider) DeleteNodes(n []nodes.Node) error { return deleteVolumes(nodeVolumes) } +func getHostIPOrDefault(hostIP string) string { + 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 @@ -266,7 +273,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 } } } @@ -278,7 +285,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 } }