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
f387c511
Commit
f387c511
authored
Feb 10, 2015
by
Filipe Brandenburger
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4269 from zmerlynn/port_endpoints
Port TestBasic & TestPrivate to Ginkgo
parents
ef71b430
7efc6058
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
117 deletions
+49
-117
private.go
test/e2e/private.go
+0
-46
rc.go
test/e2e/rc.go
+49
-71
No files found.
test/e2e/private.go
deleted
100644 → 0
View file @
ef71b430
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
e2e
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/golang/glog"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
// A basic test to check the deployment of the
// contaier gcr.io/_b_k8s_test/serve_hostname image
// with the TestBasicImage test. This test is only supported
// for the providers GCE and GKE.
func
TestPrivate
(
c
*
client
.
Client
)
bool
{
if
testContext
.
provider
!=
"gce"
&&
testContext
.
provider
!=
"gke"
&&
testContext
.
provider
!=
"aws"
{
glog
.
Infof
(
"Skipping test private which is only supported for providers gce, gke and aws (not %s)"
,
testContext
.
provider
)
return
true
}
glog
.
Info
(
"Calling out to TestBasic"
)
return
TestBasicImage
(
c
,
"private"
,
"gcr.io/_b_k8s_test/serve_hostname:1.0"
)
}
var
_
=
Describe
(
"TestPrivate"
,
func
()
{
It
(
"should pass"
,
func
()
{
c
,
err
:=
loadClient
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
TestPrivate
(
c
))
.
To
(
BeTrue
())
})
})
test/e2e/
basi
c.go
→
test/e2e/
r
c.go
View file @
f387c511
...
@@ -26,17 +26,39 @@ import (
...
@@ -26,17 +26,39 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"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/golang/glog"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
)
)
var
_
=
Describe
(
"ReplicationController"
,
func
()
{
var
c
*
client
.
Client
BeforeEach
(
func
()
{
var
err
error
c
,
err
=
loadClient
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
})
It
(
"should serve a basic image on each replica with a public image"
,
func
()
{
ServeImageOrFail
(
c
,
"basic"
,
"kubernetes/serve_hostname:1.1"
)
})
It
(
"should serve a basic image on each replica with a private image"
,
func
()
{
switch
testContext
.
provider
{
case
"gce"
,
"gke"
,
"aws"
:
ServeImageOrFail
(
c
,
"private"
,
"gcr.io/_b_k8s_test/serve_hostname:1.0"
)
default
:
By
(
fmt
.
Sprintf
(
"Skipping private variant, which is only supported for providers gce, gke and aws (not %s)"
,
testContext
.
provider
))
}
})
})
// A basic test to check the deployment of an image using
// A basic test to check the deployment of an image using
// a replication controller. The image serves its hostname
// a replication controller. The image serves its hostname
// which is checked for each replica.
// which is checked for each replica.
func
TestBasicImage
(
c
*
client
.
Client
,
test
string
,
image
string
)
bool
{
func
ServeImageOrFail
(
c
*
client
.
Client
,
test
string
,
image
string
)
{
testStart
:=
time
.
Now
()
ns
:=
api
.
NamespaceDefault
ns
:=
api
.
NamespaceDefault
name
:=
"my-hostname-"
+
test
+
"-"
+
string
(
util
.
NewUUID
())
name
:=
"my-hostname-"
+
test
+
"-"
+
string
(
util
.
NewUUID
())
replicas
:=
2
replicas
:=
2
...
@@ -45,7 +67,7 @@ func TestBasicImage(c *client.Client, test string, image string) bool {
...
@@ -45,7 +67,7 @@ func TestBasicImage(c *client.Client, test string, image string) bool {
// that serves its hostname on port 8080.
// that serves its hostname on port 8080.
// The source for the Docker containter kubernetes/serve_hostname is
// The source for the Docker containter kubernetes/serve_hostname is
// in contrib/for-demos/serve_hostname
// in contrib/for-demos/serve_hostname
glog
.
Infof
(
"Creating replication controller %s"
,
name
)
By
(
fmt
.
Sprintf
(
"Creating replication controller %s"
,
name
)
)
controller
,
err
:=
c
.
ReplicationControllers
(
ns
)
.
Create
(
&
api
.
ReplicationController
{
controller
,
err
:=
c
.
ReplicationControllers
(
ns
)
.
Create
(
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Name
:
name
,
...
@@ -71,63 +93,47 @@ func TestBasicImage(c *client.Client, test string, image string) bool {
...
@@ -71,63 +93,47 @@ func TestBasicImage(c *client.Client, test string, image string) bool {
},
},
},
},
})
})
if
err
!=
nil
{
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
glog
.
Infof
(
"Failed to create replication controller %s: %v"
,
name
,
err
)
return
false
}
// Cleanup the replication controller when we are done.
// Cleanup the replication controller when we are done.
defer
func
()
{
defer
func
()
{
// Resize the replication controller to zero to get rid of pods.
// Resize the replication controller to zero to get rid of pods.
controller
.
Spec
.
Replicas
=
0
controller
.
Spec
.
Replicas
=
0
if
_
,
err
=
c
.
ReplicationControllers
(
ns
)
.
Update
(
controller
);
err
!=
nil
{
if
_
,
err
=
c
.
ReplicationControllers
(
ns
)
.
Update
(
controller
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to resize replication controller %s to zero: %v"
,
name
,
err
)
By
(
fmt
.
Sprintf
(
"Failed to resize replication controller %s to zero: %v"
,
name
,
err
)
)
}
}
// Delete the replication controller.
// Delete the replication controller.
if
err
=
c
.
ReplicationControllers
(
ns
)
.
Delete
(
name
);
err
!=
nil
{
if
err
=
c
.
ReplicationControllers
(
ns
)
.
Delete
(
name
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to delete replication controller %s: %v"
,
name
,
err
)
By
(
fmt
.
Sprintf
(
"Failed to delete replication controller %s: %v"
,
name
,
err
)
)
}
}
// Report running time for test.
glog
.
Infof
(
"Controller %s test took %v seconds"
,
name
,
time
.
Since
(
testStart
)
.
Seconds
())
}()
}()
// List the pods, making sure we observe all the replicas.
// List the pods, making sure we observe all the replicas.
listTimeout
:=
time
.
Minute
listTimeout
:=
time
.
Minute
label
:=
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"name"
:
name
}))
label
:=
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"name"
:
name
}))
pods
,
err
:=
c
.
Pods
(
ns
)
.
List
(
label
)
pods
,
err
:=
c
.
Pods
(
ns
)
.
List
(
label
)
if
err
!=
nil
{
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
glog
.
Errorf
(
"Controller %s: Failed to list pods: %v"
,
name
,
err
)
}
t
:=
time
.
Now
()
t
:=
time
.
Now
()
for
{
for
{
glog
.
Infof
(
"Controller %s: Found %d pods out of %d"
,
name
,
len
(
pods
.
Items
),
replicas
)
By
(
fmt
.
Sprintf
(
"Controller %s: Found %d pods out of %d"
,
name
,
len
(
pods
.
Items
),
replicas
)
)
if
len
(
pods
.
Items
)
==
replicas
{
if
len
(
pods
.
Items
)
==
replicas
{
break
break
}
}
if
time
.
Since
(
t
)
>
listTimeout
{
if
time
.
Since
(
t
)
>
listTimeout
{
glog
.
Errorf
(
"Controller %s: Gave up waiting for %d pods to come up after seeing only %d pods after %v seconds"
,
Fail
(
fmt
.
Sprintf
(
name
,
replicas
,
len
(
pods
.
Items
),
time
.
Since
(
t
)
.
Seconds
())
"Controller %s: Gave up waiting for %d pods to come up after seeing only %d pods after %v seconds"
,
return
false
name
,
replicas
,
len
(
pods
.
Items
),
time
.
Since
(
t
)
.
Seconds
()))
}
}
time
.
Sleep
(
10
*
time
.
Second
)
time
.
Sleep
(
5
*
time
.
Second
)
pods
,
err
=
c
.
Pods
(
ns
)
.
List
(
label
)
pods
,
err
=
c
.
Pods
(
ns
)
.
List
(
label
)
if
err
!=
nil
{
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
glog
.
Errorf
(
"Controller %s: Failed to list pods: %v"
,
name
,
err
)
}
}
}
for
i
,
pod
:=
range
pods
.
Items
{
glog
.
Infof
(
"Controller %s: Replica %d: pod: %s hostPort: %s
\n
"
,
name
,
i
+
1
,
pod
.
Name
,
pod
.
Status
.
HostIP
)
}
// Wait for the pods to enter the running state. Waiting loops until the pods
// Wait for the pods to enter the running state. Waiting loops until the pods
// are running so non-running pods cause a timeout for this test.
// are running so non-running pods cause a timeout for this test.
for
_
,
pod
:=
range
pods
.
Items
{
for
_
,
pod
:=
range
pods
.
Items
{
err
=
waitForPodRunning
(
c
,
pod
.
Name
,
300
*
time
.
Second
)
err
=
waitForPodRunning
(
c
,
pod
.
Name
,
300
*
time
.
Second
)
if
err
!=
nil
{
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
glog
.
Errorf
(
"waitForPodRunningFailed: %v"
,
err
.
Error
())
return
false
}
}
}
// Try to make sure we get a hostIP for each pod.
// Try to make sure we get a hostIP for each pod.
...
@@ -136,71 +142,43 @@ func TestBasicImage(c *client.Client, test string, image string) bool {
...
@@ -136,71 +142,43 @@ func TestBasicImage(c *client.Client, test string, image string) bool {
for
i
,
pod
:=
range
pods
.
Items
{
for
i
,
pod
:=
range
pods
.
Items
{
for
{
for
{
p
,
err
:=
c
.
Pods
(
ns
)
.
Get
(
pod
.
Name
)
p
,
err
:=
c
.
Pods
(
ns
)
.
Get
(
pod
.
Name
)
if
err
!=
nil
{
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
glog
.
Errorf
(
"Controller %s: Failed to get status for pod %s: %v"
,
name
,
pod
.
Name
,
err
)
return
false
}
if
p
.
Status
.
HostIP
!=
""
{
if
p
.
Status
.
HostIP
!=
""
{
glog
.
Infof
(
"Controller %s: Replica %d has hostIP: %s"
,
name
,
i
+
1
,
p
.
Status
.
HostIP
)
By
(
fmt
.
Sprintf
(
"Controller %s: Replica %d has hostIP: %s"
,
name
,
i
+
1
,
p
.
Status
.
HostIP
)
)
break
break
}
}
if
time
.
Since
(
t
)
>=
hostIPTimeout
{
if
time
.
Since
(
t
)
>=
hostIPTimeout
{
glog
.
Errorf
(
"Controller %s: Gave up waiting for hostIP of replica %d after %v seconds"
,
Fail
(
fmt
.
Sprintf
(
"Controller %s: Gave up waiting for hostIP of replica %d after %v seconds"
,
name
,
i
,
time
.
Since
(
t
)
.
Seconds
())
name
,
i
,
time
.
Since
(
t
)
.
Seconds
()))
return
false
}
}
glog
.
Infof
(
"Controller %s: Retrying to get the hostIP of replica %d"
,
name
,
i
+
1
)
By
(
fmt
.
Sprintf
(
"Controller %s: Retrying to get the hostIP of replica %d"
,
name
,
i
+
1
)
)
time
.
Sleep
(
5
*
time
.
Second
)
time
.
Sleep
(
5
*
time
.
Second
)
}
}
}
}
// Re-fetch the pod information to update the host port information.
// Re-fetch the pod information to update the host port information.
pods
,
err
=
c
.
Pods
(
ns
)
.
List
(
label
)
pods
,
err
=
c
.
Pods
(
ns
)
.
List
(
label
)
if
err
!=
nil
{
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
glog
.
Errorf
(
"Controller %s: Failed to list pods: %v"
,
name
,
err
)
}
// Verify that something is listening.
// Verify that something is listening.
for
i
,
pod
:=
range
pods
.
Items
{
for
i
,
pod
:=
range
pods
.
Items
{
glog
.
Infof
(
"Pod: %s hostIP: %s"
,
pod
.
Name
,
pod
.
Status
.
HostIP
)
resp
,
err
:=
http
.
Get
(
fmt
.
Sprintf
(
"http://%s:8080"
,
pod
.
Status
.
HostIP
))
resp
,
err
:=
http
.
Get
(
fmt
.
Sprintf
(
"http://%s:8080"
,
pod
.
Status
.
HostIP
))
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Controller %s: Failed to GET from replica %d: %v"
,
name
,
i
+
1
,
err
)
Fail
(
fmt
.
Sprintf
(
"Controller %s: Failed to GET from replica %d: %v"
,
name
,
i
+
1
,
err
))
return
false
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
http
.
StatusOK
{
if
resp
.
StatusCode
!=
http
.
StatusOK
{
glog
.
Errorf
(
"Controller %s: Expected OK status code for replica %d but got %d"
,
name
,
i
+
1
,
resp
.
StatusCode
)
Fail
(
fmt
.
Sprintf
(
"Controller %s: Expected OK status code for replica %d but got %d"
,
name
,
i
+
1
,
resp
.
StatusCode
))
return
false
}
}
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Controller %s: Failed to read the body of the GET response from replica %d: %v"
,
Fail
(
fmt
.
Sprintf
(
"Controller %s: Failed to read the body of the GET response from replica %d: %v"
,
name
,
i
+
1
,
err
)
name
,
i
+
1
,
err
))
return
false
}
}
// The body should be the pod name.
// The body should be the pod name.
if
string
(
body
)
!=
pod
.
Name
{
if
string
(
body
)
!=
pod
.
Name
{
glog
.
Errorf
(
"Controller %s: Replica %d expected response %s but got %s"
,
Fail
(
fmt
.
Sprintf
(
"Controller %s: Replica %d expected response %s but got %s"
,
name
,
i
+
1
,
pod
.
Name
,
string
(
body
)))
name
,
i
+
1
,
pod
.
Name
,
string
(
body
))
return
false
}
}
glog
.
Infof
(
"Controller %s: Got expected result from replica %d: %s"
,
name
,
i
+
1
,
string
(
body
))
By
(
fmt
.
Sprintf
(
"Controller %s: Got expected result from replica %d: %s"
,
name
,
i
+
1
,
string
(
body
)
))
}
}
return
true
}
// TestBasic performs the TestBasicImage check with the
// image kubernetes/serve_hostname
func
TestBasic
(
c
*
client
.
Client
)
bool
{
return
TestBasicImage
(
c
,
"basic"
,
"kubernetes/serve_hostname:1.1"
)
}
}
var
_
=
Describe
(
"TestBasic"
,
func
()
{
It
(
"should pass"
,
func
()
{
c
,
err
:=
loadClient
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
TestBasic
(
c
))
.
To
(
BeTrue
())
})
})
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