mirror of https://github.com/k3s-io/k3s
Support print volumeMode using kubectl get pv/pvc -o wide
parent
e6390ce3ff
commit
6872cf2a55
|
@ -285,6 +285,7 @@ func AddHandlers(h printers.PrintHandler) {
|
||||||
{Name: "StorageClass", Type: "string", Description: "StorageClass of the pv"},
|
{Name: "StorageClass", Type: "string", Description: "StorageClass of the pv"},
|
||||||
{Name: "Reason", Type: "string", Description: apiv1.PersistentVolumeStatus{}.SwaggerDoc()["reason"]},
|
{Name: "Reason", Type: "string", Description: apiv1.PersistentVolumeStatus{}.SwaggerDoc()["reason"]},
|
||||||
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
{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, printPersistentVolume)
|
||||||
h.TableHandler(persistentVolumeColumnDefinitions, printPersistentVolumeList)
|
h.TableHandler(persistentVolumeColumnDefinitions, printPersistentVolumeList)
|
||||||
|
@ -297,6 +298,7 @@ func AddHandlers(h printers.PrintHandler) {
|
||||||
{Name: "Access Modes", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["accessModes"]},
|
{Name: "Access Modes", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["accessModes"]},
|
||||||
{Name: "StorageClass", Type: "string", Description: "StorageClass of the pvc"},
|
{Name: "StorageClass", Type: "string", Description: "StorageClass of the pvc"},
|
||||||
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
{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, printPersistentVolumeClaim)
|
||||||
h.TableHandler(persistentVolumeClaimColumnDefinitions, printPersistentVolumeClaimList)
|
h.TableHandler(persistentVolumeClaimColumnDefinitions, printPersistentVolumeClaimList)
|
||||||
|
@ -1328,11 +1330,14 @@ func printPersistentVolume(obj *api.PersistentVolume, options printers.PrintOpti
|
||||||
if obj.ObjectMeta.DeletionTimestamp != nil {
|
if obj.ObjectMeta.DeletionTimestamp != nil {
|
||||||
phase = "Terminating"
|
phase = "Terminating"
|
||||||
}
|
}
|
||||||
|
volumeMode := "<unset>"
|
||||||
|
if obj.Spec.VolumeMode != nil {
|
||||||
|
volumeMode = string(*obj.Spec.VolumeMode)
|
||||||
|
}
|
||||||
|
|
||||||
row.Cells = append(row.Cells, obj.Name, aSize, modesStr, reclaimPolicyStr,
|
row.Cells = append(row.Cells, obj.Name, aSize, modesStr, reclaimPolicyStr,
|
||||||
string(phase), claimRefUID, helper.GetPersistentVolumeClass(obj),
|
string(phase), claimRefUID, helper.GetPersistentVolumeClass(obj),
|
||||||
obj.Status.Reason,
|
obj.Status.Reason, translateTimestampSince(obj.CreationTimestamp), volumeMode)
|
||||||
translateTimestampSince(obj.CreationTimestamp))
|
|
||||||
return []metav1beta1.TableRow{row}, nil
|
return []metav1beta1.TableRow{row}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1361,13 +1366,19 @@ func printPersistentVolumeClaim(obj *api.PersistentVolumeClaim, options printers
|
||||||
storage := obj.Spec.Resources.Requests[api.ResourceStorage]
|
storage := obj.Spec.Resources.Requests[api.ResourceStorage]
|
||||||
capacity := ""
|
capacity := ""
|
||||||
accessModes := ""
|
accessModes := ""
|
||||||
|
volumeMode := "<unset>"
|
||||||
if obj.Spec.VolumeName != "" {
|
if obj.Spec.VolumeName != "" {
|
||||||
accessModes = helper.GetAccessModesAsString(obj.Status.AccessModes)
|
accessModes = helper.GetAccessModesAsString(obj.Status.AccessModes)
|
||||||
storage = obj.Status.Capacity[api.ResourceStorage]
|
storage = obj.Status.Capacity[api.ResourceStorage]
|
||||||
capacity = storage.String()
|
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
|
return []metav1beta1.TableRow{row}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import (
|
||||||
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
@ -3246,6 +3246,7 @@ func TestPrintReplicaSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintPersistentVolumeClaim(t *testing.T) {
|
func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
|
volumeMode := api.PersistentVolumeFilesystem
|
||||||
myScn := "my-scn"
|
myScn := "my-scn"
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
pvc api.PersistentVolumeClaim
|
pvc api.PersistentVolumeClaim
|
||||||
|
@ -3259,6 +3260,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
},
|
},
|
||||||
Spec: api.PersistentVolumeClaimSpec{
|
Spec: api.PersistentVolumeClaimSpec{
|
||||||
VolumeName: "my-volume",
|
VolumeName: "my-volume",
|
||||||
|
VolumeMode: &volumeMode,
|
||||||
},
|
},
|
||||||
Status: api.PersistentVolumeClaimStatus{
|
Status: api.PersistentVolumeClaimStatus{
|
||||||
Phase: api.ClaimBound,
|
Phase: api.ClaimBound,
|
||||||
|
@ -3268,7 +3270,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"test1\tBound\tmy-volume\t4Gi\tROX\t\t<unknown>\n",
|
"test1\tBound\tmy-volume\t4Gi\tROX\t\t<unknown>\tFilesystem\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test name, num of containers, restarts, container ready status
|
// Test name, num of containers, restarts, container ready status
|
||||||
|
@ -3276,7 +3278,9 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "test2",
|
Name: "test2",
|
||||||
},
|
},
|
||||||
Spec: api.PersistentVolumeClaimSpec{},
|
Spec: api.PersistentVolumeClaimSpec{
|
||||||
|
VolumeMode: &volumeMode,
|
||||||
|
},
|
||||||
Status: api.PersistentVolumeClaimStatus{
|
Status: api.PersistentVolumeClaimStatus{
|
||||||
Phase: api.ClaimLost,
|
Phase: api.ClaimLost,
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{api.ReadOnlyMany},
|
AccessModes: []api.PersistentVolumeAccessMode{api.ReadOnlyMany},
|
||||||
|
@ -3285,7 +3289,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"test2\tLost\t\t\t\t\t<unknown>\n",
|
"test2\tLost\t\t\t\t\t<unknown>\tFilesystem\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test name, num of containers, restarts, container ready status
|
// Test name, num of containers, restarts, container ready status
|
||||||
|
@ -3295,6 +3299,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
},
|
},
|
||||||
Spec: api.PersistentVolumeClaimSpec{
|
Spec: api.PersistentVolumeClaimSpec{
|
||||||
VolumeName: "my-volume",
|
VolumeName: "my-volume",
|
||||||
|
VolumeMode: &volumeMode,
|
||||||
},
|
},
|
||||||
Status: api.PersistentVolumeClaimStatus{
|
Status: api.PersistentVolumeClaimStatus{
|
||||||
Phase: api.ClaimPending,
|
Phase: api.ClaimPending,
|
||||||
|
@ -3304,7 +3309,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"test3\tPending\tmy-volume\t10Gi\tRWX\t\t<unknown>\n",
|
"test3\tPending\tmy-volume\t10Gi\tRWX\t\t<unknown>\tFilesystem\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test name, num of containers, restarts, container ready status
|
// Test name, num of containers, restarts, container ready status
|
||||||
|
@ -3312,6 +3317,27 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "test4",
|
Name: "test4",
|
||||||
},
|
},
|
||||||
|
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\tPending\tmy-volume\t10Gi\tRWO\tmy-scn\t<unknown>\tFilesystem\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Test name, num of containers, restarts, container ready status
|
||||||
|
api.PersistentVolumeClaim{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test5",
|
||||||
|
},
|
||||||
Spec: api.PersistentVolumeClaimSpec{
|
Spec: api.PersistentVolumeClaimSpec{
|
||||||
VolumeName: "my-volume",
|
VolumeName: "my-volume",
|
||||||
StorageClassName: &myScn,
|
StorageClassName: &myScn,
|
||||||
|
@ -3324,17 +3350,17 @@ func TestPrintPersistentVolumeClaim(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"test4\tPending\tmy-volume\t10Gi\tRWO\tmy-scn\t<unknown>\n",
|
"test5\tPending\tmy-volume\t10Gi\tRWO\tmy-scn\t<unknown>\t<unset>\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
for _, test := range tests {
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
verifyTable(t, table)
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if buf.String() != test.expect {
|
if buf.String() != test.expect {
|
||||||
|
|
Loading…
Reference in New Issue