Skip to content

Commit

Permalink
handle segmentation violation (#68)
Browse files Browse the repository at this point in the history
* handle segmentation violation

* update codeowners

* UT fix
  • Loading branch information
nitesh3108 authored Nov 29, 2023
1 parent 4c89bc3 commit cafa894
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 14 deletions.
30 changes: 16 additions & 14 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@
# These are the default owners for the code and will
# be requested for review when someone opens a pull request.
#
# Sean Gallacher (gallacher)
# Trevor Dawe (tdawe)
# Aaron Tye (atye)
# Alexander Hoppe (hoppea2)
# Alik Saring (alikdell)
# Aaron Tye (atye)
# Florian Coulombel (coulof)
# Shayna Finocchiaro (shaynafinocchiaro)
# Sharmila Ramamoorthy (sharmilarama)
# Evgeny Uglov (EvgenyUglov)
# AnandatDell (anandrajak1)
# Bowen Jiang (bjiang27)
# Tao He (taohe1012)
# Peter Cao (P-Cao)
# Yiming Bao (baoy1)
# Yian Zong (YianZong)
# Forrest Xia (forrestxia)
# Chiman Jain (chimanjain)
# Don Khan (donatwork)
# Evgeny Uglov (EvgenyUglov)
# Florian Coulombel (coulof)
# Harish H (HarishH-DELL)
# Harsha Yalamanchili (harshaatdell)
# AnandatDell (anandrajak1)
# Nitesh Rewatkar (nitesh3108)
# Rajendra Indukuri (rajendraindukuri)
# Sean Gallacher (gallacher)
# Shefali Malhotra (shefali-malhotra)
# Sharmila Ramamoorthy (sharmilarama)
# Shayna Finocchiaro (shaynafinocchiaro)
# Spandita Panigrahi (panigs7)
# Trevor Dawe (tdawe)


# for all files:
* @gallacher @tdawe @alikdell @atye @hoppea2 @coulof @shaynafinocchiaro @sharmilarama @EvgenyUglov @bjiang27 @taohe1012 @P-Cao @baoy1 @YianZong @forrestxia @donatwork @harshaatdell @anandrajak1
* @atye @hoppea2 @alikdell @anandrajak1 @bjiang27 @chimanjain @donatwork @EvgenyUglov @coulof @HarishH-DELL @harshaatdell @nitesh3108 @rajendraindukuri @gallacher @shefali-malhotra @sharmilarama @shaynafinocchiaro @panigs7 @tdawe

7 changes: 7 additions & 0 deletions internal/k8s/volume_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func (f VolumeFinder) GetPersistentVolumes(ctx context.Context) ([]VolumeInfo, e
f.Logger.Debugf("The PV, %s , is not provisioned by a CSI driver\n", volume.GetName())
continue
}

// Check added to skip PV s which do not have any PVC s
if volume.Spec.ClaimRef == nil {
f.Logger.Debugf("The PV, %s , do not have a claim \n", volume.GetName())
continue
}

if contains(f.DriverNames, volume.Spec.CSI.Driver) {
capacity := volume.Spec.Capacity[v1.ResourceStorage]
claim := volume.Spec.ClaimRef
Expand Down
84 changes: 84 additions & 0 deletions internal/k8s/volume_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,90 @@ func Test_K8sPersistentVolumeFinder(t *testing.T) {
},
})), ctrl
},
"success filtering the persistent volumes which do not have claims": func(*testing.T) (k8s.VolumeFinder, []checkFn, *gomock.Controller) {
ctrl := gomock.NewController(t)
api := mocks.NewMockVolumeGetter(ctrl)

t1, err := time.Parse(time.RFC3339, "2020-07-28T20:00:00+00:00")
assert.Nil(t, err)

volumes := &corev1.PersistentVolumeList{
Items: []corev1.PersistentVolume{
{
ObjectMeta: metav1.ObjectMeta{
Name: "persistent-volume-name",
CreationTimestamp: metav1.Time{Time: t1},
},
Spec: corev1.PersistentVolumeSpec{
Capacity: map[corev1.ResourceName]resource.Quantity{
v1.ResourceStorage: resource.MustParse("16Gi"),
},
PersistentVolumeSource: corev1.PersistentVolumeSource{
CSI: &corev1.CSIPersistentVolumeSource{
Driver: "csi-powerstore.dellemc.com",
VolumeAttributes: map[string]string{
"arrayIP": "127.0.0.1",
},
VolumeHandle: "storage-system-volume-id/127.0.0.1/protocol",
},
},
ClaimRef: &corev1.ObjectReference{
Name: "pvc-name",
Namespace: "namespace-1",
UID: "pvc-uid",
},
StorageClassName: "storage-class-name",
},
Status: corev1.PersistentVolumeStatus{
Phase: "Bound",
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "persistent-volume-name2",
CreationTimestamp: metav1.Time{Time: t1},
},
Spec: corev1.PersistentVolumeSpec{
Capacity: map[corev1.ResourceName]resource.Quantity{
v1.ResourceStorage: resource.MustParse("16Gi"),
},
PersistentVolumeSource: corev1.PersistentVolumeSource{
CSI: &corev1.CSIPersistentVolumeSource{
Driver: "csi-powerstore.dellemc.com",
VolumeAttributes: map[string]string{
"arrayIP": "127.0.0.1",
},
VolumeHandle: "storage-system-volume-id/127.0.0.1/protocol",
},
},
ClaimRef: nil,
StorageClassName: "storage-class-name",
},
Status: corev1.PersistentVolumeStatus{
Phase: "Available",
},
},
},
}

api.EXPECT().GetPersistentVolumes().Times(1).Return(volumes, nil)

finder := k8s.VolumeFinder{API: api, DriverNames: []string{"csi-powerstore.dellemc.com"}, Logger: logrus.New()}
return finder, check(hasNoError, checkExpectedOutput([]k8s.VolumeInfo{
{
Namespace: "namespace-1",
PersistentVolumeClaim: "pvc-uid",
PersistentVolumeStatus: "Bound",
VolumeClaimName: "pvc-name",
PersistentVolume: "persistent-volume-name",
StorageClass: "storage-class-name",
Driver: "csi-powerstore.dellemc.com",
ProvisionedSize: "16Gi",
VolumeHandle: "storage-system-volume-id/127.0.0.1/protocol",
CreatedTime: t1.String(),
},
})), ctrl
},
"error calling k8s": func(*testing.T) (k8s.VolumeFinder, []checkFn, *gomock.Controller) {
ctrl := gomock.NewController(t)
api := mocks.NewMockVolumeGetter(ctrl)
Expand Down

0 comments on commit cafa894

Please sign in to comment.