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
79ce4cb6
Commit
79ce4cb6
authored
Jan 11, 2017
by
shashidharatd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move some common functions in e2e to e2e.framework for reusability
parent
62c92678
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
62 deletions
+62
-62
util.go
test/e2e/framework/util.go
+52
-0
ingress.go
test/e2e/ingress.go
+4
-4
ingress_utils.go
test/e2e/ingress_utils.go
+5
-32
serviceloadbalancers.go
test/e2e/serviceloadbalancers.go
+1
-26
No files found.
test/e2e/framework/util.go
View file @
79ce4cb6
...
...
@@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"net/http"
...
...
@@ -5300,3 +5301,54 @@ func RcByNameContainer(name string, replicas int32, image string, labels map[str
},
}
}
// SimpleGET executes a get on the given url, returns error if non-200 returned.
func
SimpleGET
(
c
*
http
.
Client
,
url
,
host
string
)
(
string
,
error
)
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
return
""
,
err
}
req
.
Host
=
host
res
,
err
:=
c
.
Do
(
req
)
if
err
!=
nil
{
return
""
,
err
}
defer
res
.
Body
.
Close
()
rawBody
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
if
err
!=
nil
{
return
""
,
err
}
body
:=
string
(
rawBody
)
if
res
.
StatusCode
!=
http
.
StatusOK
{
err
=
fmt
.
Errorf
(
"GET returned http error %v"
,
res
.
StatusCode
)
}
return
body
,
err
}
// PollURL polls till the url responds with a healthy http code. If
// expectUnreachable is true, it breaks on first non-healthy http code instead.
func
PollURL
(
route
,
host
string
,
timeout
time
.
Duration
,
interval
time
.
Duration
,
httpClient
*
http
.
Client
,
expectUnreachable
bool
)
error
{
var
lastBody
string
pollErr
:=
wait
.
PollImmediate
(
interval
,
timeout
,
func
()
(
bool
,
error
)
{
var
err
error
lastBody
,
err
=
SimpleGET
(
httpClient
,
route
,
host
)
if
err
!=
nil
{
Logf
(
"host %v path %v: %v unreachable"
,
host
,
route
,
err
)
return
expectUnreachable
,
nil
}
return
!
expectUnreachable
,
nil
})
if
pollErr
!=
nil
{
return
fmt
.
Errorf
(
"Failed to execute a successful GET within %v, Last response body for %v, host %v:
\n
%v
\n\n
%v
\n
"
,
timeout
,
route
,
host
,
lastBody
,
pollErr
)
}
return
nil
}
func
DescribeIng
(
ns
string
)
{
Logf
(
"
\n
Output of kubectl describe ing:
\n
"
)
desc
,
_
:=
RunKubectl
(
"describe"
,
"ing"
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
))
Logf
(
desc
)
}
test/e2e/ingress.go
View file @
79ce4cb6
...
...
@@ -102,7 +102,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7", func() {
// Platform specific cleanup
AfterEach
(
func
()
{
if
CurrentGinkgoTestDescription
()
.
Failed
{
d
escribeIng
(
ns
)
framework
.
D
escribeIng
(
ns
)
}
if
jig
.
ing
==
nil
{
By
(
"No ingress created, no cleanup necessary"
)
...
...
@@ -137,10 +137,10 @@ var _ = framework.KubeDescribe("Loadbalancing: L7", func() {
By
(
"waiting for Ingress to come up with ip: "
+
ip
)
httpClient
:=
buildInsecureClient
(
reqTimeout
)
framework
.
ExpectNoError
(
p
ollURL
(
fmt
.
Sprintf
(
"https://%v/"
,
ip
),
""
,
framework
.
LoadBalancerPollTimeout
,
jig
.
pollInterval
,
httpClient
,
false
))
framework
.
ExpectNoError
(
framework
.
P
ollURL
(
fmt
.
Sprintf
(
"https://%v/"
,
ip
),
""
,
framework
.
LoadBalancerPollTimeout
,
jig
.
pollInterval
,
httpClient
,
false
))
By
(
"should reject HTTP traffic"
)
framework
.
ExpectNoError
(
p
ollURL
(
fmt
.
Sprintf
(
"http://%v/"
,
ip
),
""
,
framework
.
LoadBalancerPollTimeout
,
jig
.
pollInterval
,
httpClient
,
true
))
framework
.
ExpectNoError
(
framework
.
P
ollURL
(
fmt
.
Sprintf
(
"http://%v/"
,
ip
),
""
,
framework
.
LoadBalancerPollTimeout
,
jig
.
pollInterval
,
httpClient
,
true
))
By
(
"should have correct firewall rule for ingress"
)
fw
:=
gceController
.
getFirewallRule
()
...
...
@@ -192,7 +192,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7", func() {
framework
.
ExpectNoError
(
gcloudDelete
(
"firewall-rules"
,
fmt
.
Sprintf
(
"ingress-80-443-%v"
,
ns
),
framework
.
TestContext
.
CloudConfig
.
ProjectID
))
}
if
CurrentGinkgoTestDescription
()
.
Failed
{
d
escribeIng
(
ns
)
framework
.
D
escribeIng
(
ns
)
}
if
jig
.
ing
==
nil
{
By
(
"No ingress created, no cleanup necessary"
)
...
...
test/e2e/ingress_utils.go
View file @
79ce4cb6
...
...
@@ -181,33 +181,13 @@ func createComformanceTests(jig *testJig, ns string) []conformanceTests {
})
By
(
"Checking that "
+
pathToFail
+
" is not exposed by polling for failure"
)
route
:=
fmt
.
Sprintf
(
"http://%v%v"
,
jig
.
address
,
pathToFail
)
framework
.
ExpectNoError
(
p
ollURL
(
route
,
updateURLMapHost
,
framework
.
LoadBalancerCleanupTimeout
,
jig
.
pollInterval
,
&
http
.
Client
{
Timeout
:
reqTimeout
},
true
))
framework
.
ExpectNoError
(
framework
.
P
ollURL
(
route
,
updateURLMapHost
,
framework
.
LoadBalancerCleanupTimeout
,
jig
.
pollInterval
,
&
http
.
Client
{
Timeout
:
reqTimeout
},
true
))
},
fmt
.
Sprintf
(
"Waiting for path updates to reflect in L7"
),
},
}
}
// pollURL polls till the url responds with a healthy http code. If
// expectUnreachable is true, it breaks on first non-healthy http code instead.
func
pollURL
(
route
,
host
string
,
timeout
time
.
Duration
,
interval
time
.
Duration
,
httpClient
*
http
.
Client
,
expectUnreachable
bool
)
error
{
var
lastBody
string
pollErr
:=
wait
.
PollImmediate
(
interval
,
timeout
,
func
()
(
bool
,
error
)
{
var
err
error
lastBody
,
err
=
simpleGET
(
httpClient
,
route
,
host
)
if
err
!=
nil
{
framework
.
Logf
(
"host %v path %v: %v unreachable"
,
host
,
route
,
err
)
return
expectUnreachable
,
nil
}
return
!
expectUnreachable
,
nil
})
if
pollErr
!=
nil
{
return
fmt
.
Errorf
(
"Failed to execute a successful GET within %v, Last response body for %v, host %v:
\n
%v
\n\n
%v
\n
"
,
timeout
,
route
,
host
,
lastBody
,
pollErr
)
}
return
nil
}
// generateRSACerts generates a basic self signed certificate using a key length
// of rsaBits, valid for validFor time.
func
generateRSACerts
(
host
string
,
isCA
bool
,
keyOut
,
certOut
io
.
Writer
)
error
{
...
...
@@ -327,13 +307,6 @@ func createSecret(kubeClient clientset.Interface, ing *extensions.Ingress) (host
return
host
,
cert
,
key
,
err
}
func
describeIng
(
ns
string
)
{
framework
.
Logf
(
"
\n
Output of kubectl describe ing:
\n
"
)
desc
,
_
:=
framework
.
RunKubectl
(
"describe"
,
"ing"
,
fmt
.
Sprintf
(
"--namespace=%v"
,
ns
))
framework
.
Logf
(
desc
)
}
func
cleanupGCE
(
gceController
*
GCEIngressController
)
{
pollErr
:=
wait
.
Poll
(
5
*
time
.
Second
,
framework
.
LoadBalancerCleanupTimeout
,
func
()
(
bool
,
error
)
{
if
err
:=
gceController
.
Cleanup
(
false
);
err
!=
nil
{
...
...
@@ -821,7 +794,7 @@ func (j *testJig) update(update func(ing *extensions.Ingress)) {
update
(
j
.
ing
)
j
.
ing
,
err
=
j
.
client
.
Extensions
()
.
Ingresses
(
ns
)
.
Update
(
j
.
ing
)
if
err
==
nil
{
d
escribeIng
(
j
.
ing
.
Namespace
)
framework
.
D
escribeIng
(
j
.
ing
.
Namespace
)
return
}
if
!
apierrs
.
IsConflict
(
err
)
&&
!
apierrs
.
IsServerTimeout
(
err
)
{
...
...
@@ -889,7 +862,7 @@ func (j *testJig) waitForIngress(waitForNodePort bool) {
}
route
:=
fmt
.
Sprintf
(
"%v://%v%v"
,
proto
,
address
,
p
.
Path
)
framework
.
Logf
(
"Testing route %v host %v with simple GET"
,
route
,
rules
.
Host
)
framework
.
ExpectNoError
(
p
ollURL
(
route
,
rules
.
Host
,
framework
.
LoadBalancerPollTimeout
,
j
.
pollInterval
,
timeoutClient
,
false
))
framework
.
ExpectNoError
(
framework
.
P
ollURL
(
route
,
rules
.
Host
,
framework
.
LoadBalancerPollTimeout
,
j
.
pollInterval
,
timeoutClient
,
false
))
}
}
}
...
...
@@ -898,7 +871,7 @@ func (j *testJig) waitForIngress(waitForNodePort bool) {
// given url returns a non-healthy http code even once.
func
(
j
*
testJig
)
verifyURL
(
route
,
host
string
,
iterations
int
,
interval
time
.
Duration
,
httpClient
*
http
.
Client
)
error
{
for
i
:=
0
;
i
<
iterations
;
i
++
{
b
,
err
:=
s
impleGET
(
httpClient
,
route
,
host
)
b
,
err
:=
framework
.
S
impleGET
(
httpClient
,
route
,
host
)
if
err
!=
nil
{
framework
.
Logf
(
b
)
return
err
...
...
@@ -913,7 +886,7 @@ func (j *testJig) curlServiceNodePort(ns, name string, port int) {
// TODO: Curl all nodes?
u
,
err
:=
framework
.
GetNodePortURL
(
j
.
client
,
ns
,
name
,
port
)
framework
.
ExpectNoError
(
err
)
framework
.
ExpectNoError
(
p
ollURL
(
u
,
""
,
30
*
time
.
Second
,
j
.
pollInterval
,
&
http
.
Client
{
Timeout
:
reqTimeout
},
false
))
framework
.
ExpectNoError
(
framework
.
P
ollURL
(
u
,
""
,
30
*
time
.
Second
,
j
.
pollInterval
,
&
http
.
Client
{
Timeout
:
reqTimeout
},
false
))
}
// getIngressNodePorts returns all related backend services' nodePorts.
...
...
test/e2e/serviceloadbalancers.go
View file @
79ce4cb6
...
...
@@ -18,7 +18,6 @@ package e2e
import
(
"fmt"
"io/ioutil"
"net/http"
"k8s.io/apimachinery/pkg/labels"
...
...
@@ -197,7 +196,7 @@ func (s *ingManager) test(path string) error {
url
:=
fmt
.
Sprintf
(
"%v/hostName"
,
path
)
httpClient
:=
&
http
.
Client
{}
return
wait
.
Poll
(
pollInterval
,
framework
.
ServiceRespondingTimeout
,
func
()
(
bool
,
error
)
{
body
,
err
:=
s
impleGET
(
httpClient
,
url
,
""
)
body
,
err
:=
framework
.
S
impleGET
(
httpClient
,
url
,
""
)
if
err
!=
nil
{
framework
.
Logf
(
"%v
\n
%v
\n
%v"
,
url
,
body
,
err
)
return
false
,
nil
...
...
@@ -239,30 +238,6 @@ var _ = framework.KubeDescribe("ServiceLoadBalancer [Feature:ServiceLoadBalancer
})
})
// simpleGET executes a get on the given url, returns error if non-200 returned.
func
simpleGET
(
c
*
http
.
Client
,
url
,
host
string
)
(
string
,
error
)
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
return
""
,
err
}
req
.
Host
=
host
res
,
err
:=
c
.
Do
(
req
)
if
err
!=
nil
{
return
""
,
err
}
defer
res
.
Body
.
Close
()
rawBody
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
if
err
!=
nil
{
return
""
,
err
}
body
:=
string
(
rawBody
)
if
res
.
StatusCode
!=
http
.
StatusOK
{
err
=
fmt
.
Errorf
(
"GET returned http error %v"
,
res
.
StatusCode
)
}
return
body
,
err
}
// rcFromManifest reads a .json/yaml file and returns the rc in it.
func
rcFromManifest
(
fileName
string
)
*
v1
.
ReplicationController
{
var
controller
v1
.
ReplicationController
...
...
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