mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Fill PV.Status.Message with deleter/recycler errors.
This commit is contained in:
parent
3d09b99d2c
commit
449e9f49d3
@ -337,7 +337,7 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
|
|||||||
if volume.Spec.ClaimRef == nil {
|
if volume.Spec.ClaimRef == nil {
|
||||||
// Volume is unused
|
// Volume is unused
|
||||||
glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is unused", volume.Name)
|
glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is unused", volume.Name)
|
||||||
if _, err := ctrl.updateVolumePhase(volume, api.VolumeAvailable); err != nil {
|
if _, err := ctrl.updateVolumePhase(volume, api.VolumeAvailable, ""); err != nil {
|
||||||
// Nothing was saved; we will fall back into the same
|
// Nothing was saved; we will fall back into the same
|
||||||
// condition in the next call to this method
|
// condition in the next call to this method
|
||||||
return err
|
return err
|
||||||
@ -349,7 +349,7 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
|
|||||||
// The PV is reserved for a PVC; that PVC has not yet been
|
// The PV is reserved for a PVC; that PVC has not yet been
|
||||||
// bound to this PV; the PVC sync will handle it.
|
// bound to this PV; the PVC sync will handle it.
|
||||||
glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is pre-bound to claim %s", volume.Name, claimrefToClaimKey(volume.Spec.ClaimRef))
|
glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is pre-bound to claim %s", volume.Name, claimrefToClaimKey(volume.Spec.ClaimRef))
|
||||||
if _, err := ctrl.updateVolumePhase(volume, api.VolumeAvailable); err != nil {
|
if _, err := ctrl.updateVolumePhase(volume, api.VolumeAvailable, ""); err != nil {
|
||||||
// Nothing was saved; we will fall back into the same
|
// Nothing was saved; we will fall back into the same
|
||||||
// condition in the next call to this method
|
// condition in the next call to this method
|
||||||
return err
|
return err
|
||||||
@ -394,7 +394,7 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
|
|||||||
if volume.Status.Phase != api.VolumeReleased && volume.Status.Phase != api.VolumeFailed {
|
if volume.Status.Phase != api.VolumeReleased && volume.Status.Phase != api.VolumeFailed {
|
||||||
// Also, log this only once:
|
// Also, log this only once:
|
||||||
glog.V(2).Infof("volume %q is released and reclaim policy %q will be executed", volume.Name, volume.Spec.PersistentVolumeReclaimPolicy)
|
glog.V(2).Infof("volume %q is released and reclaim policy %q will be executed", volume.Name, volume.Spec.PersistentVolumeReclaimPolicy)
|
||||||
if volume, err = ctrl.updateVolumePhase(volume, api.VolumeReleased); err != nil {
|
if volume, err = ctrl.updateVolumePhase(volume, api.VolumeReleased, ""); err != nil {
|
||||||
// Nothing was saved; we will fall back into the same condition
|
// Nothing was saved; we will fall back into the same condition
|
||||||
// in the next call to this method
|
// in the next call to this method
|
||||||
return err
|
return err
|
||||||
@ -435,7 +435,7 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
|
|||||||
} else if claim.Spec.VolumeName == volume.Name {
|
} else if claim.Spec.VolumeName == volume.Name {
|
||||||
// Volume is bound to a claim properly, update status if necessary
|
// Volume is bound to a claim properly, update status if necessary
|
||||||
glog.V(4).Infof("synchronizing PersistentVolume[%s]: all is bound", volume.Name)
|
glog.V(4).Infof("synchronizing PersistentVolume[%s]: all is bound", volume.Name)
|
||||||
if _, err = ctrl.updateVolumePhase(volume, api.VolumeBound); err != nil {
|
if _, err = ctrl.updateVolumePhase(volume, api.VolumeBound, ""); err != nil {
|
||||||
// Nothing was saved; we will fall back into the same
|
// Nothing was saved; we will fall back into the same
|
||||||
// condition in the next call to this method
|
// condition in the next call to this method
|
||||||
return err
|
return err
|
||||||
@ -539,7 +539,7 @@ func (ctrl *PersistentVolumeController) updateClaimPhaseWithEvent(claim *api.Per
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateVolumePhase saves new volume phase to API server.
|
// updateVolumePhase saves new volume phase to API server.
|
||||||
func (ctrl *PersistentVolumeController) updateVolumePhase(volume *api.PersistentVolume, phase api.PersistentVolumePhase) (*api.PersistentVolume, error) {
|
func (ctrl *PersistentVolumeController) updateVolumePhase(volume *api.PersistentVolume, phase api.PersistentVolumePhase, message string) (*api.PersistentVolume, error) {
|
||||||
glog.V(4).Infof("updating PersistentVolume[%s]: set phase %s", volume.Name, phase)
|
glog.V(4).Infof("updating PersistentVolume[%s]: set phase %s", volume.Name, phase)
|
||||||
if volume.Status.Phase == phase {
|
if volume.Status.Phase == phase {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
@ -557,6 +557,8 @@ func (ctrl *PersistentVolumeController) updateVolumePhase(volume *api.Persistent
|
|||||||
}
|
}
|
||||||
|
|
||||||
volumeClone.Status.Phase = phase
|
volumeClone.Status.Phase = phase
|
||||||
|
volumeClone.Status.Message = message
|
||||||
|
|
||||||
newVol, err := ctrl.kubeClient.Core().PersistentVolumes().UpdateStatus(volumeClone)
|
newVol, err := ctrl.kubeClient.Core().PersistentVolumes().UpdateStatus(volumeClone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("updating PersistentVolume[%s]: set phase %s failed: %v", volume.Name, phase, err)
|
glog.V(4).Infof("updating PersistentVolume[%s]: set phase %s failed: %v", volume.Name, phase, err)
|
||||||
@ -582,7 +584,7 @@ func (ctrl *PersistentVolumeController) updateVolumePhaseWithEvent(volume *api.P
|
|||||||
return volume, nil
|
return volume, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
newVol, err := ctrl.updateVolumePhase(volume, phase)
|
newVol, err := ctrl.updateVolumePhase(volume, phase, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -741,7 +743,7 @@ func (ctrl *PersistentVolumeController) bind(volume *api.PersistentVolume, claim
|
|||||||
}
|
}
|
||||||
volume = updatedVolume
|
volume = updatedVolume
|
||||||
|
|
||||||
if updatedVolume, err = ctrl.updateVolumePhase(volume, api.VolumeBound); err != nil {
|
if updatedVolume, err = ctrl.updateVolumePhase(volume, api.VolumeBound, ""); err != nil {
|
||||||
glog.V(3).Infof("error binding volume %q to claim %q: failed saving the volume status: %v", volume.Name, claimToClaimKey(claim), err)
|
glog.V(3).Infof("error binding volume %q to claim %q: failed saving the volume status: %v", volume.Name, claimToClaimKey(claim), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -811,7 +813,7 @@ func (ctrl *PersistentVolumeController) unbindVolume(volume *api.PersistentVolum
|
|||||||
glog.V(4).Infof("updating PersistentVolume[%s]: rolled back", newVol.Name)
|
glog.V(4).Infof("updating PersistentVolume[%s]: rolled back", newVol.Name)
|
||||||
|
|
||||||
// Update the status
|
// Update the status
|
||||||
_, err = ctrl.updateVolumePhase(newVol, api.VolumeAvailable)
|
_, err = ctrl.updateVolumePhase(newVol, api.VolumeAvailable, "")
|
||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func TestDeleteSync(t *testing.T) {
|
|||||||
// delete failure - plugin not found
|
// delete failure - plugin not found
|
||||||
"8-3 - plugin not found",
|
"8-3 - plugin not found",
|
||||||
newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", api.VolumeBound, api.PersistentVolumeReclaimDelete),
|
newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", api.VolumeBound, api.PersistentVolumeReclaimDelete),
|
||||||
newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", api.VolumeFailed, api.PersistentVolumeReclaimDelete),
|
withMessage("Error getting deleter volume plugin for volume \"volume8-3\": no volume plugin matched", newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", api.VolumeFailed, api.PersistentVolumeReclaimDelete)),
|
||||||
noclaims,
|
noclaims,
|
||||||
noclaims,
|
noclaims,
|
||||||
[]string{"Warning VolumeFailedDelete"}, noerrors, testSyncVolume,
|
[]string{"Warning VolumeFailedDelete"}, noerrors, testSyncVolume,
|
||||||
@ -66,7 +66,7 @@ func TestDeleteSync(t *testing.T) {
|
|||||||
// delete failure - newDeleter returns error
|
// delete failure - newDeleter returns error
|
||||||
"8-4 - newDeleter returns error",
|
"8-4 - newDeleter returns error",
|
||||||
newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", api.VolumeBound, api.PersistentVolumeReclaimDelete),
|
newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", api.VolumeBound, api.PersistentVolumeReclaimDelete),
|
||||||
newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", api.VolumeFailed, api.PersistentVolumeReclaimDelete),
|
withMessage("Failed to create deleter for volume \"volume8-4\": Mock plugin error: no deleteCalls configured", newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", api.VolumeFailed, api.PersistentVolumeReclaimDelete)),
|
||||||
noclaims,
|
noclaims,
|
||||||
noclaims,
|
noclaims,
|
||||||
[]string{"Warning VolumeFailedDelete"}, noerrors,
|
[]string{"Warning VolumeFailedDelete"}, noerrors,
|
||||||
@ -76,7 +76,7 @@ func TestDeleteSync(t *testing.T) {
|
|||||||
// delete failure - delete() returns error
|
// delete failure - delete() returns error
|
||||||
"8-5 - delete returns error",
|
"8-5 - delete returns error",
|
||||||
newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", api.VolumeBound, api.PersistentVolumeReclaimDelete),
|
newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", api.VolumeBound, api.PersistentVolumeReclaimDelete),
|
||||||
newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", api.VolumeFailed, api.PersistentVolumeReclaimDelete),
|
withMessage("Delete of volume \"volume8-5\" failed: Mock delete error", newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", api.VolumeFailed, api.PersistentVolumeReclaimDelete)),
|
||||||
noclaims,
|
noclaims,
|
||||||
noclaims,
|
noclaims,
|
||||||
[]string{"Warning VolumeFailedDelete"}, noerrors,
|
[]string{"Warning VolumeFailedDelete"}, noerrors,
|
||||||
|
@ -665,6 +665,14 @@ func withLabelSelector(labels map[string]string, claims []*api.PersistentVolumeC
|
|||||||
return claims
|
return claims
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// withMessage saves given message into volume.Status.Message of the first
|
||||||
|
// volume in the array and returns the array. Meant to be used to compose
|
||||||
|
// volumes specified inline in a test.
|
||||||
|
func withMessage(message string, volumes []*api.PersistentVolume) []*api.PersistentVolume {
|
||||||
|
volumes[0].Status.Message = message
|
||||||
|
return volumes
|
||||||
|
}
|
||||||
|
|
||||||
// newVolumeArray returns array with a single volume that would be returned by
|
// newVolumeArray returns array with a single volume that would be returned by
|
||||||
// newVolume() with the same parameters.
|
// newVolume() with the same parameters.
|
||||||
func newVolumeArray(name, capacity, boundToClaimUID, boundToClaimName string, phase api.PersistentVolumePhase, reclaimPolicy api.PersistentVolumeReclaimPolicy, annotations ...string) []*api.PersistentVolume {
|
func newVolumeArray(name, capacity, boundToClaimUID, boundToClaimName string, phase api.PersistentVolumePhase, reclaimPolicy api.PersistentVolumeReclaimPolicy, annotations ...string) []*api.PersistentVolume {
|
||||||
|
@ -57,7 +57,7 @@ func TestRecycleSync(t *testing.T) {
|
|||||||
// recycle failure - plugin not found
|
// recycle failure - plugin not found
|
||||||
"6-3 - plugin not found",
|
"6-3 - plugin not found",
|
||||||
newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", api.VolumeBound, api.PersistentVolumeReclaimRecycle),
|
newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", api.VolumeBound, api.PersistentVolumeReclaimRecycle),
|
||||||
newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", api.VolumeFailed, api.PersistentVolumeReclaimRecycle),
|
withMessage("No recycler plugin found for the volume!", newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", api.VolumeFailed, api.PersistentVolumeReclaimRecycle)),
|
||||||
noclaims,
|
noclaims,
|
||||||
noclaims,
|
noclaims,
|
||||||
[]string{"Warning VolumeFailedRecycle"}, noerrors, testSyncVolume,
|
[]string{"Warning VolumeFailedRecycle"}, noerrors, testSyncVolume,
|
||||||
@ -66,7 +66,7 @@ func TestRecycleSync(t *testing.T) {
|
|||||||
// recycle failure - newRecycler returns error
|
// recycle failure - newRecycler returns error
|
||||||
"6-4 - newRecycler returns error",
|
"6-4 - newRecycler returns error",
|
||||||
newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", api.VolumeBound, api.PersistentVolumeReclaimRecycle),
|
newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", api.VolumeBound, api.PersistentVolumeReclaimRecycle),
|
||||||
newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", api.VolumeFailed, api.PersistentVolumeReclaimRecycle),
|
withMessage("Failed to create recycler: Mock plugin error: no recycleCalls configured", newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", api.VolumeFailed, api.PersistentVolumeReclaimRecycle)),
|
||||||
noclaims,
|
noclaims,
|
||||||
noclaims,
|
noclaims,
|
||||||
[]string{"Warning VolumeFailedRecycle"}, noerrors,
|
[]string{"Warning VolumeFailedRecycle"}, noerrors,
|
||||||
@ -76,7 +76,7 @@ func TestRecycleSync(t *testing.T) {
|
|||||||
// recycle failure - recycle returns error
|
// recycle failure - recycle returns error
|
||||||
"6-5 - recycle returns error",
|
"6-5 - recycle returns error",
|
||||||
newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", api.VolumeBound, api.PersistentVolumeReclaimRecycle),
|
newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", api.VolumeBound, api.PersistentVolumeReclaimRecycle),
|
||||||
newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", api.VolumeFailed, api.PersistentVolumeReclaimRecycle),
|
withMessage("Recycler failed: Mock recycle error", newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", api.VolumeFailed, api.PersistentVolumeReclaimRecycle)),
|
||||||
noclaims,
|
noclaims,
|
||||||
noclaims,
|
noclaims,
|
||||||
[]string{"Warning VolumeFailedRecycle"}, noerrors,
|
[]string{"Warning VolumeFailedRecycle"}, noerrors,
|
||||||
@ -154,7 +154,7 @@ func TestRecycleSync(t *testing.T) {
|
|||||||
// volume has unknown reclaim policy - failure expected
|
// volume has unknown reclaim policy - failure expected
|
||||||
"6-10 - unknown reclaim policy",
|
"6-10 - unknown reclaim policy",
|
||||||
newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", api.VolumeBound, "Unknown"),
|
newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", api.VolumeBound, "Unknown"),
|
||||||
newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", api.VolumeFailed, "Unknown"),
|
withMessage("Volume has unrecognized PersistentVolumeReclaimPolicy", newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", api.VolumeFailed, "Unknown")),
|
||||||
noclaims,
|
noclaims,
|
||||||
noclaims,
|
noclaims,
|
||||||
[]string{"Warning VolumeUnknownReclaimPolicy"}, noerrors, testSyncVolume,
|
[]string{"Warning VolumeUnknownReclaimPolicy"}, noerrors, testSyncVolume,
|
||||||
|
Loading…
Reference in New Issue
Block a user