Skip to content

Commit

Permalink
[scheduler] get all pvcs in shouldProcessPod
Browse files Browse the repository at this point in the history
Signed-off-by: Slava V <[email protected]>
  • Loading branch information
MrTomSawyer committed Feb 19, 2025
1 parent 4785a9d commit 4ce1a71
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions images/csi-nfs-scheduler-extender/src/pkg/scheduler/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ func shouldProcessPod(ctx context.Context, cl client.Client, log logger.Logger,
shouldProcessPod := false
targetProvisionerVolumes := make([]corev1.Volume, 0)

pvcs := &corev1.PersistentVolumeClaimList{}
err := cl.List(ctx, pvcs, client.InNamespace(pod.Namespace))
if err != nil {
return false, nil, fmt.Errorf("[ShouldProcessPod] error getting PVCs in namespace %s: %v", pod.Namespace, err)
}

pvcMap := make(map[string]*corev1.PersistentVolumeClaim, len(pvcs.Items))
for _, pvc := range pvcs.Items {
pvcMap[pvc.Name] = &pvc
}

for _, volume := range pod.Spec.Volumes {
if volume.PersistentVolumeClaim == nil {
log.Trace(fmt.Sprintf("[ShouldProcessPod] skip volume %s because it doesn't have PVC", volume.Name))
Expand All @@ -57,10 +68,9 @@ func shouldProcessPod(ctx context.Context, cl client.Client, log logger.Logger,

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

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

0 comments on commit 4ce1a71

Please sign in to comment.