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
12383dfa
Commit
12383dfa
authored
Feb 20, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21341 from smarterclayton/liveness_describer
Auto commit by PR queue bot
parents
0f1043d6
c1983679
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
16 deletions
+58
-16
describe.go
pkg/kubectl/describe.go
+57
-15
describe_test.go
pkg/kubectl/describe_test.go
+1
-1
No files found.
pkg/kubectl/describe.go
View file @
12383dfa
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io"
"io"
"net"
"net/url"
"reflect"
"reflect"
"sort"
"sort"
"strings"
"strings"
...
@@ -470,7 +472,7 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) {
...
@@ -470,7 +472,7 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) {
fmt
.
Fprintf
(
out
,
"IP:
\t
%s
\n
"
,
pod
.
Status
.
PodIP
)
fmt
.
Fprintf
(
out
,
"IP:
\t
%s
\n
"
,
pod
.
Status
.
PodIP
)
fmt
.
Fprintf
(
out
,
"Controllers:
\t
%s
\n
"
,
printControllers
(
pod
.
Annotations
))
fmt
.
Fprintf
(
out
,
"Controllers:
\t
%s
\n
"
,
printControllers
(
pod
.
Annotations
))
fmt
.
Fprintf
(
out
,
"Containers:
\n
"
)
fmt
.
Fprintf
(
out
,
"Containers:
\n
"
)
describeContainers
(
pod
,
out
)
DescribeContainers
(
pod
.
Spec
.
Containers
,
pod
.
Status
.
ContainerStatuses
,
EnvValueRetriever
(
pod
)
,
out
)
if
len
(
pod
.
Status
.
Conditions
)
>
0
{
if
len
(
pod
.
Status
.
Conditions
)
>
0
{
fmt
.
Fprint
(
out
,
"Conditions:
\n
Type
\t
Status
\n
"
)
fmt
.
Fprint
(
out
,
"Conditions:
\n
Type
\t
Status
\n
"
)
for
_
,
c
:=
range
pod
.
Status
.
Conditions
{
for
_
,
c
:=
range
pod
.
Status
.
Conditions
{
...
@@ -707,13 +709,14 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string) (strin
...
@@ -707,13 +709,14 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string) (strin
})
})
}
}
func
describeContainers
(
pod
*
api
.
Pod
,
out
io
.
Writer
)
{
// DescribeContainers is exported for consumers in other API groups that have container templates
func
DescribeContainers
(
containers
[]
api
.
Container
,
containerStatuses
[]
api
.
ContainerStatus
,
resolverFn
EnvVarResolverFunc
,
out
io
.
Writer
)
{
statuses
:=
map
[
string
]
api
.
ContainerStatus
{}
statuses
:=
map
[
string
]
api
.
ContainerStatus
{}
for
_
,
status
:=
range
pod
.
Status
.
C
ontainerStatuses
{
for
_
,
status
:=
range
c
ontainerStatuses
{
statuses
[
status
.
Name
]
=
status
statuses
[
status
.
Name
]
=
status
}
}
for
_
,
container
:=
range
pod
.
Spec
.
C
ontainers
{
for
_
,
container
:=
range
c
ontainers
{
status
:=
statuses
[
container
.
Name
]
status
:=
statuses
[
container
.
Name
]
state
:=
status
.
State
state
:=
status
.
State
...
@@ -759,14 +762,26 @@ func describeContainers(pod *api.Pod, out io.Writer) {
...
@@ -759,14 +762,26 @@ func describeContainers(pod *api.Pod, out io.Writer) {
describeStatus
(
"State"
,
state
,
out
)
describeStatus
(
"State"
,
state
,
out
)
if
status
.
LastTerminationState
.
Terminated
!=
nil
{
if
status
.
LastTerminationState
.
Terminated
!=
nil
{
describeStatus
(
"Last
Termination
State"
,
status
.
LastTerminationState
,
out
)
describeStatus
(
"Last State"
,
status
.
LastTerminationState
,
out
)
}
}
fmt
.
Fprintf
(
out
,
" Ready:
\t
%v
\n
"
,
printBool
(
status
.
Ready
))
fmt
.
Fprintf
(
out
,
" Ready:
\t
%v
\n
"
,
printBool
(
status
.
Ready
))
fmt
.
Fprintf
(
out
,
" Restart Count:
\t
%d
\n
"
,
status
.
RestartCount
)
fmt
.
Fprintf
(
out
,
" Restart Count:
\t
%d
\n
"
,
status
.
RestartCount
)
if
container
.
LivenessProbe
!=
nil
{
probe
:=
DescribeProbe
(
container
.
LivenessProbe
)
fmt
.
Fprintf
(
out
,
" Liveness:
\t
%s
\n
"
,
probe
)
}
if
container
.
ReadinessProbe
!=
nil
{
probe
:=
DescribeProbe
(
container
.
ReadinessProbe
)
fmt
.
Fprintf
(
out
,
" Readiness:
\t
%s
\n
"
,
probe
)
}
fmt
.
Fprintf
(
out
,
" Environment Variables:
\n
"
)
fmt
.
Fprintf
(
out
,
" Environment Variables:
\n
"
)
for
_
,
e
:=
range
container
.
Env
{
for
_
,
e
:=
range
container
.
Env
{
if
e
.
ValueFrom
!=
nil
&&
e
.
ValueFrom
.
FieldRef
!=
nil
{
if
e
.
ValueFrom
!=
nil
&&
e
.
ValueFrom
.
FieldRef
!=
nil
{
valueFrom
:=
envValueFrom
(
pod
,
e
)
var
valueFrom
string
if
resolverFn
!=
nil
{
valueFrom
=
resolverFn
(
e
)
}
fmt
.
Fprintf
(
out
,
" %s:
\t
%s (%s:%s)
\n
"
,
e
.
Name
,
valueFrom
,
e
.
ValueFrom
.
FieldRef
.
APIVersion
,
e
.
ValueFrom
.
FieldRef
.
FieldPath
)
fmt
.
Fprintf
(
out
,
" %s:
\t
%s (%s:%s)
\n
"
,
e
.
Name
,
valueFrom
,
e
.
ValueFrom
.
FieldRef
.
APIVersion
,
e
.
ValueFrom
.
FieldRef
.
FieldPath
)
}
else
{
}
else
{
fmt
.
Fprintf
(
out
,
" %s:
\t
%s
\n
"
,
e
.
Name
,
e
.
Value
)
fmt
.
Fprintf
(
out
,
" %s:
\t
%s
\n
"
,
e
.
Name
,
e
.
Value
)
...
@@ -775,18 +790,45 @@ func describeContainers(pod *api.Pod, out io.Writer) {
...
@@ -775,18 +790,45 @@ func describeContainers(pod *api.Pod, out io.Writer) {
}
}
}
}
func
envValueFrom
(
pod
*
api
.
Pod
,
e
api
.
EnvVar
)
string
{
// DescribeProbe is exported for consumers in other API groups that have probes
internalFieldPath
,
_
,
err
:=
api
.
Scheme
.
ConvertFieldLabel
(
e
.
ValueFrom
.
FieldRef
.
APIVersion
,
"Pod"
,
e
.
ValueFrom
.
FieldRef
.
FieldPath
,
""
)
func
DescribeProbe
(
probe
*
api
.
Probe
)
string
{
if
err
!=
nil
{
attrs
:=
fmt
.
Sprintf
(
"delay=%ds timeout=%ds period=%ds #success=%d #failure=%d"
,
probe
.
InitialDelaySeconds
,
probe
.
TimeoutSeconds
,
probe
.
PeriodSeconds
,
probe
.
SuccessThreshold
,
probe
.
FailureThreshold
)
return
""
// pod validation should catch this on create
switch
{
case
probe
.
Exec
!=
nil
:
return
fmt
.
Sprintf
(
"exec %v %s"
,
probe
.
Exec
.
Command
,
attrs
)
case
probe
.
HTTPGet
!=
nil
:
url
:=
&
url
.
URL
{}
url
.
Scheme
=
strings
.
ToLower
(
string
(
probe
.
HTTPGet
.
Scheme
))
if
len
(
probe
.
HTTPGet
.
Port
.
String
())
>
0
{
url
.
Host
=
net
.
JoinHostPort
(
probe
.
HTTPGet
.
Host
,
probe
.
HTTPGet
.
Port
.
String
())
}
else
{
url
.
Host
=
probe
.
HTTPGet
.
Host
}
url
.
Path
=
probe
.
HTTPGet
.
Path
return
fmt
.
Sprintf
(
"http-get %s %s"
,
url
.
String
(),
attrs
)
case
probe
.
TCPSocket
!=
nil
:
return
fmt
.
Sprintf
(
"tcp-socket :%s %s"
,
probe
.
TCPSocket
.
Port
.
String
(),
attrs
)
}
}
return
fmt
.
Sprintf
(
"unknown %s"
,
attrs
)
}
valueFrom
,
err
:=
fieldpath
.
ExtractFieldPathAsString
(
pod
,
internalFieldPath
)
type
EnvVarResolverFunc
func
(
e
api
.
EnvVar
)
string
if
err
!=
nil
{
return
""
// pod validation should catch this on create
// EnvValueFrom is exported for use by describers in other packages
}
func
EnvValueRetriever
(
pod
*
api
.
Pod
)
EnvVarResolverFunc
{
return
func
(
e
api
.
EnvVar
)
string
{
internalFieldPath
,
_
,
err
:=
api
.
Scheme
.
ConvertFieldLabel
(
e
.
ValueFrom
.
FieldRef
.
APIVersion
,
"Pod"
,
e
.
ValueFrom
.
FieldRef
.
FieldPath
,
""
)
if
err
!=
nil
{
return
""
// pod validation should catch this on create
}
return
valueFrom
valueFrom
,
err
:=
fieldpath
.
ExtractFieldPathAsString
(
pod
,
internalFieldPath
)
if
err
!=
nil
{
return
""
// pod validation should catch this on create
}
return
valueFrom
}
}
}
func
describeStatus
(
stateName
string
,
state
api
.
ContainerState
,
out
io
.
Writer
)
{
func
describeStatus
(
stateName
string
,
state
api
.
ContainerState
,
out
io
.
Writer
)
{
...
...
pkg/kubectl/describe_test.go
View file @
12383dfa
...
@@ -268,7 +268,7 @@ func TestDescribeContainers(t *testing.T) {
...
@@ -268,7 +268,7 @@ func TestDescribeContainers(t *testing.T) {
ContainerStatuses
:
[]
api
.
ContainerStatus
{
testCase
.
status
},
ContainerStatuses
:
[]
api
.
ContainerStatus
{
testCase
.
status
},
},
},
}
}
describeContainers
(
&
pod
,
out
)
DescribeContainers
(
pod
.
Spec
.
Containers
,
pod
.
Status
.
ContainerStatuses
,
EnvValueRetriever
(
&
pod
)
,
out
)
output
:=
out
.
String
()
output
:=
out
.
String
()
for
_
,
expected
:=
range
testCase
.
expectedElements
{
for
_
,
expected
:=
range
testCase
.
expectedElements
{
if
!
strings
.
Contains
(
output
,
expected
)
{
if
!
strings
.
Contains
(
output
,
expected
)
{
...
...
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