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
654a8d40
Commit
654a8d40
authored
Mar 23, 2015
by
Piotr Szczesniak
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5772 from a-robinson/lb
Add an end-to-end test for external load balancers.
parents
d8223ff9
22825b10
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
service.go
test/e2e/service.go
+91
-0
No files found.
test/e2e/service.go
View file @
654a8d40
...
...
@@ -18,7 +18,10 @@ package e2e
import
(
"fmt"
"io/ioutil"
"net/http"
"sort"
"strings"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
...
@@ -246,6 +249,94 @@ var _ = Describe("Services", func() {
}()
},
240.0
)
It
(
"should be able to create a functioning external load balancer"
,
func
()
{
serviceName
:=
"external-lb-test"
ns
:=
api
.
NamespaceDefault
labels
:=
map
[
string
]
string
{
"key0"
:
"value0"
,
}
service
:=
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
serviceName
,
},
Spec
:
api
.
ServiceSpec
{
Port
:
80
,
Selector
:
labels
,
TargetPort
:
util
.
NewIntOrStringFromInt
(
80
),
CreateExternalLoadBalancer
:
true
,
},
}
By
(
"cleaning up previous service "
+
serviceName
+
" from namespace "
+
ns
)
c
.
Services
(
ns
)
.
Delete
(
serviceName
)
By
(
"creating service "
+
serviceName
+
" with external load balancer in namespace "
+
ns
)
result
,
err
:=
c
.
Services
(
ns
)
.
Create
(
service
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
defer
func
(
ns
,
serviceName
string
)
{
// clean up when we're done
By
(
"deleting service "
+
serviceName
+
" in namespace "
+
ns
)
err
:=
c
.
Services
(
ns
)
.
Delete
(
serviceName
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
}(
ns
,
serviceName
)
if
len
(
result
.
Spec
.
PublicIPs
)
!=
1
{
Failf
(
"got unexpected number (%d) of public IPs for externally load balanced service: %v"
,
result
.
Spec
.
PublicIPs
,
result
)
}
ip
:=
result
.
Spec
.
PublicIPs
[
0
]
port
:=
result
.
Spec
.
Port
pod
:=
&
api
.
Pod
{
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Pod"
,
APIVersion
:
"v1beta1"
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"elb-test-"
+
string
(
util
.
NewUUID
()),
Labels
:
labels
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"webserver"
,
Image
:
"kubernetes/test-webserver"
,
},
},
},
}
By
(
"creating pod to be part of service "
+
serviceName
)
podClient
:=
c
.
Pods
(
api
.
NamespaceDefault
)
defer
func
()
{
By
(
"deleting pod "
+
pod
.
Name
)
defer
GinkgoRecover
()
podClient
.
Delete
(
pod
.
Name
)
}()
if
_
,
err
:=
podClient
.
Create
(
pod
);
err
!=
nil
{
Failf
(
"Failed to create pod %s: %v"
,
pod
.
Name
,
err
)
}
expectNoError
(
waitForPodRunning
(
c
,
pod
.
Name
))
By
(
"hitting the pod through the service's external load balancer"
)
var
resp
*
http
.
Response
for
t
:=
time
.
Now
();
time
.
Since
(
t
)
<
4
*
time
.
Minute
;
time
.
Sleep
(
5
*
time
.
Second
)
{
resp
,
err
=
http
.
Get
(
fmt
.
Sprintf
(
"http://%s:%d"
,
ip
,
port
))
if
err
==
nil
{
break
}
}
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
if
resp
.
StatusCode
!=
200
{
Failf
(
"received non-success return status %q trying to access pod through load balancer; got body: %s"
,
resp
.
Status
,
string
(
body
))
}
if
!
strings
.
Contains
(
string
(
body
),
"test-webserver"
)
{
Failf
(
"received response body without expected substring 'test-webserver': %s"
,
string
(
body
))
}
})
It
(
"should correctly serve identically named services in different namespaces on different external IP addresses"
,
func
()
{
serviceNames
:=
[]
string
{
"services-namespace-test0"
}
// Could add more here, but then it takes longer.
namespaces
:=
[]
string
{
"namespace0"
,
"namespace1"
}
// As above.
...
...
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