From 7fb4a2be41c9b45778c6562e36adc57b78d77c55 Mon Sep 17 00:00:00 2001 From: Alexander Kanevskiy Date: Tue, 3 Sep 2019 15:55:58 +0300 Subject: [PATCH] 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 --- cmd/kubeadm/app/preflight/checks.go | 7 +++++-- cmd/kubeadm/app/preflight/checks_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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.