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
131e8a0e
Commit
131e8a0e
authored
Mar 06, 2015
by
Yifan Gu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor pkg/kubelet/kubelet.go: probeContainer().
Update the probe_test.go.
parent
09af0cd3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
215 additions
and
42 deletions
+215
-42
probe_test.go
pkg/kubelet/probe_test.go
+215
-42
No files found.
pkg/kubelet/probe_test.go
View file @
131e8a0e
...
...
@@ -23,7 +23,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
...
...
@@ -147,6 +146,7 @@ func (p fakeExecProber) Probe(_ exec.Cmd) (probe.Result, error) {
func
makeTestKubelet
(
result
probe
.
Result
,
err
error
)
*
Kubelet
{
return
&
Kubelet
{
readiness
:
newReadinessStates
(),
prober
:
probeHolder
{
exec
:
fakeExecProber
{
result
:
result
,
...
...
@@ -156,68 +156,239 @@ func makeTestKubelet(result probe.Result, err error) *Kubelet {
}
}
// TestProbeContainer tests the functionality of probeContainer.
// Test cases are:
//
// No probe.
// Only LivenessProbe.
// Only ReadinessProbe.
// Both probes.
//
// Also, for each probe, there will be several cases covering whether the initial
// delay has passed, whether the probe handler will return Success, Failure,
// Unknown or error.
//
func
TestProbeContainer
(
t
*
testing
.
T
)
{
dc
:=
&
docker
.
APIContainers
{
Created
:
time
.
Now
()
.
Unix
()}
dc
:=
&
docker
.
APIContainers
{
ID
:
"foobar"
,
Created
:
time
.
Now
()
.
Unix
(),
}
tests
:=
[]
struct
{
p
*
api
.
Probe
defaultResult
probe
.
Result
expect
Error
bool
expectedRe
sult
probe
.
Result
testContainer
api
.
Container
expectError
bool
expect
edResult
probe
.
Result
expectedRe
adiness
bool
}{
// No probes.
{
defaultResult
:
probe
.
Success
,
expectedResult
:
probe
.
Success
,
testContainer
:
api
.
Container
{},
expectedResult
:
probe
.
Success
,
expectedReadiness
:
true
,
},
// Only LivenessProbe.
{
defaultResult
:
probe
.
Failure
,
expectedResult
:
probe
.
Success
,
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
100
},
},
expectedResult
:
probe
.
Success
,
expectedReadiness
:
true
,
},
{
p
:
&
api
.
Probe
{
InitialDelaySeconds
:
100
},
defaultResult
:
probe
.
Failure
,
expectError
:
false
,
expectedResult
:
probe
.
Failure
,
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
},
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
p
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
defaultResult
:
probe
.
Failure
,
expectError
:
false
,
expectedResult
:
probe
.
Unknown
,
expectedResult
:
probe
.
Failure
,
expectedReadiness
:
false
,
},
{
p
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
defaultResult
:
probe
.
Failure
,
expectError
:
false
,
expectedResult
:
probe
.
Success
,
expectedResult
:
probe
.
Success
,
expectedReadiness
:
true
,
},
{
p
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
defaultResult
:
probe
.
Failure
,
expectError
:
true
,
expectedResult
:
probe
.
Unknown
,
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
p
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
expectError
:
true
,
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
// Only ReadinessProbe.
{
testContainer
:
api
.
Container
{
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
100
},
},
expectedResult
:
probe
.
Failure
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
},
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
expectedResult
:
probe
.
Failure
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
expectedResult
:
probe
.
Success
,
expectedReadiness
:
true
,
},
{
testContainer
:
api
.
Container
{
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
expectError
:
true
,
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
// Both LivenessProbe and ReadinessProbe.
{
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
100
},
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
100
},
},
expectedResult
:
probe
.
Failure
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
100
},
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
},
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
100
},
},
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
},
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
},
expectedResult
:
probe
.
Unknown
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
},
},
defaultResult
:
probe
.
Success
,
expectError
:
false
,
expectedResult
:
probe
.
Failure
,
expectedResult
:
probe
.
Failure
,
expectedReadiness
:
false
,
},
{
testContainer
:
api
.
Container
{
LivenessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
ReadinessProbe
:
&
api
.
Probe
{
InitialDelaySeconds
:
-
100
,
Handler
:
api
.
Handler
{
Exec
:
&
api
.
ExecAction
{},
},
},
},
expectedResult
:
probe
.
Success
,
expectedReadiness
:
true
,
},
}
...
...
@@ -229,8 +400,7 @@ func TestProbeContainer(t *testing.T) {
}
else
{
kl
=
makeTestKubelet
(
test
.
expectedResult
,
nil
)
}
result
,
err
:=
kl
.
probeContainer
(
test
.
p
,
""
,
types
.
UID
(
""
),
api
.
PodStatus
{},
api
.
Container
{},
dc
,
test
.
defaultResult
)
result
,
err
:=
kl
.
probeContainer
(
&
api
.
BoundPod
{},
api
.
PodStatus
{},
test
.
testContainer
,
dc
)
if
test
.
expectError
&&
err
==
nil
{
t
.
Error
(
"Expected error but did no error was returned."
)
}
...
...
@@ -240,5 +410,8 @@ func TestProbeContainer(t *testing.T) {
if
test
.
expectedResult
!=
result
{
t
.
Errorf
(
"Expected result was %v but probeContainer() returned %v"
,
test
.
expectedResult
,
result
)
}
if
test
.
expectedReadiness
!=
kl
.
readiness
.
get
(
dc
.
ID
)
{
t
.
Errorf
(
"Expected readiness was %v but probeContainer() set %v"
,
test
.
expectedReadiness
,
kl
.
readiness
.
get
(
dc
.
ID
))
}
}
}
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