@@ -677,62 +677,69 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta PredicateMetadata, nodeI
677
677
manifest := & (pod .Spec )
678
678
for i := range manifest .Volumes {
679
679
volume := & manifest .Volumes [i ]
680
- if volume .PersistentVolumeClaim != nil {
681
- pvcName := volume .PersistentVolumeClaim .ClaimName
682
- if pvcName == "" {
683
- return false , nil , fmt .Errorf ("PersistentVolumeClaim had no name" )
684
- }
685
- pvc , err := c .pvcLister .PersistentVolumeClaims (namespace ).Get (pvcName )
686
- if err != nil {
687
- return false , nil , err
688
- }
680
+ if volume .PersistentVolumeClaim == nil {
681
+ continue
682
+ }
683
+ pvcName := volume .PersistentVolumeClaim .ClaimName
684
+ if pvcName == "" {
685
+ return false , nil , fmt .Errorf ("PersistentVolumeClaim had no name" )
686
+ }
687
+ pvc , err := c .pvcLister .PersistentVolumeClaims (namespace ).Get (pvcName )
688
+ if err != nil {
689
+ return false , nil , err
690
+ }
689
691
690
- if pvc == nil {
691
- return false , nil , fmt .Errorf ("PersistentVolumeClaim was not found: %q" , pvcName )
692
- }
692
+ if pvc == nil {
693
+ return false , nil , fmt .Errorf ("PersistentVolumeClaim was not found: %q" , pvcName )
694
+ }
693
695
694
- pvName := pvc .Spec .VolumeName
695
- if pvName == "" {
696
- scName := v1helper .GetPersistentVolumeClaimClass (pvc )
697
- if len (scName ) > 0 {
698
- class , _ := c .scLister .Get (scName )
699
- if class != nil {
700
- if class .VolumeBindingMode == nil {
701
- return false , nil , fmt .Errorf ("VolumeBindingMode not set for StorageClass %q" , scName )
702
- }
703
- if * class .VolumeBindingMode == storage .VolumeBindingWaitForFirstConsumer {
704
- // Skip unbound volumes
705
- continue
706
- }
707
- }
708
- }
709
- return false , nil , fmt .Errorf ("PersistentVolumeClaim was not found: %q" , pvcName )
696
+ pvName := pvc .Spec .VolumeName
697
+ if pvName == "" {
698
+ scName := v1helper .GetPersistentVolumeClaimClass (pvc )
699
+ if len (scName ) == 0 {
700
+ return false , nil , fmt .Errorf ("PersistentVolumeClaim had no pv name and storageClass name" )
710
701
}
711
702
712
- pv , err := c .pvLister .Get (pvName )
713
- if err ! = nil {
714
- return false , nil , err
715
- }
703
+ class , _ := c .scLister .Get (scName )
704
+ if class = = nil {
705
+ return false , nil , fmt . Errorf ( "StorageClass %q claimed by PersistentVolumeClaim %q not found" ,
706
+ scName , pvcName )
716
707
717
- if pv == nil {
718
- return false , nil , fmt .Errorf ("PersistentVolume was not found: %q" , pvName )
708
+ }
709
+ if class .VolumeBindingMode == nil {
710
+ return false , nil , fmt .Errorf ("VolumeBindingMode not set for StorageClass %q" , scName )
711
+ }
712
+ if * class .VolumeBindingMode == storage .VolumeBindingWaitForFirstConsumer {
713
+ // Skip unbound volumes
714
+ continue
719
715
}
720
716
721
- for k , v := range pv .ObjectMeta .Labels {
722
- if k != v1 .LabelZoneFailureDomain && k != v1 .LabelZoneRegion {
723
- continue
724
- }
725
- nodeV , _ := nodeConstraints [k ]
726
- volumeVSet , err := volumehelpers .LabelZonesToSet (v )
727
- if err != nil {
728
- klog .Warningf ("Failed to parse label for %q: %q. Ignoring the label. err=%v. " , k , v , err )
729
- continue
730
- }
717
+ return false , nil , fmt .Errorf ("PersistentVolume had no name" )
718
+ }
731
719
732
- if ! volumeVSet .Has (nodeV ) {
733
- 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 )
734
- return false , []PredicateFailureReason {ErrVolumeZoneConflict }, nil
735
- }
720
+ pv , err := c .pvLister .Get (pvName )
721
+ if err != nil {
722
+ return false , nil , err
723
+ }
724
+
725
+ if pv == nil {
726
+ return false , nil , fmt .Errorf ("PersistentVolume was not found: %q" , pvName )
727
+ }
728
+
729
+ for k , v := range pv .ObjectMeta .Labels {
730
+ if k != v1 .LabelZoneFailureDomain && k != v1 .LabelZoneRegion {
731
+ continue
732
+ }
733
+ nodeV , _ := nodeConstraints [k ]
734
+ volumeVSet , err := volumehelpers .LabelZonesToSet (v )
735
+ if err != nil {
736
+ klog .Warningf ("Failed to parse label for %q: %q. Ignoring the label. err=%v. " , k , v , err )
737
+ continue
738
+ }
739
+
740
+ if ! volumeVSet .Has (nodeV ) {
741
+ 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 )
742
+ return false , []PredicateFailureReason {ErrVolumeZoneConflict }, nil
736
743
}
737
744
}
738
745
}
0 commit comments