Unverified Commit 1dae5f04 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #58522 from jsafrane/fix-binding-error-messages

Automatic merge from submit-queue (batch tested with PRs 54242, 58522, 58704, 58708, 58712). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Clean up error messages for pre-bound PVCs. When a PVC explicitly requests specific PV and the PV does not match, we should tell the user what exactly does not match. From: `Volume's size is smaller than requested or volume's class does not match with claim` To: `Cannot bind to requested volume "<volume name>": %s`, where `%s` is one of: - `requested PV is too small` - `storageClasseNames do not match` - `incompatible volumeMode` - `error checking volumeMode: api defaulting for volumeMode failed` (this should not ever happen) /sig storage @kubernetes/sig-storage-pr-reviews **Release note**: ```release-note NONE ```
parents d3cc9390 24400c24
...@@ -235,22 +235,22 @@ func checkVolumeSatisfyClaim(volume *v1.PersistentVolume, claim *v1.PersistentVo ...@@ -235,22 +235,22 @@ func checkVolumeSatisfyClaim(volume *v1.PersistentVolume, claim *v1.PersistentVo
requestedSize := requestedQty.Value() requestedSize := requestedQty.Value()
isMisMatch, err := checkVolumeModeMisMatches(&claim.Spec, &volume.Spec) isMisMatch, err := checkVolumeModeMisMatches(&claim.Spec, &volume.Spec)
if err != nil { if err != nil {
return fmt.Errorf("error checking if volumeMode was a mismatch: %v", err) return fmt.Errorf("error checking volumeMode: %v", err)
} }
volumeQty := volume.Spec.Capacity[v1.ResourceStorage] volumeQty := volume.Spec.Capacity[v1.ResourceStorage]
volumeSize := volumeQty.Value() volumeSize := volumeQty.Value()
if volumeSize < requestedSize { if volumeSize < requestedSize {
return fmt.Errorf("Storage capacity of volume[%s] requested by claim[%v] is not enough", volume.Name, claimToClaimKey(claim)) return fmt.Errorf("requested PV is too small")
} }
requestedClass := v1helper.GetPersistentVolumeClaimClass(claim) requestedClass := v1helper.GetPersistentVolumeClaimClass(claim)
if v1helper.GetPersistentVolumeClass(volume) != requestedClass { if v1helper.GetPersistentVolumeClass(volume) != requestedClass {
return fmt.Errorf("Class of volume[%s] is not the same as claim[%v]", volume.Name, claimToClaimKey(claim)) return fmt.Errorf("storageClasseName does not match")
} }
if isMisMatch { if isMisMatch {
return fmt.Errorf("VolumeMode[%v] of volume[%s] is incompatible with VolumeMode[%v] of claim[%v]", volume.Spec.VolumeMode, volume.Name, claim.Spec.VolumeMode, claim.Name) return fmt.Errorf("incompatible volumeMode")
} }
return nil return nil
...@@ -363,7 +363,8 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol ...@@ -363,7 +363,8 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol
if err = checkVolumeSatisfyClaim(volume, claim); err != nil { if err = checkVolumeSatisfyClaim(volume, claim); err != nil {
glog.V(4).Infof("Can't bind the claim to volume %q: %v", volume.Name, err) glog.V(4).Infof("Can't bind the claim to volume %q: %v", volume.Name, err)
//send a event //send a event
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, events.VolumeMismatch, "Volume's size is smaller than requested or volume's class does not match with claim") msg := fmt.Sprintf("Cannot bind to requested volume %q: %s", volume.Name, err)
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, events.VolumeMismatch, msg)
//volume does not satisfy the requirements of the claim //volume does not satisfy the requirements of the claim
if _, err = ctrl.updateClaimStatus(claim, v1.ClaimPending, nil); err != nil { if _, err = ctrl.updateClaimStatus(claim, v1.ClaimPending, nil); err != nil {
return err return err
......
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