Merge pull request #50953 from zjj2wry/get-pvc
Automatic merge from submit-queue fix issue(#50937)Fix kubectl get pvc lose volume name **What this PR does / why we need it**: closes #50937 **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: this should has volumename column. ``` NAME STATUS CAPACITY ACCESS MODES STORAGECLASS AGE myclaim Bound pv-gcepd2 5Gi ROX slow 35m myclaim2 Bound pv-gcepd 5Gi ROX slow 25m ``` **Release note**: ```release-note NONE ```
This commit is contained in:
		| @@ -286,6 +286,7 @@ func AddHandlers(h printers.PrintHandler) { | |||||||
| 	persistentVolumeClaimColumnDefinitions := []metav1alpha1.TableColumnDefinition{ | 	persistentVolumeClaimColumnDefinitions := []metav1alpha1.TableColumnDefinition{ | ||||||
| 		{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, | 		{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, | ||||||
| 		{Name: "Status", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["phase"]}, | 		{Name: "Status", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["phase"]}, | ||||||
|  | 		{Name: "Volume", Type: "string", Description: apiv1.PersistentVolumeSpec{}.SwaggerDoc()["volumeName"]}, | ||||||
| 		{Name: "Capacity", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["capacity"]}, | 		{Name: "Capacity", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["capacity"]}, | ||||||
| 		{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"}, | ||||||
|   | |||||||
| @@ -2917,3 +2917,103 @@ func TestPrintReplicaSet(t *testing.T) { | |||||||
| 		buf.Reset() | 		buf.Reset() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestPrintPersistentVolumeClaim(t *testing.T) { | ||||||
|  | 	myScn := "my-scn" | ||||||
|  | 	tests := []struct { | ||||||
|  | 		pvc    api.PersistentVolumeClaim | ||||||
|  | 		expect string | ||||||
|  | 	}{ | ||||||
|  | 		{ | ||||||
|  | 			// Test name, num of containers, restarts, container ready status | ||||||
|  | 			api.PersistentVolumeClaim{ | ||||||
|  | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
|  | 					Name: "test1", | ||||||
|  | 				}, | ||||||
|  | 				Spec: api.PersistentVolumeClaimSpec{ | ||||||
|  | 					VolumeName: "my-volume", | ||||||
|  | 				}, | ||||||
|  | 				Status: api.PersistentVolumeClaimStatus{ | ||||||
|  | 					Phase:       api.ClaimBound, | ||||||
|  | 					AccessModes: []api.PersistentVolumeAccessMode{api.ReadOnlyMany}, | ||||||
|  | 					Capacity: map[api.ResourceName]resource.Quantity{ | ||||||
|  | 						api.ResourceStorage: resource.MustParse("4Gi"), | ||||||
|  | 					}, | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
|  | 			"test1\tBound\tmy-volume\t4Gi\tROX\t\t<unknown>\n", | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			// Test name, num of containers, restarts, container ready status | ||||||
|  | 			api.PersistentVolumeClaim{ | ||||||
|  | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
|  | 					Name: "test2", | ||||||
|  | 				}, | ||||||
|  | 				Spec: api.PersistentVolumeClaimSpec{}, | ||||||
|  | 				Status: api.PersistentVolumeClaimStatus{ | ||||||
|  | 					Phase:       api.ClaimLost, | ||||||
|  | 					AccessModes: []api.PersistentVolumeAccessMode{api.ReadOnlyMany}, | ||||||
|  | 					Capacity: map[api.ResourceName]resource.Quantity{ | ||||||
|  | 						api.ResourceStorage: resource.MustParse("4Gi"), | ||||||
|  | 					}, | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
|  | 			"test2\tLost\t\t\t\t\t<unknown>\n", | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			// Test name, num of containers, restarts, container ready status | ||||||
|  | 			api.PersistentVolumeClaim{ | ||||||
|  | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
|  | 					Name: "test3", | ||||||
|  | 				}, | ||||||
|  | 				Spec: api.PersistentVolumeClaimSpec{ | ||||||
|  | 					VolumeName: "my-volume", | ||||||
|  | 				}, | ||||||
|  | 				Status: api.PersistentVolumeClaimStatus{ | ||||||
|  | 					Phase:       api.ClaimPending, | ||||||
|  | 					AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteMany}, | ||||||
|  | 					Capacity: map[api.ResourceName]resource.Quantity{ | ||||||
|  | 						api.ResourceStorage: resource.MustParse("10Gi"), | ||||||
|  | 					}, | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
|  | 			"test3\tPending\tmy-volume\t10Gi\tRWX\t\t<unknown>\n", | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			// Test name, num of containers, restarts, container ready status | ||||||
|  | 			api.PersistentVolumeClaim{ | ||||||
|  | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
|  | 					Name: "test4", | ||||||
|  | 				}, | ||||||
|  | 				Spec: api.PersistentVolumeClaimSpec{ | ||||||
|  | 					VolumeName:       "my-volume", | ||||||
|  | 					StorageClassName: &myScn, | ||||||
|  | 				}, | ||||||
|  | 				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>\n", | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | 	buf := bytes.NewBuffer([]byte{}) | ||||||
|  | 	for _, test := range tests { | ||||||
|  | 		table, err := printers.NewTablePrinter().With(AddHandlers).PrintTable(&test.pvc, printers.PrintOptions{}) | ||||||
|  | 		if err != nil { | ||||||
|  | 			t.Fatal(err) | ||||||
|  | 		} | ||||||
|  | 		if err := printers.PrintTable(table, buf, printers.PrintOptions{NoHeaders: true}); err != nil { | ||||||
|  | 			t.Fatal(err) | ||||||
|  | 		} | ||||||
|  | 		if buf.String() != test.expect { | ||||||
|  | 			fmt.Println(buf.String()) | ||||||
|  | 			fmt.Println(test.expect) | ||||||
|  | 			t.Fatalf("Expected: %s, but got: %s", test.expect, buf.String()) | ||||||
|  | 		} | ||||||
|  | 		buf.Reset() | ||||||
|  | 	} | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Submit Queue
					Kubernetes Submit Queue