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
47a802d3
Commit
47a802d3
authored
Jun 16, 2015
by
Saad Ali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9648 from mikedanese/cleanup-service-e2e
cleanup some of the e2e service reachability code
parents
8a2f45b0
145f59f1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
41 deletions
+39
-41
service.go
test/e2e/service.go
+39
-41
No files found.
test/e2e/service.go
View file @
47a802d3
...
@@ -33,6 +33,7 @@ import (
...
@@ -33,6 +33,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
)
)
...
@@ -1002,66 +1003,63 @@ func testLoadBalancerNotReachable(ingress api.LoadBalancerIngress, port int) {
...
@@ -1002,66 +1003,63 @@ func testLoadBalancerNotReachable(ingress api.LoadBalancerIngress, port int) {
}
}
func
testReachable
(
ip
string
,
port
int
)
{
func
testReachable
(
ip
string
,
port
int
)
{
var
err
error
var
resp
*
http
.
Response
url
:=
fmt
.
Sprintf
(
"http://%s:%d"
,
ip
,
port
)
url
:=
fmt
.
Sprintf
(
"http://%s:%d"
,
ip
,
port
)
if
ip
==
""
{
if
ip
==
""
{
Failf
(
"
got empty IP for reachability check
"
,
url
)
Failf
(
"
Got empty IP for reachability check (%s)
"
,
url
)
}
}
if
port
==
0
{
if
port
==
0
{
Failf
(
"
got port==0 for reachability check
"
,
url
)
Failf
(
"
Got port==0 for reachability check (%s)
"
,
url
)
}
}
By
(
fmt
.
Sprintf
(
"Checking reachability of %s"
,
url
))
By
(
fmt
.
Sprintf
(
"Checking reachability of %s"
,
url
))
for
t
:=
time
.
Now
();
time
.
Since
(
t
)
<
podStartTimeout
;
time
.
Sleep
(
5
*
time
.
Second
)
{
expectNoError
(
wait
.
Poll
(
poll
,
podStartTimeout
,
func
()
(
bool
,
error
)
{
resp
,
err
=
httpGetNoConnectionPool
(
url
)
resp
,
err
:=
httpGetNoConnectionPool
(
url
)
if
err
==
nil
{
if
err
!=
nil
{
break
Logf
(
"Got error waiting for reachability of %s: %v"
,
url
,
err
)
return
false
,
nil
}
}
By
(
fmt
.
Sprintf
(
"Got error waiting for reachability of %s: %v"
,
url
,
err
))
defer
resp
.
Body
.
Close
()
}
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
if
err
!=
nil
{
defer
resp
.
Body
.
Close
()
Logf
(
"Got error reading response from %s: %v"
,
url
,
err
)
return
false
,
nil
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
}
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
if
resp
.
StatusCode
!=
200
{
if
resp
.
StatusCode
!=
200
{
return
false
,
fmt
.
Errorf
(
"received non-success return status %q trying to access %s; got body: %s"
,
resp
.
Status
,
url
,
string
(
body
))
Failf
(
"received non-success return status %q trying to access %s; got body: %s"
,
resp
.
Status
,
url
,
string
(
body
))
}
}
if
!
strings
.
Contains
(
string
(
body
),
"test-webserver"
)
{
if
!
strings
.
Contains
(
string
(
body
),
"test-webserver"
)
{
return
false
,
fmt
.
Errorf
(
"received response body without expected substring 'test-webserver': %s"
,
string
(
body
))
Failf
(
"received response body without expected substring 'test-webserver': %s"
,
string
(
body
))
}
}
Logf
(
"Successfully reached %v"
,
url
)
return
true
,
nil
}))
}
}
func
testNotReachable
(
ip
string
,
port
int
)
{
func
testNotReachable
(
ip
string
,
port
int
)
{
var
err
error
var
resp
*
http
.
Response
var
body
[]
byte
url
:=
fmt
.
Sprintf
(
"http://%s:%d"
,
ip
,
port
)
url
:=
fmt
.
Sprintf
(
"http://%s:%d"
,
ip
,
port
)
if
ip
==
""
{
if
ip
==
""
{
Failf
(
"
got empty IP for non-reachability check
"
,
url
)
Failf
(
"
Got empty IP for non-reachability check (%s)
"
,
url
)
}
}
if
port
==
0
{
if
port
==
0
{
Failf
(
"
got port==0 for non-reachability check
"
,
url
)
Failf
(
"
Got port==0 for non-reachability check (%s)
"
,
url
)
}
}
for
t
:=
time
.
Now
();
time
.
Since
(
t
)
<
podStartTimeout
;
time
.
Sleep
(
5
*
time
.
Second
)
{
By
(
fmt
.
Sprintf
(
"Checking that %s is not reachable"
,
url
))
resp
,
err
=
httpGetNoConnectionPool
(
url
)
expectNoError
(
wait
.
Poll
(
poll
,
podStartTimeout
,
func
()
(
bool
,
error
)
{
resp
,
err
:=
httpGetNoConnectionPool
(
url
)
if
err
!=
nil
{
if
err
!=
nil
{
break
Logf
(
"Successfully waited for the url %s to be unreachable."
,
url
)
return
true
,
nil
}
}
body
,
err
=
ioutil
.
ReadAll
(
resp
.
Body
)
defer
resp
.
Body
.
Close
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
resp
.
Body
.
Close
()
if
err
!=
nil
{
By
(
fmt
.
Sprintf
(
"Got success waiting for non-reachability of %s: %v"
,
url
,
resp
.
Status
))
Logf
(
"Expecting %s to be unreachable but was reachable and got an error reading response: %v"
,
url
,
err
)
}
return
false
,
nil
if
err
==
nil
{
}
Failf
(
"able to reach service %s when should no longer have been reachable: %q body=%s"
,
url
,
resp
.
Status
,
string
(
body
))
Logf
(
"Able to reach service %s when should no longer have been reachable, status:%d and body: %s"
,
url
,
resp
.
Status
,
string
(
body
))
}
return
false
,
nil
// TODO: Check type of error
}))
By
(
fmt
.
Sprintf
(
"Found (expected) error during not-reachability test %v"
,
err
))
}
}
// Does an HTTP GET, but does not reuse TCP connections
// Does an HTTP GET, but does not reuse TCP connections
...
...
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