diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index adc0b694780..21e2694d35f 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -431,9 +431,12 @@ func (hst HTTPProxyCheck) Name() string { // Check validates http connectivity type, direct or via proxy. func (hst HTTPProxyCheck) Check() (warnings, errorList []error) { klog.V(1).Infoln("validating if the connectivity type is via proxy or direct") - u := (&url.URL{Scheme: hst.Proto, Host: hst.Host}).String() + u := &url.URL{Scheme: hst.Proto, Host: hst.Host} + if utilsnet.IsIPv6String(hst.Host) { + u.Host = net.JoinHostPort(hst.Host, "1234") + } - req, err := http.NewRequest("GET", u, nil) + req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, []error{err} } diff --git a/cmd/kubeadm/app/preflight/checks_test.go b/cmd/kubeadm/app/preflight/checks_test.go index 60945e08742..5adea3ee433 100644 --- a/cmd/kubeadm/app/preflight/checks_test.go +++ b/cmd/kubeadm/app/preflight/checks_test.go @@ -590,6 +590,22 @@ func TestHTTPProxyCheck(t *testing.T) { }, // Expected to go via proxy, range is not in 2001:db8::/48 expectWarnings: true, }, + { + name: "IPv6 direct access, no brackets", + check: HTTPProxyCheck{ + Proto: "https", + Host: "2001:db8::1:15", + }, // Expected to be accessed directly, part of 2001:db8::/48 in NO_PROXY + expectWarnings: false, + }, + { + name: "IPv6 via proxy, no brackets", + check: HTTPProxyCheck{ + Proto: "https", + Host: "2001:db8:1::1:15", + }, // Expected to go via proxy, range is not in 2001:db8::/48 + expectWarnings: true, + }, } // Save current content of *_proxy and *_PROXY variables.