Unverified Commit 40c7c837 authored by k8s-ci-robot's avatar k8s-ci-robot Committed by GitHub

Merge pull request #68673 from cofyc/fix68391

Ignore non-avaiable volumes in findMatchingVolume
parents bcbc4f73 1e27a28d
...@@ -1222,6 +1222,9 @@ func (plugin *mockVolumePlugin) Provision(selectedNode *v1.Node, allowedTopologi ...@@ -1222,6 +1222,9 @@ func (plugin *mockVolumePlugin) Provision(selectedNode *v1.Node, allowedTopologi
GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{}, GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{},
}, },
}, },
Status: v1.PersistentVolumeStatus{
Phase: v1.VolumeAvailable,
},
} }
} }
......
...@@ -211,11 +211,18 @@ func findMatchingVolume( ...@@ -211,11 +211,18 @@ func findMatchingVolume(
} }
// filter out: // filter out:
// - volumes in non-available phase
// - volumes bound to another claim // - volumes bound to another claim
// - volumes whose labels don't match the claim's selector, if specified // - volumes whose labels don't match the claim's selector, if specified
// - volumes in Class that is not requested // - volumes in Class that is not requested
// - volumes whose NodeAffinity does not match the node // - volumes whose NodeAffinity does not match the node
if volume.Spec.ClaimRef != nil { if volume.Status.Phase != v1.VolumeAvailable {
// We ignore volumes in non-available phase, because volumes that
// satisfies matching criteria will be updated to available, binding
// them now has high chance of encountering unnecessary failures
// due to API conflicts.
continue
} else if volume.Spec.ClaimRef != nil {
continue continue
} else if selector != nil && !selector.Matches(labels.Set(volume.Labels)) { } else if selector != nil && !selector.Matches(labels.Set(volume.Labels)) {
continue continue
......
...@@ -166,7 +166,7 @@ func TestProvisionSync(t *testing.T) { ...@@ -166,7 +166,7 @@ func TestProvisionSync(t *testing.T) {
{ {
// No provisioning if there is a matching volume available // No provisioning if there is a matching volume available
"11-6 - provisioning when there is a volume available", "11-6 - provisioning when there is a volume available",
newVolumeArray("volume11-6", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classGold), newVolumeArray("volume11-6", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold),
newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, annBoundByController), newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, annBoundByController),
newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, &classGold, annBoundByController, annBindCompleted), newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, &classGold, annBoundByController, annBindCompleted),
......
...@@ -494,6 +494,9 @@ func makeTestPV(name, node, capacity, version string, boundToPVC *v1.PersistentV ...@@ -494,6 +494,9 @@ func makeTestPV(name, node, capacity, version string, boundToPVC *v1.PersistentV
}, },
StorageClassName: className, StorageClassName: className,
}, },
Status: v1.PersistentVolumeStatus{
Phase: v1.VolumeAvailable,
},
} }
if node != "" { if node != "" {
pv.Spec.NodeAffinity = getVolumeNodeAffinity(nodeLabelKey, node) pv.Spec.NodeAffinity = getVolumeNodeAffinity(nodeLabelKey, node)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment