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
e6188f8c
Unverified
Commit
e6188f8c
authored
Apr 25, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Apr 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76646 from cwdsuzhou/print_volumeMode
Support print volumeMode using kubectl get pv/pvc
parents
a7a6bf43
6872cf2a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
11 deletions
+48
-11
printers.go
pkg/printers/internalversion/printers.go
+14
-3
printers_test.go
pkg/printers/internalversion/printers_test.go
+34
-8
No files found.
pkg/printers/internalversion/printers.go
View file @
e6188f8c
...
...
@@ -285,6 +285,7 @@ func AddHandlers(h printers.PrintHandler) {
{
Name
:
"StorageClass"
,
Type
:
"string"
,
Description
:
"StorageClass of the pv"
},
{
Name
:
"Reason"
,
Type
:
"string"
,
Description
:
apiv1
.
PersistentVolumeStatus
{}
.
SwaggerDoc
()[
"reason"
]},
{
Name
:
"Age"
,
Type
:
"string"
,
Description
:
metav1
.
ObjectMeta
{}
.
SwaggerDoc
()[
"creationTimestamp"
]},
{
Name
:
"VolumeMode"
,
Type
:
"string"
,
Priority
:
1
,
Description
:
apiv1
.
PersistentVolumeSpec
{}
.
SwaggerDoc
()[
"volumeMode"
]},
}
h
.
TableHandler
(
persistentVolumeColumnDefinitions
,
printPersistentVolume
)
h
.
TableHandler
(
persistentVolumeColumnDefinitions
,
printPersistentVolumeList
)
...
...
@@ -297,6 +298,7 @@ func AddHandlers(h printers.PrintHandler) {
{
Name
:
"Access Modes"
,
Type
:
"string"
,
Description
:
apiv1
.
PersistentVolumeClaimStatus
{}
.
SwaggerDoc
()[
"accessModes"
]},
{
Name
:
"StorageClass"
,
Type
:
"string"
,
Description
:
"StorageClass of the pvc"
},
{
Name
:
"Age"
,
Type
:
"string"
,
Description
:
metav1
.
ObjectMeta
{}
.
SwaggerDoc
()[
"creationTimestamp"
]},
{
Name
:
"VolumeMode"
,
Type
:
"string"
,
Priority
:
1
,
Description
:
apiv1
.
PersistentVolumeClaimSpec
{}
.
SwaggerDoc
()[
"volumeMode"
]},
}
h
.
TableHandler
(
persistentVolumeClaimColumnDefinitions
,
printPersistentVolumeClaim
)
h
.
TableHandler
(
persistentVolumeClaimColumnDefinitions
,
printPersistentVolumeClaimList
)
...
...
@@ -1328,11 +1330,14 @@ func printPersistentVolume(obj *api.PersistentVolume, options printers.PrintOpti
if
obj
.
ObjectMeta
.
DeletionTimestamp
!=
nil
{
phase
=
"Terminating"
}
volumeMode
:=
"<unset>"
if
obj
.
Spec
.
VolumeMode
!=
nil
{
volumeMode
=
string
(
*
obj
.
Spec
.
VolumeMode
)
}
row
.
Cells
=
append
(
row
.
Cells
,
obj
.
Name
,
aSize
,
modesStr
,
reclaimPolicyStr
,
string
(
phase
),
claimRefUID
,
helper
.
GetPersistentVolumeClass
(
obj
),
obj
.
Status
.
Reason
,
translateTimestampSince
(
obj
.
CreationTimestamp
))
obj
.
Status
.
Reason
,
translateTimestampSince
(
obj
.
CreationTimestamp
),
volumeMode
)
return
[]
metav1beta1
.
TableRow
{
row
},
nil
}
...
...
@@ -1361,13 +1366,19 @@ func printPersistentVolumeClaim(obj *api.PersistentVolumeClaim, options printers
storage
:=
obj
.
Spec
.
Resources
.
Requests
[
api
.
ResourceStorage
]
capacity
:=
""
accessModes
:=
""
volumeMode
:=
"<unset>"
if
obj
.
Spec
.
VolumeName
!=
""
{
accessModes
=
helper
.
GetAccessModesAsString
(
obj
.
Status
.
AccessModes
)
storage
=
obj
.
Status
.
Capacity
[
api
.
ResourceStorage
]
capacity
=
storage
.
String
()
}
row
.
Cells
=
append
(
row
.
Cells
,
obj
.
Name
,
string
(
phase
),
obj
.
Spec
.
VolumeName
,
capacity
,
accessModes
,
helper
.
GetPersistentVolumeClaimClass
(
obj
),
translateTimestampSince
(
obj
.
CreationTimestamp
))
if
obj
.
Spec
.
VolumeMode
!=
nil
{
volumeMode
=
string
(
*
obj
.
Spec
.
VolumeMode
)
}
row
.
Cells
=
append
(
row
.
Cells
,
obj
.
Name
,
string
(
phase
),
obj
.
Spec
.
VolumeName
,
capacity
,
accessModes
,
helper
.
GetPersistentVolumeClaimClass
(
obj
),
translateTimestampSince
(
obj
.
CreationTimestamp
),
volumeMode
)
return
[]
metav1beta1
.
TableRow
{
row
},
nil
}
...
...
pkg/printers/internalversion/printers_test.go
View file @
e6188f8c
...
...
@@ -29,7 +29,7 @@ import (
"sigs.k8s.io/yaml"
v1
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
...
...
@@ -3246,6 +3246,7 @@ func TestPrintReplicaSet(t *testing.T) {
}
func
TestPrintPersistentVolumeClaim
(
t
*
testing
.
T
)
{
volumeMode
:=
api
.
PersistentVolumeFilesystem
myScn
:=
"my-scn"
tests
:=
[]
struct
{
pvc
api
.
PersistentVolumeClaim
...
...
@@ -3259,6 +3260,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"my-volume"
,
VolumeMode
:
&
volumeMode
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimBound
,
...
...
@@ -3268,7 +3270,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
},
},
},
"test1
\t
Bound
\t
my-volume
\t
4Gi
\t
ROX
\t\t
<unknown>
\n
"
,
"test1
\t
Bound
\t
my-volume
\t
4Gi
\t
ROX
\t\t
<unknown>
\
t
Filesystem
\
n
"
,
},
{
// Test name, num of containers, restarts, container ready status
...
...
@@ -3276,7 +3278,9 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test2"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeMode
:
&
volumeMode
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimLost
,
AccessModes
:
[]
api
.
PersistentVolumeAccessMode
{
api
.
ReadOnlyMany
},
...
...
@@ -3285,7 +3289,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
},
},
},
"test2
\t
Lost
\t\t\t\t\t
<unknown>
\n
"
,
"test2
\t
Lost
\t\t\t\t\t
<unknown>
\
t
Filesystem
\
n
"
,
},
{
// Test name, num of containers, restarts, container ready status
...
...
@@ -3295,6 +3299,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"my-volume"
,
VolumeMode
:
&
volumeMode
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimPending
,
...
...
@@ -3304,7 +3309,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
},
},
},
"test3
\t
Pending
\t
my-volume
\t
10Gi
\t
RWX
\t\t
<unknown>
\n
"
,
"test3
\t
Pending
\t
my-volume
\t
10Gi
\t
RWX
\t\t
<unknown>
\
t
Filesystem
\
n
"
,
},
{
// Test name, num of containers, restarts, container ready status
...
...
@@ -3315,6 +3320,27 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"my-volume"
,
StorageClassName
:
&
myScn
,
VolumeMode
:
&
volumeMode
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimPending
,
AccessModes
:
[]
api
.
PersistentVolumeAccessMode
{
api
.
ReadWriteOnce
},
Capacity
:
map
[
api
.
ResourceName
]
resource
.
Quantity
{
api
.
ResourceStorage
:
resource
.
MustParse
(
"10Gi"
),
},
},
},
"test4
\t
Pending
\t
my-volume
\t
10Gi
\t
RWO
\t
my-scn
\t
<unknown>
\t
Filesystem
\n
"
,
},
{
// Test name, num of containers, restarts, container ready status
api
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test5"
,
},
Spec
:
api
.
PersistentVolumeClaimSpec
{
VolumeName
:
"my-volume"
,
StorageClassName
:
&
myScn
,
},
Status
:
api
.
PersistentVolumeClaimStatus
{
Phase
:
api
.
ClaimPending
,
...
...
@@ -3324,17 +3350,17 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
},
},
},
"test
4
\t
Pending
\t
my-volume
\t
10Gi
\t
RWO
\t
my-scn
\t
<unknown
>
\n
"
,
"test
5
\t
Pending
\t
my-volume
\t
10Gi
\t
RWO
\t
my-scn
\t
<unknown>
\t
<unset
>
\n
"
,
},
}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
table
,
err
:=
printers
.
NewTableGenerator
()
.
With
(
AddHandlers
)
.
GenerateTable
(
&
test
.
pvc
,
printers
.
PrintOptions
{})
table
,
err
:=
printers
.
NewTableGenerator
()
.
With
(
AddHandlers
)
.
GenerateTable
(
&
test
.
pvc
,
printers
.
PrintOptions
{
Wide
:
true
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
verifyTable
(
t
,
table
)
if
err
:=
printers
.
PrintTable
(
table
,
buf
,
printers
.
PrintOptions
{
NoHeaders
:
true
});
err
!=
nil
{
if
err
:=
printers
.
PrintTable
(
table
,
buf
,
printers
.
PrintOptions
{
NoHeaders
:
true
,
Wide
:
true
});
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
buf
.
String
()
!=
test
.
expect
{
...
...
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