Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4da39ae7
Commit
4da39ae7
authored
Jan 11, 2018
by
Robert Pothier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Kubeadm proxy handling for IPv6
This updates HTTPProxyCheck with brackets around the ipv6 address to handle adding :port
parent
aee2cff1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
25 deletions
+91
-25
checks.go
cmd/kubeadm/app/preflight/checks.go
+3
-3
checks_test.go
cmd/kubeadm/app/preflight/checks_test.go
+88
-22
No files found.
cmd/kubeadm/app/preflight/checks.go
View file @
4da39ae7
...
@@ -425,9 +425,9 @@ func (hst HTTPProxyCheck) Name() string {
...
@@ -425,9 +425,9 @@ func (hst HTTPProxyCheck) Name() string {
// Check validates http connectivity type, direct or via proxy.
// Check validates http connectivity type, direct or via proxy.
func
(
hst
HTTPProxyCheck
)
Check
()
(
warnings
,
errors
[]
error
)
{
func
(
hst
HTTPProxyCheck
)
Check
()
(
warnings
,
errors
[]
error
)
{
u
rl
:=
fmt
.
Sprintf
(
"%s://%s"
,
hst
.
Proto
,
hst
.
Host
)
u
:=
(
&
url
.
URL
{
Scheme
:
hst
.
Proto
,
Host
:
hst
.
Host
})
.
String
(
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
u
rl
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
u
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
[]
error
{
err
}
return
nil
,
[]
error
{
err
}
}
}
...
@@ -437,7 +437,7 @@ func (hst HTTPProxyCheck) Check() (warnings, errors []error) {
...
@@ -437,7 +437,7 @@ func (hst HTTPProxyCheck) Check() (warnings, errors []error) {
return
nil
,
[]
error
{
err
}
return
nil
,
[]
error
{
err
}
}
}
if
proxy
!=
nil
{
if
proxy
!=
nil
{
return
[]
error
{
fmt
.
Errorf
(
"Connection to %q uses proxy %q. If that is not intended, adjust your proxy settings"
,
u
rl
,
proxy
)},
nil
return
[]
error
{
fmt
.
Errorf
(
"Connection to %q uses proxy %q. If that is not intended, adjust your proxy settings"
,
u
,
proxy
)},
nil
}
}
return
nil
,
nil
return
nil
,
nil
}
}
...
...
cmd/kubeadm/app/preflight/checks_test.go
View file @
4da39ae7
...
@@ -504,38 +504,84 @@ func TestHTTPProxyCIDRCheck(t *testing.T) {
...
@@ -504,38 +504,84 @@ func TestHTTPProxyCIDRCheck(t *testing.T) {
}
}
// Save current content of *_proxy and *_PROXY variables.
// Save current content of *_proxy and *_PROXY variables.
savedEnv
:=
resetProxyEnv
()
savedEnv
:=
resetProxyEnv
(
t
)
defer
restoreEnv
(
savedEnv
)
defer
restoreEnv
(
savedEnv
)
t
.
Log
(
"Saved environment: "
,
savedEnv
)
os
.
Setenv
(
"HTTP_PROXY"
,
"http://proxy.example.com:3128"
)
os
.
Setenv
(
"NO_PROXY"
,
"example.com,10.0.0.0/8,2001:db8::/48"
)
// Check if we can reliably execute tests:
for
_
,
rt
:=
range
tests
{
// ProxyFromEnvironment caches the *_proxy environment variables and
warning
,
_
:=
rt
.
check
.
Check
()
// if ProxyFromEnvironment already executed before our test with empty
if
(
warning
!=
nil
)
!=
rt
.
expectWarnings
{
// HTTP_PROXY it will make these tests return false positive failures
t
.
Errorf
(
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"http://host.fake.tld/"
,
nil
)
"failed HTTPProxyCIDRCheck:
\n\t
expected: %t
\n\t
actual: %t (CIDR:%s). Warnings: %v"
,
if
err
!=
nil
{
rt
.
expectWarnings
,
t
.
Fatalf
(
"unexpected err: %v"
,
err
)
(
warning
!=
nil
),
}
rt
.
check
.
CIDR
,
proxy
,
err
:=
http
.
ProxyFromEnvironment
(
req
)
warning
,
if
err
!=
nil
{
)
t
.
Fatalf
(
"unexpected err: %v"
,
err
)
}
}
}
if
proxy
==
nil
{
}
t
.
Skip
(
"test skipped as ProxyFromEnvironment already initialized in environment without defined HTTP proxy"
)
func
TestHTTPProxyCheck
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
name
string
check
HTTPProxyCheck
expectWarnings
bool
}{
{
name
:
"Loopback address"
,
check
:
HTTPProxyCheck
{
Proto
:
"https"
,
Host
:
"127.0.0.1"
,
},
// Loopback addresses never should produce proxy warnings
expectWarnings
:
false
,
},
{
name
:
"IPv4 direct access"
,
check
:
HTTPProxyCheck
{
Proto
:
"https"
,
Host
:
"10.96.0.1"
,
},
// Expected to be accessed directly, we set NO_PROXY to 10.0.0.0/8
expectWarnings
:
false
,
},
{
name
:
"IPv4 via proxy"
,
check
:
HTTPProxyCheck
{
Proto
:
"https"
,
Host
:
"192.168.0.1"
,
},
// Expected to go via proxy as this range is not listed in NO_PROXY
expectWarnings
:
true
,
},
{
name
:
"IPv6 direct access"
,
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"
,
check
:
HTTPProxyCheck
{
Proto
:
"https"
,
Host
:
"[2001:db8:1::1:15]"
,
},
// Expected to go via proxy, range is not in 2001:db8::/48
expectWarnings
:
true
,
},
}
}
t
.
Log
(
"http.ProxyFromEnvironment is usable, continue executing test"
)
// Save current content of *_proxy and *_PROXY variables.
savedEnv
:=
resetProxyEnv
(
t
)
defer
restoreEnv
(
savedEnv
)
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
warning
,
_
:=
rt
.
check
.
Check
()
warning
,
_
:=
rt
.
check
.
Check
()
if
(
warning
!=
nil
)
!=
rt
.
expectWarnings
{
if
(
warning
!=
nil
)
!=
rt
.
expectWarnings
{
t
.
Errorf
(
t
.
Errorf
(
"failed HTTPProxyCIDRCheck:
\n\t
expected: %t
\n\t
actual: %t (CIDR:%s). Warnings: %v"
,
"%s failed HTTPProxyCheck:
\n\t
expected: %t
\n\t
actual: %t (Host:%s). Warnings: %v"
,
rt
.
name
,
rt
.
expectWarnings
,
rt
.
expectWarnings
,
(
warning
!=
nil
),
(
warning
!=
nil
),
rt
.
check
.
CIDR
,
rt
.
check
.
Host
,
warning
,
warning
,
)
)
}
}
...
@@ -545,7 +591,7 @@ func TestHTTPProxyCIDRCheck(t *testing.T) {
...
@@ -545,7 +591,7 @@ func TestHTTPProxyCIDRCheck(t *testing.T) {
// resetProxyEnv is helper function that unsets all *_proxy variables
// resetProxyEnv is helper function that unsets all *_proxy variables
// and return previously set values as map. This can be used to restore
// and return previously set values as map. This can be used to restore
// original state of the environment.
// original state of the environment.
func
resetProxyEnv
()
map
[
string
]
string
{
func
resetProxyEnv
(
t
*
testing
.
T
)
map
[
string
]
string
{
savedEnv
:=
make
(
map
[
string
]
string
)
savedEnv
:=
make
(
map
[
string
]
string
)
for
_
,
e
:=
range
os
.
Environ
()
{
for
_
,
e
:=
range
os
.
Environ
()
{
pair
:=
strings
.
Split
(
e
,
"="
)
pair
:=
strings
.
Split
(
e
,
"="
)
...
@@ -554,6 +600,26 @@ func resetProxyEnv() map[string]string {
...
@@ -554,6 +600,26 @@ func resetProxyEnv() map[string]string {
os
.
Unsetenv
(
pair
[
0
])
os
.
Unsetenv
(
pair
[
0
])
}
}
}
}
t
.
Log
(
"Saved environment: "
,
savedEnv
)
os
.
Setenv
(
"HTTP_PROXY"
,
"http://proxy.example.com:3128"
)
os
.
Setenv
(
"NO_PROXY"
,
"example.com,10.0.0.0/8,2001:db8::/48"
)
// Check if we can reliably execute tests:
// ProxyFromEnvironment caches the *_proxy environment variables and
// if ProxyFromEnvironment already executed before our test with empty
// HTTP_PROXY it will make these tests return false positive failures
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"http://host.fake.tld/"
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected err: %v"
,
err
)
}
proxy
,
err
:=
http
.
ProxyFromEnvironment
(
req
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected err: %v"
,
err
)
}
if
proxy
==
nil
{
t
.
Skip
(
"test skipped as ProxyFromEnvironment already initialized in environment without defined HTTP proxy"
)
}
t
.
Log
(
"http.ProxyFromEnvironment is usable, continue executing test"
)
return
savedEnv
return
savedEnv
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment