diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index c67d028ba4..b02f04c38b 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -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 := "" + 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 := "" 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 } diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index 92692fb231..a5960d0019 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -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\tBound\tmy-volume\t4Gi\tROX\t\t\n", + "test1\tBound\tmy-volume\t4Gi\tROX\t\t\tFilesystem\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\tLost\t\t\t\t\t\n", + "test2\tLost\t\t\t\t\t\tFilesystem\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\tPending\tmy-volume\t10Gi\tRWX\t\t\n", + "test3\tPending\tmy-volume\t10Gi\tRWX\t\t\tFilesystem\n", }, { // Test name, num of containers, restarts, container ready status @@ -3312,6 +3317,27 @@ func TestPrintPersistentVolumeClaim(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ 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\tFilesystem\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, @@ -3324,17 +3350,17 @@ func TestPrintPersistentVolumeClaim(t *testing.T) { }, }, }, - "test4\tPending\tmy-volume\t10Gi\tRWO\tmy-scn\t\n", + "test5\tPending\tmy-volume\t10Gi\tRWO\tmy-scn\t\t\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 {