Skip to content

Commit c70e3e9

Browse files
authored
Merge pull request kubernetes#89845 from yuga711/pvc-pv
Added events for failures in PV/PVC processing.
2 parents b54c4ea + 5a4f1be commit c70e3e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/controller/volume/persistentvolume/pv_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol
415415
// OBSERVATION: pvc is "Pending", pv is "Bound"
416416
if !metav1.HasAnnotation(claim.ObjectMeta, pvutil.AnnBoundByController) {
417417
klog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: volume already bound to different claim by user, will retry later", claimToClaimKey(claim))
418+
claimMsg := fmt.Sprintf("volume %q already bound to a different claim.", volume.Name)
419+
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, events.FailedBinding, claimMsg)
418420
// User asked for a specific PV, retry later
419421
if _, err = ctrl.updateClaimStatus(claim, v1.ClaimPending, nil); err != nil {
420422
return err
@@ -424,6 +426,9 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol
424426
// This should never happen because someone had to remove
425427
// AnnBindCompleted annotation on the claim.
426428
klog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: volume already bound to different claim %q by controller, THIS SHOULD NEVER HAPPEN", claimToClaimKey(claim), claimrefToClaimKey(volume.Spec.ClaimRef))
429+
claimMsg := fmt.Sprintf("volume %q already bound to a different claim.", volume.Name)
430+
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, events.FailedBinding, claimMsg)
431+
427432
return fmt.Errorf("Invalid binding of claim %q to volume %q: volume already claimed by %q", claimToClaimKey(claim), claim.Spec.VolumeName, claimrefToClaimKey(volume.Spec.ClaimRef))
428433
}
429434
}
@@ -604,12 +609,15 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *v1.PersistentVolume)
604609
return err
605610
}
606611
}
607-
608612
if err = ctrl.reclaimVolume(volume); err != nil {
609613
// Release failed, we will fall back into the same condition
610614
// in the next call to this method
611615
return err
612616
}
617+
if volume.Spec.PersistentVolumeReclaimPolicy == v1.PersistentVolumeReclaimRetain {
618+
// volume is being retained, it references a claim that does not exist now.
619+
klog.V(4).Infof("PersistentVolume[%s] references a claim %q (%s) that is not found", volume.Name, claimrefToClaimKey(volume.Spec.ClaimRef), volume.Spec.ClaimRef.UID)
620+
}
613621
return nil
614622
} else if claim.Spec.VolumeName == "" {
615623
if pvutil.CheckVolumeModeMismatches(&claim.Spec, &volume.Spec) {

0 commit comments

Comments
 (0)