Return no volume match if prebound PV node affinity doesn't match node

This commit is contained in:
Michelle Au
2017-11-29 17:29:58 -08:00
parent 2aeace402a
commit c26debecef
3 changed files with 18 additions and 5 deletions

View File

@@ -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

View File

@@ -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",