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
d9569948
Commit
d9569948
authored
Jul 04, 2018
by
Conor Landry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
show pods using pvcs for kubectl describe
sort pods in kubectl describe pvc with user-defined alignment
parent
97a4da71
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
2 deletions
+75
-2
describe.go
pkg/printers/internalversion/describe.go
+75
-2
No files found.
pkg/printers/internalversion/describe.go
View file @
d9569948
...
...
@@ -1291,12 +1291,52 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri
return
""
,
err
}
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
mountPods
,
err
:=
getMountPods
(
pc
,
pvc
.
Name
)
if
err
!=
nil
{
return
""
,
err
}
events
,
_
:=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
legacyscheme
.
Scheme
,
pvc
)
return
describePersistentVolumeClaim
(
pvc
,
events
)
return
describePersistentVolumeClaim
(
pvc
,
events
,
mountPods
)
}
func
getMountPods
(
c
coreclient
.
PodInterface
,
pvcName
string
)
([]
api
.
Pod
,
error
)
{
nsPods
,
err
:=
c
.
List
(
metav1
.
ListOptions
{})
if
err
!=
nil
{
return
[]
api
.
Pod
{},
err
}
var
pods
[]
api
.
Pod
for
_
,
pod
:=
range
nsPods
.
Items
{
pvcs
:=
getPvcs
(
pod
.
Spec
.
Volumes
)
for
_
,
pvc
:=
range
pvcs
{
if
pvc
.
PersistentVolumeClaim
.
ClaimName
==
pvcName
{
pods
=
append
(
pods
,
pod
)
}
}
}
return
pods
,
nil
}
func
describePersistentVolumeClaim
(
pvc
*
api
.
PersistentVolumeClaim
,
events
*
api
.
EventList
)
(
string
,
error
)
{
func
getPvcs
(
volumes
[]
api
.
Volume
)
[]
api
.
Volume
{
var
pvcs
[]
api
.
Volume
for
_
,
volume
:=
range
volumes
{
if
volume
.
VolumeSource
.
PersistentVolumeClaim
!=
nil
{
pvcs
=
append
(
pvcs
,
volume
)
}
}
return
pvcs
}
func
describePersistentVolumeClaim
(
pvc
*
api
.
PersistentVolumeClaim
,
events
*
api
.
EventList
,
mountPods
[]
api
.
Pod
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
w
:=
NewPrefixWriter
(
out
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
pvc
.
Name
)
...
...
@@ -1342,6 +1382,8 @@ func describePersistentVolumeClaim(pvc *api.PersistentVolumeClaim, events *api.E
DescribeEvents
(
events
,
w
)
}
printPodsMultiline
(
w
,
"Mounted By"
,
mountPods
)
return
nil
})
}
...
...
@@ -3867,6 +3909,37 @@ func printTaintsMultilineWithIndent(w PrefixWriter, initialIndent, title, innerI
}
}
// printPodsMultiline prints multiple pods with a proper alignment.
func
printPodsMultiline
(
w
PrefixWriter
,
title
string
,
pods
[]
api
.
Pod
)
{
printPodsMultilineWithIndent
(
w
,
""
,
title
,
"
\t
"
,
pods
)
}
// printPodsMultilineWithIndent prints multiple pods with a user-defined alignment.
func
printPodsMultilineWithIndent
(
w
PrefixWriter
,
initialIndent
,
title
,
innerIndent
string
,
pods
[]
api
.
Pod
)
{
w
.
Write
(
LEVEL_0
,
"%s%s:%s"
,
initialIndent
,
title
,
innerIndent
)
if
pods
==
nil
||
len
(
pods
)
==
0
{
w
.
WriteLine
(
"<none>"
)
return
}
// to print pods in the sorted order
sort
.
Slice
(
pods
,
func
(
i
,
j
int
)
bool
{
cmpKey
:=
func
(
pod
api
.
Pod
)
string
{
return
pod
.
Name
}
return
cmpKey
(
pods
[
i
])
<
cmpKey
(
pods
[
j
])
})
for
i
,
pod
:=
range
pods
{
if
i
!=
0
{
w
.
Write
(
LEVEL_0
,
"%s"
,
initialIndent
)
w
.
Write
(
LEVEL_0
,
"%s"
,
innerIndent
)
}
w
.
Write
(
LEVEL_0
,
"%s
\n
"
,
pod
.
Name
)
}
}
// printPodTolerationsMultiline prints multiple tolerations with a proper alignment.
func
printPodTolerationsMultiline
(
w
PrefixWriter
,
title
string
,
tolerations
[]
api
.
Toleration
)
{
printTolerationsMultilineWithIndent
(
w
,
""
,
title
,
"
\t
"
,
tolerations
)
...
...
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