mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
fix:cached claim is not the newest will cause unexpected issue
This commit is contained in:
@@ -622,9 +622,22 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *v1.PersistentVolume)
|
||||
if claim != nil && claim.UID != volume.Spec.ClaimRef.UID {
|
||||
// The claim that the PV was pointing to was deleted, and another
|
||||
// with the same name created.
|
||||
klog.V(4).Infof("synchronizing PersistentVolume[%s]: claim %s has different UID, the old one must have been deleted", volume.Name, claimrefToClaimKey(volume.Spec.ClaimRef))
|
||||
// Treat the volume as bound to a missing claim.
|
||||
claim = nil
|
||||
// in some cases, the cached claim is not the newest, and the volume.Spec.ClaimRef.UID is newer than cached.
|
||||
// so we should double check by calling apiserver and get the newest claim, then compare them.
|
||||
klog.V(4).Infof("Maybe cached claim: %s is not the newest one, we should fetch it from apiserver", claimrefToClaimKey(volume.Spec.ClaimRef))
|
||||
|
||||
claim, err = ctrl.kubeClient.CoreV1().PersistentVolumeClaims(volume.Spec.ClaimRef.Namespace).Get(context.TODO(), volume.Spec.ClaimRef.Name, metav1.GetOptions{})
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
return err
|
||||
} else if claim != nil {
|
||||
// Treat the volume as bound to a missing claim.
|
||||
if claim.UID != volume.Spec.ClaimRef.UID {
|
||||
klog.V(4).Infof("synchronizing PersistentVolume[%s]: claim %s has a newer UID than pv.ClaimRef, the old one must have been deleted", volume.Name, claimrefToClaimKey(volume.Spec.ClaimRef))
|
||||
claim = nil
|
||||
} else {
|
||||
klog.V(4).Infof("synchronizing PersistentVolume[%s]: claim %s has a same UID with pv.ClaimRef", volume.Name, claimrefToClaimKey(volume.Spec.ClaimRef))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if claim == nil {
|
||||
|
||||
Reference in New Issue
Block a user