mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Return no volume match if prebound PV node affinity doesn't match node
This commit is contained in:
@@ -169,12 +169,13 @@ func findMatchingVolume(
|
||||
continue
|
||||
}
|
||||
|
||||
nodeAffinityValid := true
|
||||
if node != nil {
|
||||
// Scheduler path, check that the PV NodeAffinity
|
||||
// is satisfied by the node
|
||||
err := volumeutil.CheckNodeAffinity(volume, node.Labels)
|
||||
if err != nil {
|
||||
continue
|
||||
nodeAffinityValid = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +186,14 @@ func findMatchingVolume(
|
||||
if volumeQty.Cmp(requestedQty) < 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// If PV node affinity is invalid, return no match.
|
||||
// This means the prebound PV (and therefore PVC)
|
||||
// is not suitable for this node.
|
||||
if !nodeAffinityValid {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return volume, nil
|
||||
}
|
||||
|
||||
@@ -199,6 +208,7 @@ func findMatchingVolume(
|
||||
// - volumes bound to another claim
|
||||
// - volumes whose labels don't match the claim's selector, if specified
|
||||
// - volumes in Class that is not requested
|
||||
// - volumes whose NodeAffinity does not match the node
|
||||
if volume.Spec.ClaimRef != nil {
|
||||
continue
|
||||
} else if selector != nil && !selector.Matches(labels.Set(volume.Labels)) {
|
||||
@@ -207,6 +217,9 @@ func findMatchingVolume(
|
||||
if v1helper.GetPersistentVolumeClass(volume) != requestedClass {
|
||||
continue
|
||||
}
|
||||
if !nodeAffinityValid {
|
||||
continue
|
||||
}
|
||||
|
||||
if node != nil {
|
||||
// Scheduler path
|
||||
|
||||
@@ -1218,7 +1218,7 @@ func TestFindMatchVolumeWithNode(t *testing.T) {
|
||||
pvc.Spec.StorageClassName = &classWait
|
||||
pvc.Name = "claim02"
|
||||
}),
|
||||
node: node2,
|
||||
node: node3,
|
||||
},
|
||||
"success-bad-and-good-node-affinity": {
|
||||
expectedMatch: "affinity-pv3",
|
||||
|
||||
Reference in New Issue
Block a user