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
8ffc8ef4
Unverified
Commit
8ffc8ef4
authored
Dec 03, 2018
by
Kubernetes Prow Robot
Committed by
GitHub
Dec 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #68663 from WanLinghao/probe_proxy
Disable proxy use in http probe
parents
f5e98aa6
29f7e537
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
http.go
pkg/probe/http/http.go
+7
-1
http_test.go
pkg/probe/http/http_test.go
+57
-0
No files found.
pkg/probe/http/http.go
View file @
8ffc8ef4
...
...
@@ -39,7 +39,13 @@ func New() Prober {
// NewWithTLSConfig takes tls config as parameter.
func
NewWithTLSConfig
(
config
*
tls
.
Config
)
Prober
{
transport
:=
utilnet
.
SetTransportDefaults
(
&
http
.
Transport
{
TLSClientConfig
:
config
,
DisableKeepAlives
:
true
})
// We do not want the probe use node's local proxy set.
transport
:=
utilnet
.
SetTransportDefaults
(
&
http
.
Transport
{
TLSClientConfig
:
config
,
DisableKeepAlives
:
true
,
Proxy
:
http
.
ProxyURL
(
nil
),
})
return
httpProber
{
transport
}
}
...
...
pkg/probe/http/http_test.go
View file @
8ffc8ef4
...
...
@@ -22,6 +22,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"strconv"
"strings"
"testing"
...
...
@@ -32,6 +33,62 @@ import (
const
FailureCode
int
=
-
1
func
setEnv
(
key
,
value
string
)
func
()
{
originalValue
:=
os
.
Getenv
(
key
)
os
.
Setenv
(
key
,
value
)
if
len
(
originalValue
)
>
0
{
return
func
()
{
os
.
Setenv
(
key
,
originalValue
)
}
}
return
func
()
{}
}
func
unsetEnv
(
key
string
)
func
()
{
originalValue
:=
os
.
Getenv
(
key
)
os
.
Unsetenv
(
key
)
if
len
(
originalValue
)
>
0
{
return
func
()
{
os
.
Setenv
(
key
,
originalValue
)
}
}
return
func
()
{}
}
func
TestHTTPProbeProxy
(
t
*
testing
.
T
)
{
res
:=
"welcome to http probe proxy"
localProxy
:=
"http://127.0.0.1:9098/"
defer
setEnv
(
"http_proxy"
,
localProxy
)()
defer
setEnv
(
"HTTP_PROXY"
,
localProxy
)()
defer
unsetEnv
(
"no_proxy"
)()
defer
unsetEnv
(
"NO_PROXY"
)()
prober
:=
New
()
go
func
()
{
http
.
HandleFunc
(
"/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
fmt
.
Fprintf
(
w
,
res
)
})
err
:=
http
.
ListenAndServe
(
":9098"
,
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to start foo server: localhost:9098"
)
}
}()
// take some time to wait server boot
time
.
Sleep
(
2
*
time
.
Second
)
url
,
err
:=
url
.
Parse
(
"http://example.com"
)
if
err
!=
nil
{
t
.
Errorf
(
"proxy test unexpected error: %v"
,
err
)
}
_
,
response
,
_
:=
prober
.
Probe
(
url
,
http
.
Header
{},
time
.
Second
*
3
)
if
response
==
res
{
t
.
Errorf
(
"proxy test unexpected error: the probe is using proxy"
)
}
}
func
TestHTTPProbeChecker
(
t
*
testing
.
T
)
{
handleReq
:=
func
(
s
int
,
body
string
)
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
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