@@ -667,62 +667,69 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta Metadata, nodeInfo *sche
667
667
manifest := & (pod .Spec )
668
668
for i := range manifest .Volumes {
669
669
volume := & manifest .Volumes [i ]
670
- if volume .PersistentVolumeClaim != nil {
671
- pvcName := volume .PersistentVolumeClaim .ClaimName
672
- if pvcName == "" {
673
- return false , nil , fmt .Errorf ("PersistentVolumeClaim had no name" )
674
- }
675
- pvc , err := c .pvcLister .PersistentVolumeClaims (namespace ).Get (pvcName )
676
- if err != nil {
677
- return false , nil , err
678
- }
670
+ if volume .PersistentVolumeClaim == nil {
671
+ continue
672
+ }
673
+ pvcName := volume .PersistentVolumeClaim .ClaimName
674
+ if pvcName == "" {
675
+ return false , nil , fmt .Errorf ("PersistentVolumeClaim had no name" )
676
+ }
677
+ pvc , err := c .pvcLister .PersistentVolumeClaims (namespace ).Get (pvcName )
678
+ if err != nil {
679
+ return false , nil , err
680
+ }
679
681
680
- if pvc == nil {
681
- return false , nil , fmt .Errorf ("PersistentVolumeClaim was not found: %q" , pvcName )
682
- }
682
+ if pvc == nil {
683
+ return false , nil , fmt .Errorf ("PersistentVolumeClaim was not found: %q" , pvcName )
684
+ }
683
685
684
- pvName := pvc .Spec .VolumeName
685
- if pvName == "" {
686
- scName := v1helper .GetPersistentVolumeClaimClass (pvc )
687
- if len (scName ) > 0 {
688
- class , _ := c .scLister .Get (scName )
689
- if class != nil {
690
- if class .VolumeBindingMode == nil {
691
- return false , nil , fmt .Errorf ("VolumeBindingMode not set for StorageClass %q" , scName )
692
- }
693
- if * class .VolumeBindingMode == storage .VolumeBindingWaitForFirstConsumer {
694
- // Skip unbound volumes
695
- continue
696
- }
697
- }
698
- }
699
- return false , nil , fmt .Errorf ("PersistentVolumeClaim was not found: %q" , pvcName )
686
+ pvName := pvc .Spec .VolumeName
687
+ if pvName == "" {
688
+ scName := v1helper .GetPersistentVolumeClaimClass (pvc )
689
+ if len (scName ) == 0 {
690
+ return false , nil , fmt .Errorf ("PersistentVolumeClaim had no pv name and storageClass name" )
700
691
}
701
692
702
- pv , err := c .pvLister .Get (pvName )
703
- if err ! = nil {
704
- return false , nil , err
705
- }
693
+ class , _ := c .scLister .Get (scName )
694
+ if class = = nil {
695
+ return false , nil , fmt . Errorf ( "StorageClass %q claimed by PersistentVolumeClaim %q not found" ,
696
+ scName , pvcName )
706
697
707
- if pv == nil {
708
- return false , nil , fmt .Errorf ("PersistentVolume was not found: %q" , pvName )
698
+ }
699
+ if class .VolumeBindingMode == nil {
700
+ return false , nil , fmt .Errorf ("VolumeBindingMode not set for StorageClass %q" , scName )
701
+ }
702
+ if * class .VolumeBindingMode == storage .VolumeBindingWaitForFirstConsumer {
703
+ // Skip unbound volumes
704
+ continue
709
705
}
710
706
711
- for k , v := range pv .ObjectMeta .Labels {
712
- if k != v1 .LabelZoneFailureDomain && k != v1 .LabelZoneRegion {
713
- continue
714
- }
715
- nodeV , _ := nodeConstraints [k ]
716
- volumeVSet , err := volumehelpers .LabelZonesToSet (v )
717
- if err != nil {
718
- klog .Warningf ("Failed to parse label for %q: %q. Ignoring the label. err=%v. " , k , v , err )
719
- continue
720
- }
707
+ return false , nil , fmt .Errorf ("PersistentVolume had no name" )
708
+ }
721
709
722
- if ! volumeVSet .Has (nodeV ) {
723
- klog .V (10 ).Infof ("Won't schedule pod %q onto node %q due to volume %q (mismatch on %q)" , pod .Name , node .Name , pvName , k )
724
- return false , []PredicateFailureReason {ErrVolumeZoneConflict }, nil
725
- }
710
+ pv , err := c .pvLister .Get (pvName )
711
+ if err != nil {
712
+ return false , nil , err
713
+ }
714
+
715
+ if pv == nil {
716
+ return false , nil , fmt .Errorf ("PersistentVolume was not found: %q" , pvName )
717
+ }
718
+
719
+ for k , v := range pv .ObjectMeta .Labels {
720
+ if k != v1 .LabelZoneFailureDomain && k != v1 .LabelZoneRegion {
721
+ continue
722
+ }
723
+ nodeV , _ := nodeConstraints [k ]
724
+ volumeVSet , err := volumehelpers .LabelZonesToSet (v )
725
+ if err != nil {
726
+ klog .Warningf ("Failed to parse label for %q: %q. Ignoring the label. err=%v. " , k , v , err )
727
+ continue
728
+ }
729
+
730
+ if ! volumeVSet .Has (nodeV ) {
731
+ klog .V (10 ).Infof ("Won't schedule pod %q onto node %q due to volume %q (mismatch on %q)" , pod .Name , node .Name , pvName , k )
732
+ return false , []PredicateFailureReason {ErrVolumeZoneConflict }, nil
726
733
}
727
734
}
728
735
}
0 commit comments