Skip to content

Commit cd9c412

Browse files
authored
[scheduler] get all pvcs in shouldProcessPod (#78)
* [scheduler] get all pvcs in shouldProcessPod Signed-off-by: Slava V <[email protected]> * [scheduler] make gci fix Signed-off-by: Slava V <[email protected]> * [scheduler] run gci Signed-off-by: Slava V <[email protected]> --------- Signed-off-by: Slava V <[email protected]>
1 parent 64bc17f commit cd9c412

File tree

1 file changed

+14
-4
lines changed
  • images/csi-nfs-scheduler-extender/src/pkg/scheduler

1 file changed

+14
-4
lines changed

images/csi-nfs-scheduler-extender/src/pkg/scheduler/func.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ func shouldProcessPod(ctx context.Context, cl client.Client, log logger.Logger,
4949
shouldProcessPod := false
5050
targetProvisionerVolumes := make([]corev1.Volume, 0)
5151

52+
pvcs := &corev1.PersistentVolumeClaimList{}
53+
err := cl.List(ctx, pvcs, client.InNamespace(pod.Namespace))
54+
if err != nil {
55+
return false, nil, fmt.Errorf("[ShouldProcessPod] error getting PVCs in namespace %s: %v", pod.Namespace, err)
56+
}
57+
58+
pvcMap := make(map[string]*corev1.PersistentVolumeClaim, len(pvcs.Items))
59+
for _, pvc := range pvcs.Items {
60+
pvcMap[pvc.Name] = &pvc
61+
}
62+
5263
for _, volume := range pod.Spec.Volumes {
5364
if volume.PersistentVolumeClaim == nil {
5465
log.Trace(fmt.Sprintf("[ShouldProcessPod] skip volume %s because it doesn't have PVC", volume.Name))
@@ -57,10 +68,9 @@ func shouldProcessPod(ctx context.Context, cl client.Client, log logger.Logger,
5768

5869
log.Trace(fmt.Sprintf("[ShouldProcessPod] process volume: %+v that has pvc: %+v", volume, volume.PersistentVolumeClaim))
5970
pvcName := volume.PersistentVolumeClaim.ClaimName
60-
pvc := &corev1.PersistentVolumeClaim{}
61-
err := cl.Get(ctx, client.ObjectKey{Namespace: pod.Namespace, Name: pvcName}, pvc)
62-
if err != nil {
63-
return false, nil, fmt.Errorf("[ShouldProcessPod] error getting PVC %s/%s: %v", pod.Namespace, pvcName, err)
71+
pvc, found := pvcMap[pvcName]
72+
if !found {
73+
return false, nil, fmt.Errorf("[ShouldProcessPod] found no pvc %s in namespace %s", pvcName, pod.Namespace)
6474
}
6575

6676
log.Trace(fmt.Sprintf("[ShouldProcessPod] Successfully get PVC %s/%s: %+v", pod.Namespace, pvcName, pvc))

0 commit comments

Comments
 (0)