mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
kubeadm: use JoinHostPort in WaitControlPlaneClient
Using naive string concat with ":" does not work for IPv6. Apply the fix to WaitForKubelet as well.
This commit is contained in:
@@ -19,9 +19,11 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
flag "github.com/spf13/pflag"
|
||||
@@ -579,9 +581,12 @@ func (d *initData) WaitControlPlaneClient() (clientset.Interface, error) {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range config.Clusters {
|
||||
v.Server = fmt.Sprintf("https://%s:%d",
|
||||
d.Cfg().LocalAPIEndpoint.AdvertiseAddress,
|
||||
d.Cfg().LocalAPIEndpoint.BindPort)
|
||||
v.Server = fmt.Sprintf("https://%s",
|
||||
net.JoinHostPort(
|
||||
d.Cfg().LocalAPIEndpoint.AdvertiseAddress,
|
||||
strconv.Itoa(int(d.Cfg().LocalAPIEndpoint.BindPort)),
|
||||
),
|
||||
)
|
||||
}
|
||||
client, err := kubeconfigutil.ToClientSet(config)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,8 +19,10 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@@ -636,9 +638,12 @@ func (j *joinData) WaitControlPlaneClient() (clientset.Interface, error) {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range config.Clusters {
|
||||
v.Server = fmt.Sprintf("https://%s:%d",
|
||||
j.Cfg().ControlPlane.LocalAPIEndpoint.AdvertiseAddress,
|
||||
j.Cfg().ControlPlane.LocalAPIEndpoint.BindPort)
|
||||
v.Server = fmt.Sprintf("https://%s",
|
||||
net.JoinHostPort(
|
||||
j.Cfg().ControlPlane.LocalAPIEndpoint.AdvertiseAddress,
|
||||
strconv.Itoa(int(j.Cfg().ControlPlane.LocalAPIEndpoint.BindPort)),
|
||||
),
|
||||
)
|
||||
}
|
||||
client, err := kubeconfigutil.ToClientSet(config)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
@@ -357,7 +358,8 @@ func (w *KubeWaiter) WaitForKubelet(healthzAddress string, healthzPort int32) er
|
||||
var (
|
||||
lastError error
|
||||
start = time.Now()
|
||||
healthzEndpoint = fmt.Sprintf("http://%s:%d/healthz", healthzAddress, healthzPort)
|
||||
addrPort = net.JoinHostPort(healthzAddress, strconv.Itoa(int(healthzPort)))
|
||||
healthzEndpoint = fmt.Sprintf("http://%s/healthz", addrPort)
|
||||
)
|
||||
|
||||
if healthzPort == 0 {
|
||||
|
||||
@@ -19,8 +19,10 @@ package dryrun
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
@@ -103,7 +105,11 @@ func (w *Waiter) WaitForPodsWithLabel(kvLabel string) error {
|
||||
|
||||
// WaitForKubelet blocks until the kubelet /healthz endpoint returns 'ok'
|
||||
func (w *Waiter) WaitForKubelet(healthzAddress string, healthzPort int32) error {
|
||||
fmt.Printf("[dryrun] Would make sure the kubelet returns 'ok' at http://%s:%d/healthz\n", healthzAddress, healthzPort)
|
||||
var (
|
||||
addrPort = net.JoinHostPort(healthzAddress, strconv.Itoa(int(healthzPort)))
|
||||
healthzEndpoint = fmt.Sprintf("http://%s/healthz", addrPort)
|
||||
)
|
||||
fmt.Printf("[dryrun] Would make sure the kubelet returns 'ok' at %s\n", healthzEndpoint)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user