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{
_,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 its PersistentVolume. Data on the volume is lost!");err!=nil{
_,err=ctrl.updateClaimPhaseWithEvent(claim,api.ClaimLost,api.EventTypeWarning,"ClaimLost","Bound claim has lost its PersistentVolume. Data on the volume is lost!")
returnerr
}
volume,ok:=obj.(*api.PersistentVolume)
if!ok{
returnfmt.Errorf("Cannot convert object from volume cache to volume %q!?: %+v",claim.Spec.VolumeName,obj)
glog.V(4).Infof("synchronizing bound PersistentVolumeClaim[%s]: claim is already correctly bound",claimToClaimKey(claim))
ifvolume.Spec.ClaimRef==nil{
iferr=ctrl.bind(volume,claim);err!=nil{
// Claim is bound but volume has come unbound.
// Objects not saved, next syncPV or syncClaim will try again
// Or, a claim was bound and the controller has not received updated
returnerr
// 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))
iferr=ctrl.bind(volume,claim);err!=nil{
// Objects not saved, next syncPV or syncClaim will try again
returnerr
}
returnnil
}elseifvolume.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))
iferr=ctrl.bind(volume,claim);err!=nil{
// Objects not saved, next syncPV or syncClaim will try again
returnerr
}
returnnil
}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{
returnerr
}
returnnil
}
}
returnnil
}
}
// Claim is bound but volume has a different claimant.
// Set the claim phase to 'Lost', which is a terminal
// phase.
_,err=ctrl.updateClaimPhaseWithEvent(claim,api.ClaimLost,api.EventTypeWarning,"ClaimMisbound","Two claims are bound to the same volume, this one is bound incorrectly")
returnerr
}
}
// 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.