Skip to content

Commit 991547e

Browse files
committed
Add kubectl describe CSINode test coverage
1 parent 238d2c8 commit 991547e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

staging/src/k8s.io/kubectl/pkg/describe/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4032,7 +4032,7 @@ func describeCSINode(csi *storagev1.CSINode, events *corev1.EventList) (output s
40324032
for _, driver := range csi.Spec.Drivers {
40334033
w.Write(LEVEL_2, "%s:\n", driver.Name)
40344034
w.Write(LEVEL_3, "Node ID:\t%s\n", driver.NodeID)
4035-
if driver.Allocatable.Count != nil {
4035+
if driver.Allocatable != nil && driver.Allocatable.Count != nil {
40364036
w.Write(LEVEL_3, "Allocatables:\n")
40374037
w.Write(LEVEL_4, "Count:\t%d\n", *driver.Allocatable.Count)
40384038
}

staging/src/k8s.io/kubectl/pkg/describe/describe_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,38 @@ func TestDescribeStorageClass(t *testing.T) {
17801780
}
17811781
}
17821782

1783+
func TestDescribeCSINode(t *testing.T) {
1784+
limit := utilpointer.Int32Ptr(int32(2))
1785+
f := fake.NewSimpleClientset(&storagev1.CSINode{
1786+
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
1787+
Spec: storagev1.CSINodeSpec{
1788+
Drivers: []storagev1.CSINodeDriver{
1789+
{
1790+
Name: "driver1",
1791+
NodeID: "node1",
1792+
},
1793+
{
1794+
Name: "driver2",
1795+
NodeID: "node2",
1796+
Allocatable: &storagev1.VolumeNodeResources{Count: limit},
1797+
},
1798+
},
1799+
},
1800+
})
1801+
s := CSINodeDescriber{f}
1802+
out, err := s.Describe("", "foo", DescriberSettings{ShowEvents: true})
1803+
if err != nil {
1804+
t.Errorf("unexpected error: %v", err)
1805+
}
1806+
if !strings.Contains(out, "foo") ||
1807+
!strings.Contains(out, "driver1") ||
1808+
!strings.Contains(out, "node1") ||
1809+
!strings.Contains(out, "driver2") ||
1810+
!strings.Contains(out, "node2") {
1811+
t.Errorf("unexpected out: %s", out)
1812+
}
1813+
}
1814+
17831815
func TestDescribePodDisruptionBudget(t *testing.T) {
17841816
minAvailable := intstr.FromInt(22)
17851817
f := fake.NewSimpleClientset(&policyv1beta1.PodDisruptionBudget{

0 commit comments

Comments
 (0)