Skip to content

Commit

Permalink
Setting the default hostIP for get kubeconfig
Browse files Browse the repository at this point in the history
Update pkg/cluster/internal/providers/podman/provider.go

Co-authored-by: Antonio Ojea <[email protected]>
  • Loading branch information
kebe7jun and aojea committed Nov 7, 2024
1 parent 1a8f047 commit 1852589
Showing 1 changed file with 11 additions and 2 deletions.
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 {
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

0 comments on commit 1852589

Please sign in to comment.