Skip to content

Commit

Permalink
fix nil pointer error (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
YianZong authored Aug 18, 2022
1 parent e06daba commit 06da091
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/k8s/volume_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (f VolumeFinder) GetPersistentVolumes(ctx context.Context) ([]VolumeInfo, e
}

for _, volume := range volumes.Items {
if Contains(f.DriverNames, volume.Spec.CSI.Driver) {
if volume.Spec.CSI != nil && Contains(f.DriverNames, volume.Spec.CSI.Driver) {
capacity := volume.Spec.Capacity[v1.ResourceStorage]
claim := volume.Spec.ClaimRef
status := volume.Status
Expand Down
26 changes: 26 additions & 0 deletions internal/k8s/volume_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,32 @@ func Test_K8sPersistentVolumeFinder(t *testing.T) {
Phase: "Bound",
},
},
{ // non-CSI PV
ObjectMeta: metav1.ObjectMeta{
Name: "persistent-volume-name-3",
CreationTimestamp: metav1.Time{Time: t1},
},
Spec: corev1.PersistentVolumeSpec{
Capacity: map[corev1.ResourceName]resource.Quantity{
v1.ResourceStorage: resource.MustParse("16Gi"),
},
PersistentVolumeSource: corev1.PersistentVolumeSource{
NFS: &corev1.NFSVolumeSource{
Server: "nas-server",
Path: "file-path",
},
},
ClaimRef: &corev1.ObjectReference{
Name: "pvc-name-4",
Namespace: "namespace-4",
UID: "pvc-uid-4",
},
StorageClassName: "storage-class-name-4",
},
Status: corev1.PersistentVolumeStatus{
Phase: "Bound",
},
},
},
}

Expand Down

0 comments on commit 06da091

Please sign in to comment.