mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Merge pull request #28813 from xiang90/pv_1
Automatic merge from submit-queue controller/volume: simplify sync logic in syncBoundClaim Remove all unnecessary branchings.
This commit is contained in:
commit
696cca21e2
@ -258,22 +258,19 @@ 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.
|
||||||
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!")
|
||||||
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.
|
||||||
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!")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
volume, ok := obj.(*api.PersistentVolume)
|
volume, ok := obj.(*api.PersistentVolume)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Cannot convert object from volume cache to volume %q!?: %+v", claim.Spec.VolumeName, obj)
|
return fmt.Errorf("Cannot convert object from volume cache to volume %q!?: %+v", claim.Spec.VolumeName, obj)
|
||||||
@ -291,7 +288,8 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else if volume.Spec.ClaimRef.UID == claim.UID {
|
}
|
||||||
|
if volume.Spec.ClaimRef.UID == claim.UID {
|
||||||
// All is well
|
// All is well
|
||||||
// NOTE: syncPV can handle this so it can be left out.
|
// NOTE: syncPV can handle this so it can be left out.
|
||||||
// NOTE: bind() call here will do nothing in most cases as
|
// NOTE: bind() call here will do nothing in most cases as
|
||||||
@ -302,16 +300,13 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Claim is bound but volume has a different claimant.
|
// Claim is bound but volume has a different claimant.
|
||||||
// Set the claim phase to 'Lost', which is a terminal
|
// Set the claim phase to 'Lost', which is a terminal
|
||||||
// phase.
|
// 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 {
|
_, err = ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimMisbound", "Two claims are bound to the same volume, this one is bound incorrectly")
|
||||||
return err
|
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
Block a user