Skip to content

Commit

Permalink
kubeadm: Form correct URL for IPv6 in HTTPProxy check
Browse files Browse the repository at this point in the history
Force correct syntax on host/port in URL of HTTPProxy check
if the host argument is a raw IPv6 address string
  • Loading branch information
kad committed Sep 3, 2019
1 parent c7c89f8 commit 7fb4a2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/kubeadm/app/preflight/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/kubeadm/app/preflight/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7fb4a2b

Please sign in to comment.