From 49dcdbe2c5aaae652d9c76fceb771670fbfcfcf9 Mon Sep 17 00:00:00 2001 From: mlmhl Date: Sat, 10 Feb 2018 19:22:15 +0800 Subject: [PATCH 1/2] add description of pvc condition for kubectl describe command --- pkg/printers/internalversion/describe.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/printers/internalversion/describe.go b/pkg/printers/internalversion/describe.go index bfcdfd33c02..9a68c295d7d 100644 --- a/pkg/printers/internalversion/describe.go +++ b/pkg/printers/internalversion/describe.go @@ -1264,6 +1264,20 @@ func describePersistentVolumeClaim(pvc *api.PersistentVolumeClaim, events *api.E if pvc.Spec.VolumeMode != nil { w.Write(LEVEL_0, "VolumeMode:\t%v\n", *pvc.Spec.VolumeMode) } + if len(pvc.Status.Conditions) > 0 { + w.Write(LEVEL_0, "Conditions:\n") + w.Write(LEVEL_1, "Type\tStatus\tLastProbeTime\tLastTransitionTime\tReason\tMessage\n") + w.Write(LEVEL_1, "----\t------\t-----------------\t------------------\t------\t-------\n") + for _, c := range pvc.Status.Conditions { + w.Write(LEVEL_1, "%v \t%v \t%s \t%s \t%v \t%v\n", + c.Type, + c.Status, + c.LastProbeTime.Time.Format(time.RFC1123Z), + c.LastTransitionTime.Time.Format(time.RFC1123Z), + c.Reason, + c.Message) + } + } if events != nil { DescribeEvents(events, w) } From c29728f220e5d973b2faafec66eb7a2ed613d400 Mon Sep 17 00:00:00 2001 From: mlmhl Date: Sat, 17 Mar 2018 15:26:30 +0800 Subject: [PATCH 2/2] add unit test for PVC conditions describer --- pkg/printers/internalversion/describe_test.go | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/pkg/printers/internalversion/describe_test.go b/pkg/printers/internalversion/describe_test.go index dc0775055e2..eea94efcba1 100644 --- a/pkg/printers/internalversion/describe_test.go +++ b/pkg/printers/internalversion/describe_test.go @@ -1020,6 +1020,7 @@ func TestPersistentVolumeClaimDescriber(t *testing.T) { block := api.PersistentVolumeBlock file := api.PersistentVolumeFilesystem goldClassName := "gold" + now := time.Now() testCases := []struct { name string pvc *api.PersistentVolumeClaim @@ -1070,6 +1071,103 @@ func TestPersistentVolumeClaimDescriber(t *testing.T) { }, expectedElements: []string{"VolumeMode", "Block"}, }, + // Tests for Status.Condition. + { + name: "condition-type", + pvc: &api.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, + Spec: api.PersistentVolumeClaimSpec{ + VolumeName: "volume4", + StorageClassName: &goldClassName, + }, + Status: api.PersistentVolumeClaimStatus{ + Conditions: []api.PersistentVolumeClaimCondition{ + {Type: api.PersistentVolumeClaimResizing}, + }, + }, + }, + expectedElements: []string{"Conditions", "Type", "Resizing"}, + }, + { + name: "condition-status", + pvc: &api.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, + Spec: api.PersistentVolumeClaimSpec{ + VolumeName: "volume5", + StorageClassName: &goldClassName, + }, + Status: api.PersistentVolumeClaimStatus{ + Conditions: []api.PersistentVolumeClaimCondition{ + {Status: api.ConditionTrue}, + }, + }, + }, + expectedElements: []string{"Conditions", "Status", "True"}, + }, + { + name: "condition-last-probe-time", + pvc: &api.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, + Spec: api.PersistentVolumeClaimSpec{ + VolumeName: "volume6", + StorageClassName: &goldClassName, + }, + Status: api.PersistentVolumeClaimStatus{ + Conditions: []api.PersistentVolumeClaimCondition{ + {LastProbeTime: metav1.Time{Time: now}}, + }, + }, + }, + expectedElements: []string{"Conditions", "LastProbeTime", now.Format(time.RFC1123Z)}, + }, + { + name: "condition-last-transition-time", + pvc: &api.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, + Spec: api.PersistentVolumeClaimSpec{ + VolumeName: "volume7", + StorageClassName: &goldClassName, + }, + Status: api.PersistentVolumeClaimStatus{ + Conditions: []api.PersistentVolumeClaimCondition{ + {LastTransitionTime: metav1.Time{Time: now}}, + }, + }, + }, + expectedElements: []string{"Conditions", "LastTransitionTime", now.Format(time.RFC1123Z)}, + }, + { + name: "condition-reason", + pvc: &api.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, + Spec: api.PersistentVolumeClaimSpec{ + VolumeName: "volume8", + StorageClassName: &goldClassName, + }, + Status: api.PersistentVolumeClaimStatus{ + Conditions: []api.PersistentVolumeClaimCondition{ + {Reason: "OfflineResize"}, + }, + }, + }, + expectedElements: []string{"Conditions", "Reason", "OfflineResize"}, + }, + { + name: "condition-message", + pvc: &api.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, + Spec: api.PersistentVolumeClaimSpec{ + VolumeName: "volume9", + StorageClassName: &goldClassName, + }, + Status: api.PersistentVolumeClaimStatus{ + Conditions: []api.PersistentVolumeClaimCondition{ + {Message: "User request resize"}, + }, + }, + }, + expectedElements: []string{"Conditions", "Message", "User request resize"}, + }, } for _, test := range testCases {