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
e35ee9b3
Commit
e35ee9b3
authored
Jul 23, 2015
by
Vish Kannan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11500 from mbforbes/fasterLiveness
Makes liveness test faster
parents
87333097
e704004a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
31 deletions
+32
-31
pods.go
test/e2e/pods.go
+32
-31
No files found.
test/e2e/pods.go
View file @
e35ee9b3
...
@@ -60,24 +60,25 @@ func runLivenessTest(c *client.Client, ns string, podDescr *api.Pod, expectResta
...
@@ -60,24 +60,25 @@ func runLivenessTest(c *client.Client, ns string, podDescr *api.Pod, expectResta
initialRestartCount
:=
api
.
GetExistingContainerStatus
(
pod
.
Status
.
ContainerStatuses
,
"liveness"
)
.
RestartCount
initialRestartCount
:=
api
.
GetExistingContainerStatus
(
pod
.
Status
.
ContainerStatuses
,
"liveness"
)
.
RestartCount
By
(
fmt
.
Sprintf
(
"Initial restart count of pod %s is %d"
,
podDescr
.
Name
,
initialRestartCount
))
By
(
fmt
.
Sprintf
(
"Initial restart count of pod %s is %d"
,
podDescr
.
Name
,
initialRestartCount
))
// Wait for at most 48 * 5 = 240s = 4 minutes until restartCount is incremented
// Wait for the restart state to be as desired.
restarts
:=
false
restarts
,
deadline
:=
false
,
time
.
Now
()
.
Add
(
2
*
time
.
Minute
)
for
i
:=
0
;
i
<
48
;
i
++
{
for
start
:=
time
.
Now
();
time
.
Now
()
.
Before
(
deadline
);
time
.
Sleep
(
2
*
time
.
Second
)
{
// Wait until restartCount is incremented.
time
.
Sleep
(
5
*
time
.
Second
)
pod
,
err
=
c
.
Pods
(
ns
)
.
Get
(
podDescr
.
Name
)
pod
,
err
=
c
.
Pods
(
ns
)
.
Get
(
podDescr
.
Name
)
expectNoError
(
err
,
fmt
.
Sprintf
(
"getting pod %s"
,
podDescr
.
Name
))
expectNoError
(
err
,
fmt
.
Sprintf
(
"getting pod %s"
,
podDescr
.
Name
))
restartCount
:=
api
.
GetExistingContainerStatus
(
pod
.
Status
.
ContainerStatuses
,
"liveness"
)
.
RestartCount
restartCount
:=
api
.
GetExistingContainerStatus
(
pod
.
Status
.
ContainerStatuses
,
"liveness"
)
.
RestartCount
By
(
fmt
.
Sprintf
(
"Restart count of pod %s in namespace %s is now %d"
,
podDescr
.
Name
,
ns
,
restartCount
))
By
(
fmt
.
Sprintf
(
"Restart count of pod %s/%s is now %d (%v elapsed)"
,
ns
,
podDescr
.
Name
,
restartCount
,
time
.
Since
(
start
)))
if
restartCount
>
initialRestartCount
{
if
restartCount
>
initialRestartCount
{
By
(
fmt
.
Sprintf
(
"Restart count of pod %s in namespace %s increased from %d to %d during the test"
,
podDescr
.
Name
,
ns
,
initialRestartCount
,
restartCount
))
By
(
fmt
.
Sprintf
(
"Restart count of pod %s/%s changed from %d to %d"
,
ns
,
podDescr
.
Name
,
initialRestartCount
,
restartCount
))
restarts
=
true
restarts
=
true
break
break
}
}
}
}
if
restarts
!=
expectRestart
{
if
restarts
!=
expectRestart
{
Fail
(
fmt
.
Sprintf
(
"pod %s in namespace %s - expected restarts: %v, found restarts: %v"
,
podDescr
.
Name
,
ns
,
expectRestart
,
restarts
))
Failf
(
"pod %s/%s - expected restarts: %t, found restarts: %t"
,
ns
,
podDescr
.
Name
,
expectRestart
,
restarts
)
}
}
}
}
...
@@ -88,7 +89,7 @@ func testHostIP(c *client.Client, ns string, pod *api.Pod) {
...
@@ -88,7 +89,7 @@ func testHostIP(c *client.Client, ns string, pod *api.Pod) {
defer
podClient
.
Delete
(
pod
.
Name
,
nil
)
defer
podClient
.
Delete
(
pod
.
Name
,
nil
)
_
,
err
:=
podClient
.
Create
(
pod
)
_
,
err
:=
podClient
.
Create
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to create pod: %v"
,
err
)
)
Fail
f
(
"Failed to create pod: %v"
,
err
)
}
}
By
(
"ensuring that pod is running and has a hostIP"
)
By
(
"ensuring that pod is running and has a 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
...
@@ -166,7 +167,7 @@ var _ = Describe("Pods", func() {
...
@@ -166,7 +167,7 @@ var _ = Describe("Pods", func() {
defer
podClient
.
Delete
(
pod
.
Name
,
nil
)
defer
podClient
.
Delete
(
pod
.
Name
,
nil
)
_
,
err
:=
podClient
.
Create
(
pod
)
_
,
err
:=
podClient
.
Create
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Error creating a pod: %v"
,
err
)
)
Fail
f
(
"Error creating a pod: %v"
,
err
)
}
}
expectNoError
(
framework
.
WaitForPodRunning
(
pod
.
Name
))
expectNoError
(
framework
.
WaitForPodRunning
(
pod
.
Name
))
})
})
...
@@ -208,13 +209,13 @@ var _ = Describe("Pods", func() {
...
@@ -208,13 +209,13 @@ var _ = Describe("Pods", func() {
By
(
"setting up watch"
)
By
(
"setting up watch"
)
pods
,
err
:=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
())
pods
,
err
:=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to query for pods: %v"
,
err
)
)
Fail
f
(
"Failed to query for pods: %v"
,
err
)
}
}
Expect
(
len
(
pods
.
Items
))
.
To
(
Equal
(
0
))
Expect
(
len
(
pods
.
Items
))
.
To
(
Equal
(
0
))
w
,
err
:=
podClient
.
Watch
(
w
,
err
:=
podClient
.
Watch
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
(),
pods
.
ListMeta
.
ResourceVersion
)
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
(),
pods
.
ListMeta
.
ResourceVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to set up watch: %v"
,
err
)
)
Fail
f
(
"Failed to set up watch: %v"
,
err
)
}
}
By
(
"submitting the pod to kubernetes"
)
By
(
"submitting the pod to kubernetes"
)
...
@@ -224,13 +225,13 @@ var _ = Describe("Pods", func() {
...
@@ -224,13 +225,13 @@ var _ = Describe("Pods", func() {
defer
podClient
.
Delete
(
pod
.
Name
,
nil
)
defer
podClient
.
Delete
(
pod
.
Name
,
nil
)
_
,
err
=
podClient
.
Create
(
pod
)
_
,
err
=
podClient
.
Create
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to create pod: %v"
,
err
)
)
Fail
f
(
"Failed to create pod: %v"
,
err
)
}
}
By
(
"verifying the pod is in kubernetes"
)
By
(
"verifying the pod is in kubernetes"
)
pods
,
err
=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
())
pods
,
err
=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to query for pods: %v"
,
err
)
)
Fail
f
(
"Failed to query for pods: %v"
,
err
)
}
}
Expect
(
len
(
pods
.
Items
))
.
To
(
Equal
(
1
))
Expect
(
len
(
pods
.
Items
))
.
To
(
Equal
(
1
))
...
@@ -238,7 +239,7 @@ var _ = Describe("Pods", func() {
...
@@ -238,7 +239,7 @@ var _ = Describe("Pods", func() {
select
{
select
{
case
event
,
_
:=
<-
w
.
ResultChan
()
:
case
event
,
_
:=
<-
w
.
ResultChan
()
:
if
event
.
Type
!=
watch
.
Added
{
if
event
.
Type
!=
watch
.
Added
{
Fail
(
fmt
.
Sprintf
(
"Failed to observe pod creation: %v"
,
event
)
)
Fail
f
(
"Failed to observe pod creation: %v"
,
event
)
}
}
case
<-
time
.
After
(
podStartTimeout
)
:
case
<-
time
.
After
(
podStartTimeout
)
:
Fail
(
"Timeout while waiting for pod creation"
)
Fail
(
"Timeout while waiting for pod creation"
)
...
@@ -248,7 +249,7 @@ var _ = Describe("Pods", func() {
...
@@ -248,7 +249,7 @@ var _ = Describe("Pods", func() {
podClient
.
Delete
(
pod
.
Name
,
nil
)
podClient
.
Delete
(
pod
.
Name
,
nil
)
pods
,
err
=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
())
pods
,
err
=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})),
fields
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to delete pod: %v"
,
err
)
)
Fail
f
(
"Failed to delete pod: %v"
,
err
)
}
}
Expect
(
len
(
pods
.
Items
))
.
To
(
Equal
(
0
))
Expect
(
len
(
pods
.
Items
))
.
To
(
Equal
(
0
))
...
@@ -375,7 +376,7 @@ var _ = Describe("Pods", func() {
...
@@ -375,7 +376,7 @@ var _ = Describe("Pods", func() {
defer
framework
.
Client
.
Pods
(
framework
.
Namespace
.
Name
)
.
Delete
(
serverPod
.
Name
,
nil
)
defer
framework
.
Client
.
Pods
(
framework
.
Namespace
.
Name
)
.
Delete
(
serverPod
.
Name
,
nil
)
_
,
err
:=
framework
.
Client
.
Pods
(
framework
.
Namespace
.
Name
)
.
Create
(
serverPod
)
_
,
err
:=
framework
.
Client
.
Pods
(
framework
.
Namespace
.
Name
)
.
Create
(
serverPod
)
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to create serverPod: %v"
,
err
)
)
Fail
f
(
"Failed to create serverPod: %v"
,
err
)
}
}
expectNoError
(
framework
.
WaitForPodRunning
(
serverPod
.
Name
))
expectNoError
(
framework
.
WaitForPodRunning
(
serverPod
.
Name
))
...
@@ -407,7 +408,7 @@ var _ = Describe("Pods", func() {
...
@@ -407,7 +408,7 @@ var _ = Describe("Pods", func() {
defer
framework
.
Client
.
Services
(
framework
.
Namespace
.
Name
)
.
Delete
(
svc
.
Name
)
defer
framework
.
Client
.
Services
(
framework
.
Namespace
.
Name
)
.
Delete
(
svc
.
Name
)
_
,
err
=
framework
.
Client
.
Services
(
framework
.
Namespace
.
Name
)
.
Create
(
svc
)
_
,
err
=
framework
.
Client
.
Services
(
framework
.
Namespace
.
Name
)
.
Create
(
svc
)
if
err
!=
nil
{
if
err
!=
nil
{
Fail
(
fmt
.
Sprintf
(
"Failed to create service: %v"
,
err
)
)
Fail
f
(
"Failed to create service: %v"
,
err
)
}
}
// Make a client pod that verifies that it has the service environment variables.
// Make a client pod that verifies that it has the service environment variables.
...
@@ -528,7 +529,7 @@ var _ = Describe("Pods", func() {
...
@@ -528,7 +529,7 @@ var _ = Describe("Pods", func() {
It("should support remote command execution", func() {
It("should support remote command execution", func() {
clientConfig, err := loadConfig()
clientConfig, err := loadConfig()
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Failed to create client config: %v", err)
)
Fail
f("Failed to create client config: %v", err
)
}
}
podClient := framework.Client.Pods(framework.Namespace.Name)
podClient := framework.Client.Pods(framework.Namespace.Name)
...
@@ -557,7 +558,7 @@ var _ = Describe("Pods", func() {
...
@@ -557,7 +558,7 @@ var _ = Describe("Pods", func() {
By("submitting the pod to kubernetes")
By("submitting the pod to kubernetes")
_, err = podClient.Create(pod)
_, err = podClient.Create(pod)
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Failed to create pod: %v", err)
)
Fail
f("Failed to create pod: %v", err
)
}
}
defer func() {
defer func() {
// We call defer here in case there is a problem with
// We call defer here in case there is a problem with
...
@@ -572,7 +573,7 @@ var _ = Describe("Pods", func() {
...
@@ -572,7 +573,7 @@ var _ = Describe("Pods", func() {
By("verifying the pod is in kubernetes")
By("verifying the pod is in kubernetes")
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Failed to query for pods: %v", err)
)
Fail
f("Failed to query for pods: %v", err
)
}
}
Expect(len(pods.Items)).To(Equal(1))
Expect(len(pods.Items)).To(Equal(1))
...
@@ -589,18 +590,18 @@ var _ = Describe("Pods", func() {
...
@@ -589,18 +590,18 @@ var _ = Describe("Pods", func() {
e := remotecommand.New(req, clientConfig, []string{"whoami"}, nil, out, nil, false)
e := remotecommand.New(req, clientConfig, []string{"whoami"}, nil, out, nil, false)
err = e.Execute()
err = e.Execute()
if err != nil {
if err != nil {
Fail
(fmt.Sprint
f("Failed to execute command on host %s pod %s in container %s: %v",
Failf("Failed to execute command on host %s pod %s in container %s: %v",
pod.Status.Host, pod.Name, pod.Spec.Containers[0].Name, err)
)
pod.Status.Host, pod.Name, pod.Spec.Containers[0].Name, err)
}
}
if e, a := "root\n", out.String(); e != a {
if e, a := "root\n", out.String(); e != a {
Fail
(fmt.Sprintf("exec: whoami: expected '%s', got '%s'", e, a)
)
Fail
f("exec: whoami: expected '%s', got '%s'", e, a
)
}
}
})
})
It("should support port forwarding", func() {
It("should support port forwarding", func() {
clientConfig, err := loadConfig()
clientConfig, err := loadConfig()
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Failed to create client config: %v", err)
)
Fail
f("Failed to create client config: %v", err
)
}
}
podClient := framework.Client.Pods(framework.Namespace.Name)
podClient := framework.Client.Pods(framework.Namespace.Name)
...
@@ -630,7 +631,7 @@ var _ = Describe("Pods", func() {
...
@@ -630,7 +631,7 @@ var _ = Describe("Pods", func() {
By("submitting the pod to kubernetes")
By("submitting the pod to kubernetes")
_, err = podClient.Create(pod)
_, err = podClient.Create(pod)
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Failed to create pod: %v", err)
)
Fail
f("Failed to create pod: %v", err
)
}
}
defer func() {
defer func() {
// We call defer here in case there is a problem with
// We call defer here in case there is a problem with
...
@@ -645,7 +646,7 @@ var _ = Describe("Pods", func() {
...
@@ -645,7 +646,7 @@ var _ = Describe("Pods", func() {
By("verifying the pod is in kubernetes")
By("verifying the pod is in kubernetes")
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Failed to query for pods: %v", err)
)
Fail
f("Failed to query for pods: %v", err
)
}
}
Expect(len(pods.Items)).To(Equal(1))
Expect(len(pods.Items)).To(Equal(1))
...
@@ -662,7 +663,7 @@ var _ = Describe("Pods", func() {
...
@@ -662,7 +663,7 @@ var _ = Describe("Pods", func() {
stopChan := make(chan struct{})
stopChan := make(chan struct{})
pf, err := portforward.New(req, clientConfig, []string{"5678:80"}, stopChan)
pf, err := portforward.New(req, clientConfig, []string{"5678:80"}, stopChan)
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Error creating port forwarder: %s", err)
)
Fail
f("Error creating port forwarder: %s", err
)
}
}
errorChan := make(chan error)
errorChan := make(chan error)
...
@@ -675,11 +676,11 @@ var _ = Describe("Pods", func() {
...
@@ -675,11 +676,11 @@ var _ = Describe("Pods", func() {
resp, err := http.Get("http://localhost:5678/")
resp, err := http.Get("http://localhost:5678/")
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Error with http get to localhost:5678: %s", err)
)
Fail
f("Error with http get to localhost:5678: %s", err
)
}
}
body, err := ioutil.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
if err != nil {
Fail
(fmt.Sprintf("Error reading response body: %s", err)
)
Fail
f("Error reading response body: %s", err
)
}
}
titleRegex := regexp.MustCompile("<title>(.+)</title>")
titleRegex := regexp.MustCompile("<title>(.+)</title>")
...
@@ -688,7 +689,7 @@ var _ = Describe("Pods", func() {
...
@@ -688,7 +689,7 @@ var _ = Describe("Pods", func() {
Fail("Unable to locate page title in response HTML")
Fail("Unable to locate page title in response HTML")
}
}
if e, a := "Welcome to nginx on Debian!", matches[1]; e != a {
if e, a := "Welcome to nginx on Debian!", matches[1]; e != a {
Fail
(fmt.Sprintf("<title>: expected '%s', got '%s'", e, a)
)
Fail
f("<title>: expected '%s', got '%s'", e, a
)
}
}
})
})
*/
*/
...
...
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