@@ -165,7 +165,21 @@ func (pl *VolumeZone) getPVbyPod(logger klog.Logger, pod *v1.Pod) ([]pvTopology,
165
165
if s := getErrorAsStatus (err ); ! s .IsSuccess () {
166
166
return nil , s
167
167
}
168
- podPVTopologies = append (podPVTopologies , pl .getPVTopologiesFromPV (logger , pv )... )
168
+
169
+ for _ , key := range topologyLabels {
170
+ if value , ok := pv .ObjectMeta .Labels [key ]; ok {
171
+ volumeVSet , err := volumehelpers .LabelZonesToSet (value )
172
+ if err != nil {
173
+ logger .Info ("Failed to parse label, ignoring the label" , "label" , fmt .Sprintf ("%s:%s" , key , value ), "err" , err )
174
+ continue
175
+ }
176
+ podPVTopologies = append (podPVTopologies , pvTopology {
177
+ pvName : pv .Name ,
178
+ key : key ,
179
+ values : sets.Set [string ](volumeVSet ),
180
+ })
181
+ }
182
+ }
169
183
}
170
184
return podPVTopologies , nil
171
185
}
@@ -212,8 +226,33 @@ func (pl *VolumeZone) Filter(ctx context.Context, cs *framework.CycleState, pod
212
226
}
213
227
214
228
node := nodeInfo .Node ()
215
- status , _ := pl .isSchedulableNode (logger , podPVTopologies , node , pod )
216
- return status
229
+ hasAnyNodeConstraint := false
230
+ for _ , topologyLabel := range topologyLabels {
231
+ if _ , ok := node .Labels [topologyLabel ]; ok {
232
+ hasAnyNodeConstraint = true
233
+ break
234
+ }
235
+ }
236
+
237
+ if ! hasAnyNodeConstraint {
238
+ // The node has no zone constraints, so we're OK to schedule.
239
+ // This is to handle a single-zone cluster scenario where the node may not have any topology labels.
240
+ return nil
241
+ }
242
+
243
+ for _ , pvTopology := range podPVTopologies {
244
+ v , ok := node .Labels [pvTopology .key ]
245
+ if ! ok {
246
+ // if we can't match the beta label, try to match pv's beta label with node's ga label
247
+ v , ok = node .Labels [translateToGALabel (pvTopology .key )]
248
+ }
249
+ if ! ok || ! pvTopology .values .Has (v ) {
250
+ logger .V (10 ).Info ("Won't schedule pod onto node due to volume (mismatch on label key)" , "pod" , klog .KObj (pod ), "node" , klog .KObj (node ), "PV" , klog .KRef ("" , pvTopology .pvName ), "PVLabelKey" , pvTopology .key )
251
+ return framework .NewStatus (framework .UnschedulableAndUnresolvable , ErrReasonConflict )
252
+ }
253
+ }
254
+
255
+ return nil
217
256
}
218
257
219
258
func getStateData (cs * framework.CycleState ) (* stateData , error ) {
@@ -257,7 +296,7 @@ func (pl *VolumeZone) EventsToRegister() []framework.ClusterEventWithHint {
257
296
// See: https://github.com/kubernetes/kubernetes/issues/110175
258
297
{Event : framework.ClusterEvent {Resource : framework .Node , ActionType : framework .Add | framework .UpdateNodeLabel | framework .UpdateNodeTaint }},
259
298
// A new pvc may make a pod schedulable.
260
- // PVC 's VolumeName is mutable if old PVC's volumeName is empty .
299
+ // Also, if pvc 's VolumeName is filled, that also could make a pod schedulable .
261
300
{Event : framework.ClusterEvent {Resource : framework .PersistentVolumeClaim , ActionType : framework .Add | framework .Update }, QueueingHintFn : pl .isSchedulableAfterPersistentVolumeClaimChange },
262
301
// A new pv or updating a pv's volume zone labels may make a pod schedulable.
263
302
{Event : framework.ClusterEvent {Resource : framework .PersistentVolume , ActionType : framework .Add | framework .Update }},
@@ -278,36 +317,6 @@ func (pl *VolumeZone) getPersistentVolumeClaimNameFromPod(pod *v1.Pod) []string
278
317
return pvcNames
279
318
}
280
319
281
- // isSchedulablerNode checks whether the node can schedule the pod.
282
- func (pl * VolumeZone ) isSchedulableNode (logger klog.Logger , podPVTopologies []pvTopology , node * v1.Node , pod * v1.Pod ) (* framework.Status , bool ) {
283
- hasAnyNodeConstraint := false
284
- for _ , topologyLabel := range topologyLabels {
285
- if _ , ok := node .Labels [topologyLabel ]; ok {
286
- hasAnyNodeConstraint = true
287
- break
288
- }
289
- }
290
-
291
- if ! hasAnyNodeConstraint {
292
- // The node has no zone constraints, so we're OK to schedule.
293
- // This is to handle a single-zone cluster scenario where the node may not have any topology labels.
294
- return nil , true
295
- }
296
-
297
- for _ , pvTopology := range podPVTopologies {
298
- v , ok := node .Labels [pvTopology .key ]
299
- if ! ok {
300
- // if we can't match the beta label, try to match pv's beta label with node's ga label
301
- v , ok = node .Labels [translateToGALabel (pvTopology .key )]
302
- }
303
- if ! ok || ! pvTopology .values .Has (v ) {
304
- logger .V (10 ).Info ("Cannot schedule pod onto node due to volume (mismatch on label key)" , "pod" , klog .KObj (pod ), "node" , klog .KObj (node ), "PV" , klog .KRef ("" , pvTopology .pvName ), "PVLabelKey" , pvTopology .key )
305
- return framework .NewStatus (framework .UnschedulableAndUnresolvable , ErrReasonConflict ), false
306
- }
307
- }
308
- return nil , true
309
- }
310
-
311
320
// isSchedulableAfterPersistentVolumeClaimChange is invoked whenever a PersistentVolumeClaim added or updated.
312
321
// It checks whether the change of PVC has made a previously unschedulable pod schedulable.
313
322
// A PVC becoming bound or using a WaitForFirstConsumer storageclass can cause the pod to become schedulable.
@@ -334,12 +343,12 @@ func (pl *VolumeZone) isSchedulableAfterPersistentVolumeClaimChange(logger klog.
334
343
335
344
// checkPVCBindingToPodPV verifies if the PVC is bound to PV of a given Pod.
336
345
func (pl * VolumeZone ) checkPVCBindingToPodPV (logger klog.Logger , pvc * v1.PersistentVolumeClaim , pod * v1.Pod ) bool {
337
- if pvc == nil {
346
+ if ( pvc == nil ) || ( pod . Namespace != pvc . Namespace ) {
338
347
return false
339
348
}
340
349
pvcNames := pl .getPersistentVolumeClaimNameFromPod (pod )
341
350
for _ , pvcName := range pvcNames {
342
- if ( pvc .Name != pvcName ) || ( pod . Namespace != pvc . Namespace ) {
351
+ if pvc .Name != pvcName {
343
352
// pod's PVC doesn't match with the given PVC
344
353
continue
345
354
}
@@ -363,26 +372,6 @@ func (pl *VolumeZone) checkPVCBindingToPodPV(logger klog.Logger, pvc *v1.Persist
363
372
return false
364
373
}
365
374
366
- // getPVTopologiesFromPV retrieves pvTopology from a given PV and returns the array
367
- func (pl * VolumeZone ) getPVTopologiesFromPV (logger klog.Logger , pv * v1.PersistentVolume ) []pvTopology {
368
- podPVTopologies := make ([]pvTopology , 0 )
369
- for _ , key := range topologyLabels {
370
- if value , ok := pv .ObjectMeta .Labels [key ]; ok {
371
- volumeVSet , err := volumehelpers .LabelZonesToSet (value )
372
- if err != nil {
373
- logger .V (5 ).Info ("Failed to parse label, ignoring the label" , "label" , fmt .Sprintf ("%s:%s" , key , value ), "err" , err )
374
- continue
375
- }
376
- podPVTopologies = append (podPVTopologies , pvTopology {
377
- pvName : pv .Name ,
378
- key : key ,
379
- values : sets.Set [string ](volumeVSet ),
380
- })
381
- }
382
- }
383
- return podPVTopologies
384
- }
385
-
386
375
// New initializes a new plugin and returns it.
387
376
func New (_ context.Context , _ runtime.Object , handle framework.Handle ) (framework.Plugin , error ) {
388
377
informerFactory := handle .SharedInformerFactory ()
0 commit comments