From 40815ecb05de88a729863dcc736c8a994428eb66 Mon Sep 17 00:00:00 2001 From: nitesh3108 Date: Tue, 28 Nov 2023 11:41:14 -0500 Subject: [PATCH 1/3] handle segmentation violation --- internal/k8s/volume_finder.go | 7 +++ internal/k8s/volume_finder_test.go | 76 ++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/internal/k8s/volume_finder.go b/internal/k8s/volume_finder.go index 505449b..6abf0bd 100644 --- a/internal/k8s/volume_finder.go +++ b/internal/k8s/volume_finder.go @@ -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 diff --git a/internal/k8s/volume_finder_test.go b/internal/k8s/volume_finder_test.go index 024ea47..2bb4d10 100644 --- a/internal/k8s/volume_finder_test.go +++ b/internal/k8s/volume_finder_test.go @@ -326,6 +326,82 @@ 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-name", + CreationTimestamp: metav1.Time{Time: t1}, + }, + Spec: corev1.PersistentVolumeSpec{ + Capacity: map[corev1.ResourceName]resource.Quantity{ + v1.ResourceStorage: resource.MustParse("16Gi"), + }, + PersistentVolumeSource: corev1.PersistentVolumeSource{}, + 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) From a617cd613acddfebfdbfd3b9deff47366326fb11 Mon Sep 17 00:00:00 2001 From: nitesh3108 Date: Tue, 28 Nov 2023 13:51:21 -0500 Subject: [PATCH 2/3] update codeowners --- .github/CODEOWNERS | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index edbca79..02424c3 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 + From 06b21b396c3112c37a64d12be11123281c1574ed Mon Sep 17 00:00:00 2001 From: nitesh3108 Date: Wed, 29 Nov 2023 02:50:19 -0500 Subject: [PATCH 3/3] UT fix --- internal/k8s/volume_finder_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/k8s/volume_finder_test.go b/internal/k8s/volume_finder_test.go index 2bb4d10..90c5615 100644 --- a/internal/k8s/volume_finder_test.go +++ b/internal/k8s/volume_finder_test.go @@ -366,16 +366,24 @@ func Test_K8sPersistentVolumeFinder(t *testing.T) { }, { ObjectMeta: metav1.ObjectMeta{ - Name: "persistent-volume-name", + 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{}, - ClaimRef: nil, - StorageClassName: "storage-class-name", + 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",