Fix handling of APIserver errors when saving provisioned PVs.
When API server crashes *after* saving a provisioned PV and before sending 200 OK, the controller tries to save the PV again. In this case, it gets AlreadyExists error, which should be interpreted as success and not as error. Especially, a volume that corresponds to the PV should not be deleted in the underlying storage.
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
@@ -1364,14 +1365,19 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interfa
|
||||
for i := 0; i < ctrl.createProvisionedPVRetryCount; i++ {
|
||||
glog.V(4).Infof("provisionClaimOperation [%s]: trying to save volume %s", claimToClaimKey(claim), volume.Name)
|
||||
var newVol *v1.PersistentVolume
|
||||
if newVol, err = ctrl.kubeClient.Core().PersistentVolumes().Create(volume); err == nil {
|
||||
if newVol, err = ctrl.kubeClient.Core().PersistentVolumes().Create(volume); err == nil || apierrs.IsAlreadyExists(err) {
|
||||
// Save succeeded.
|
||||
glog.V(3).Infof("volume %q for claim %q saved", volume.Name, claimToClaimKey(claim))
|
||||
if err != nil {
|
||||
glog.V(3).Infof("volume %q for claim %q already exists, reusing", volume.Name, claimToClaimKey(claim))
|
||||
err = nil
|
||||
} else {
|
||||
glog.V(3).Infof("volume %q for claim %q saved", volume.Name, claimToClaimKey(claim))
|
||||
|
||||
_, updateErr := ctrl.storeVolumeUpdate(newVol)
|
||||
if updateErr != nil {
|
||||
// We will get an "volume added" event soon, this is not a big error
|
||||
glog.V(4).Infof("provisionClaimOperation [%s]: cannot update internal cache: %v", volume.Name, updateErr)
|
||||
_, updateErr := ctrl.storeVolumeUpdate(newVol)
|
||||
if updateErr != nil {
|
||||
// We will get an "volume added" event soon, this is not a big error
|
||||
glog.V(4).Infof("provisionClaimOperation [%s]: cannot update internal cache: %v", volume.Name, updateErr)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
Reference in New Issue
Block a user