mirror of https://github.com/k3s-io/k3s
Revert "controller/volume: simplify sync logic in syncBoundClaim"
This reverts commit 67787caeeb
.
pull/6/head
parent
f0fa9e588f
commit
a6d0dc0529
|
@ -258,55 +258,60 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu
|
||||||
// [Unit test set 3]
|
// [Unit test set 3]
|
||||||
if claim.Spec.VolumeName == "" {
|
if claim.Spec.VolumeName == "" {
|
||||||
// Claim was bound before but not any more.
|
// Claim was bound before but not any more.
|
||||||
_, err := ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimLost", "Bound claim has lost reference to PersistentVolume. Data on the volume is lost!")
|
if _, err := ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimLost", "Bound claim has lost reference to PersistentVolume. Data on the volume is lost!"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, found, err := ctrl.volumes.store.GetByKey(claim.Spec.VolumeName)
|
obj, found, err := ctrl.volumes.store.GetByKey(claim.Spec.VolumeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
// Claim is bound to a non-existing volume.
|
// Claim is bound to a non-existing volume.
|
||||||
_, err = ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimLost", "Bound claim has lost its PersistentVolume. Data on the volume is lost!")
|
if _, err = ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimLost", "Bound claim has lost its PersistentVolume. Data on the volume is lost!"); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
volume, ok := obj.(*api.PersistentVolume)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("Cannot convert object from volume cache to volume %q!?: %+v", claim.Spec.VolumeName, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume %q found: %s", claimToClaimKey(claim), claim.Spec.VolumeName, getVolumeStatusForLogging(volume))
|
|
||||||
if volume.Spec.ClaimRef == nil {
|
|
||||||
// Claim is bound but volume has come unbound.
|
|
||||||
// Or, a claim was bound and the controller has not received updated
|
|
||||||
// volume yet. We can't distinguish these cases.
|
|
||||||
// Bind the volume again and set all states to Bound.
|
|
||||||
glog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume is unbound, fixing", claimToClaimKey(claim))
|
|
||||||
if err = ctrl.bind(volume, claim); err != nil {
|
|
||||||
// Objects not saved, next syncPV or syncClaim will try again
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
} else {
|
||||||
if volume.Spec.ClaimRef.UID == claim.UID {
|
volume, ok := obj.(*api.PersistentVolume)
|
||||||
// All is well
|
if !ok {
|
||||||
// NOTE: syncPV can handle this so it can be left out.
|
return fmt.Errorf("Cannot convert object from volume cache to volume %q!?: %+v", claim.Spec.VolumeName, obj)
|
||||||
// NOTE: bind() call here will do nothing in most cases as
|
|
||||||
// everything should be already set.
|
|
||||||
glog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: claim is already correctly bound", claimToClaimKey(claim))
|
|
||||||
if err = ctrl.bind(volume, claim); err != nil {
|
|
||||||
// Objects not saved, next syncPV or syncClaim will try again
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Claim is bound but volume has a different claimant.
|
glog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume %q found: %s", claimToClaimKey(claim), claim.Spec.VolumeName, getVolumeStatusForLogging(volume))
|
||||||
// Set the claim phase to 'Lost', which is a terminal
|
if volume.Spec.ClaimRef == nil {
|
||||||
// phase.
|
// Claim is bound but volume has come unbound.
|
||||||
_, err = ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimMisbound", "Two claims are bound to the same volume, this one is bound incorrectly")
|
// Or, a claim was bound and the controller has not received updated
|
||||||
return err
|
// volume yet. We can't distinguish these cases.
|
||||||
|
// Bind the volume again and set all states to Bound.
|
||||||
|
glog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume is unbound, fixing", claimToClaimKey(claim))
|
||||||
|
if err = ctrl.bind(volume, claim); err != nil {
|
||||||
|
// Objects not saved, next syncPV or syncClaim will try again
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else if volume.Spec.ClaimRef.UID == claim.UID {
|
||||||
|
// All is well
|
||||||
|
// NOTE: syncPV can handle this so it can be left out.
|
||||||
|
// NOTE: bind() call here will do nothing in most cases as
|
||||||
|
// everything should be already set.
|
||||||
|
glog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: claim is already correctly bound", claimToClaimKey(claim))
|
||||||
|
if err = ctrl.bind(volume, claim); err != nil {
|
||||||
|
// Objects not saved, next syncPV or syncClaim will try again
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
// Claim is bound but volume has a different claimant.
|
||||||
|
// Set the claim phase to 'Lost', which is a terminal
|
||||||
|
// phase.
|
||||||
|
if _, err = ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimMisbound", "Two claims are bound to the same volume, this one is bound incorrectly"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncVolume is the main controller method to decide what to do with a volume.
|
// syncVolume is the main controller method to decide what to do with a volume.
|
||||||
|
|
Loading…
Reference in New Issue