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
26ab52a3
Commit
26ab52a3
authored
Mar 01, 2017
by
tanshanshan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
24d84fa3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
11 deletions
+123
-11
generate.go
pkg/kubelet/status/generate.go
+13
-6
generate_test.go
pkg/kubelet/status/generate_test.go
+110
-5
No files found.
pkg/kubelet/status/generate.go
View file @
26ab52a3
...
...
@@ -23,6 +23,13 @@ import (
"k8s.io/kubernetes/pkg/api/v1"
)
const
(
UnknownContainerStatuses
=
"UnknownContainerStatuses"
PodCompleted
=
"PodCompleted"
ContainersNotReady
=
"ContainersNotReady"
ContainersNotInitialized
=
"ContainersNotInitialized"
)
// GeneratePodReadyCondition returns ready condition if all containers in a pod are ready, else it
// returns an unready condition.
func
GeneratePodReadyCondition
(
spec
*
v1
.
PodSpec
,
containerStatuses
[]
v1
.
ContainerStatus
,
podPhase
v1
.
PodPhase
)
v1
.
PodCondition
{
...
...
@@ -31,7 +38,7 @@ func GeneratePodReadyCondition(spec *v1.PodSpec, containerStatuses []v1.Containe
return
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionFalse
,
Reason
:
"UnknownContainerStatuses"
,
Reason
:
UnknownContainerStatuses
,
}
}
unknownContainers
:=
[]
string
{}
...
...
@@ -51,7 +58,7 @@ func GeneratePodReadyCondition(spec *v1.PodSpec, containerStatuses []v1.Containe
return
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionFalse
,
Reason
:
"PodCompleted"
,
Reason
:
PodCompleted
,
}
}
...
...
@@ -67,7 +74,7 @@ func GeneratePodReadyCondition(spec *v1.PodSpec, containerStatuses []v1.Containe
return
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionFalse
,
Reason
:
"ContainersNotReady"
,
Reason
:
ContainersNotReady
,
Message
:
unreadyMessage
,
}
}
...
...
@@ -86,7 +93,7 @@ func GeneratePodInitializedCondition(spec *v1.PodSpec, containerStatuses []v1.Co
return
v1
.
PodCondition
{
Type
:
v1
.
PodInitialized
,
Status
:
v1
.
ConditionFalse
,
Reason
:
"UnknownContainerStatuses"
,
Reason
:
UnknownContainerStatuses
,
}
}
unknownContainers
:=
[]
string
{}
...
...
@@ -106,7 +113,7 @@ func GeneratePodInitializedCondition(spec *v1.PodSpec, containerStatuses []v1.Co
return
v1
.
PodCondition
{
Type
:
v1
.
PodInitialized
,
Status
:
v1
.
ConditionTrue
,
Reason
:
"PodCompleted"
,
Reason
:
PodCompleted
,
}
}
...
...
@@ -122,7 +129,7 @@ func GeneratePodInitializedCondition(spec *v1.PodSpec, containerStatuses []v1.Co
return
v1
.
PodCondition
{
Type
:
v1
.
PodInitialized
,
Status
:
v1
.
ConditionFalse
,
Reason
:
"ContainersNotInitialized"
,
Reason
:
ContainersNotInitialized
,
Message
:
unreadyMessage
,
}
}
...
...
pkg/kubelet/status/generate_test.go
View file @
26ab52a3
...
...
@@ -20,6 +20,7 @@ import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/kubernetes/pkg/api/v1"
)
...
...
@@ -34,7 +35,7 @@ func TestGeneratePodReadyCondition(t *testing.T) {
spec
:
nil
,
containerStatuses
:
nil
,
podPhase
:
v1
.
PodRunning
,
expected
:
getReadyCondition
(
false
,
"UnknownContainerStatuses"
,
""
),
expected
:
getReadyCondition
(
false
,
UnknownContainerStatuses
,
""
),
},
{
spec
:
&
v1
.
PodSpec
{},
...
...
@@ -50,7 +51,7 @@ func TestGeneratePodReadyCondition(t *testing.T) {
},
containerStatuses
:
[]
v1
.
ContainerStatus
{},
podPhase
:
v1
.
PodRunning
,
expected
:
getReadyCondition
(
false
,
"ContainersNotReady"
,
"containers with unknown status: [1234]"
),
expected
:
getReadyCondition
(
false
,
ContainersNotReady
,
"containers with unknown status: [1234]"
),
},
{
spec
:
&
v1
.
PodSpec
{
...
...
@@ -77,7 +78,7 @@ func TestGeneratePodReadyCondition(t *testing.T) {
getReadyStatus
(
"1234"
),
},
podPhase
:
v1
.
PodRunning
,
expected
:
getReadyCondition
(
false
,
"ContainersNotReady"
,
"containers with unknown status: [5678]"
),
expected
:
getReadyCondition
(
false
,
ContainersNotReady
,
"containers with unknown status: [5678]"
),
},
{
spec
:
&
v1
.
PodSpec
{
...
...
@@ -91,7 +92,7 @@ func TestGeneratePodReadyCondition(t *testing.T) {
getNotReadyStatus
(
"5678"
),
},
podPhase
:
v1
.
PodRunning
,
expected
:
getReadyCondition
(
false
,
"ContainersNotReady"
,
"containers with unready status: [5678]"
),
expected
:
getReadyCondition
(
false
,
ContainersNotReady
,
"containers with unready status: [5678]"
),
},
{
spec
:
&
v1
.
PodSpec
{
...
...
@@ -103,7 +104,7 @@ func TestGeneratePodReadyCondition(t *testing.T) {
getNotReadyStatus
(
"1234"
),
},
podPhase
:
v1
.
PodSucceeded
,
expected
:
getReadyCondition
(
false
,
"PodCompleted"
,
""
),
expected
:
getReadyCondition
(
false
,
PodCompleted
,
""
),
},
}
...
...
@@ -115,6 +116,110 @@ func TestGeneratePodReadyCondition(t *testing.T) {
}
}
func
TestGeneratePodInitializedCondition
(
t
*
testing
.
T
)
{
noInitContainer
:=
&
v1
.
PodSpec
{}
oneInitContainer
:=
&
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"1234"
},
},
}
twoInitContainer
:=
&
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"1234"
},
{
Name
:
"5678"
},
},
}
tests
:=
[]
struct
{
spec
*
v1
.
PodSpec
containerStatuses
[]
v1
.
ContainerStatus
podPhase
v1
.
PodPhase
expected
v1
.
PodCondition
}{
{
spec
:
twoInitContainer
,
containerStatuses
:
nil
,
podPhase
:
v1
.
PodRunning
,
expected
:
v1
.
PodCondition
{
Status
:
v1
.
ConditionFalse
,
Reason
:
UnknownContainerStatuses
,
},
},
{
spec
:
noInitContainer
,
containerStatuses
:
[]
v1
.
ContainerStatus
{},
podPhase
:
v1
.
PodRunning
,
expected
:
v1
.
PodCondition
{
Status
:
v1
.
ConditionTrue
,
Reason
:
""
,
},
},
{
spec
:
oneInitContainer
,
containerStatuses
:
[]
v1
.
ContainerStatus
{},
podPhase
:
v1
.
PodRunning
,
expected
:
v1
.
PodCondition
{
Status
:
v1
.
ConditionFalse
,
Reason
:
ContainersNotInitialized
,
},
},
{
spec
:
twoInitContainer
,
containerStatuses
:
[]
v1
.
ContainerStatus
{
getReadyStatus
(
"1234"
),
getReadyStatus
(
"5678"
),
},
podPhase
:
v1
.
PodRunning
,
expected
:
v1
.
PodCondition
{
Status
:
v1
.
ConditionTrue
,
Reason
:
""
,
},
},
{
spec
:
twoInitContainer
,
containerStatuses
:
[]
v1
.
ContainerStatus
{
getReadyStatus
(
"1234"
),
},
podPhase
:
v1
.
PodRunning
,
expected
:
v1
.
PodCondition
{
Status
:
v1
.
ConditionFalse
,
Reason
:
ContainersNotInitialized
,
},
},
{
spec
:
twoInitContainer
,
containerStatuses
:
[]
v1
.
ContainerStatus
{
getReadyStatus
(
"1234"
),
getNotReadyStatus
(
"5678"
),
},
podPhase
:
v1
.
PodRunning
,
expected
:
v1
.
PodCondition
{
Status
:
v1
.
ConditionFalse
,
Reason
:
ContainersNotInitialized
,
},
},
{
spec
:
oneInitContainer
,
containerStatuses
:
[]
v1
.
ContainerStatus
{
getReadyStatus
(
"1234"
),
},
podPhase
:
v1
.
PodSucceeded
,
expected
:
v1
.
PodCondition
{
Status
:
v1
.
ConditionTrue
,
Reason
:
PodCompleted
,
},
},
}
for
_
,
test
:=
range
tests
{
test
.
expected
.
Type
=
v1
.
PodInitialized
condition
:=
GeneratePodInitializedCondition
(
test
.
spec
,
test
.
containerStatuses
,
test
.
podPhase
)
assert
.
Equal
(
t
,
test
.
expected
.
Type
,
condition
.
Type
)
assert
.
Equal
(
t
,
test
.
expected
.
Status
,
condition
.
Status
)
assert
.
Equal
(
t
,
test
.
expected
.
Reason
,
condition
.
Reason
)
}
}
func
getReadyCondition
(
ready
bool
,
reason
,
message
string
)
v1
.
PodCondition
{
status
:=
v1
.
ConditionFalse
if
ready
{
...
...
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