Skip to content

Commit 7fb4a2b

Browse files
committed
kubeadm: Form correct URL for IPv6 in HTTPProxy check
Force correct syntax on host/port in URL of HTTPProxy check if the host argument is a raw IPv6 address string
1 parent c7c89f8 commit 7fb4a2b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cmd/kubeadm/app/preflight/checks.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,12 @@ func (hst HTTPProxyCheck) Name() string {
431431
// Check validates http connectivity type, direct or via proxy.
432432
func (hst HTTPProxyCheck) Check() (warnings, errorList []error) {
433433
klog.V(1).Infoln("validating if the connectivity type is via proxy or direct")
434-
u := (&url.URL{Scheme: hst.Proto, Host: hst.Host}).String()
434+
u := &url.URL{Scheme: hst.Proto, Host: hst.Host}
435+
if utilsnet.IsIPv6String(hst.Host) {
436+
u.Host = net.JoinHostPort(hst.Host, "1234")
437+
}
435438

436-
req, err := http.NewRequest("GET", u, nil)
439+
req, err := http.NewRequest("GET", u.String(), nil)
437440
if err != nil {
438441
return nil, []error{err}
439442
}

cmd/kubeadm/app/preflight/checks_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,22 @@ func TestHTTPProxyCheck(t *testing.T) {
590590
}, // Expected to go via proxy, range is not in 2001:db8::/48
591591
expectWarnings: true,
592592
},
593+
{
594+
name: "IPv6 direct access, no brackets",
595+
check: HTTPProxyCheck{
596+
Proto: "https",
597+
Host: "2001:db8::1:15",
598+
}, // Expected to be accessed directly, part of 2001:db8::/48 in NO_PROXY
599+
expectWarnings: false,
600+
},
601+
{
602+
name: "IPv6 via proxy, no brackets",
603+
check: HTTPProxyCheck{
604+
Proto: "https",
605+
Host: "2001:db8:1::1:15",
606+
}, // Expected to go via proxy, range is not in 2001:db8::/48
607+
expectWarnings: true,
608+
},
593609
}
594610

595611
// Save current content of *_proxy and *_PROXY variables.

0 commit comments

Comments
 (0)