[Portworx] add idempotency for local snapshots
@@ -844,8 +844,24 @@ func (p *portworx) SnapshotCreate(
}
snapshotID, err = volDriver.Snapshot(volumeID, true, locator, true)
if err != nil {
+ // Check already exists error and return existing snapshot if found
+ if isAlreadyExistsError(err) {
+ snapInfo, err := p.inspectVolume(volDriver, snapName)
+ if err != nil {
+ return nil, getErrorSnapshotConditions(err), err
+ }
+
+ if snapInfo.ParentID != volumeID {
+ err := fmt.Errorf("found existing snapshot with name: %s but parent volume ID doesn't match."+
+ "expected: %s found: %s", snapName, volumeID, snapInfo.ParentID)
+ return nil, getErrorSnapshotConditions(err), err
+ }
+
+ snapshotID = snapInfo.VolumeID
+ } else {
return nil, getErrorSnapshotConditions(err), err
}
+ }
snapStatusConditions = getReadySnapshotConditions()
}
@@ -2040,6 +2056,14 @@ func isCloudsnapStatusFailed(st api.CloudBackupStatusType) bool {
st == api.CloudBackupStatusAborted
}
+func isAlreadyExistsError(err error) bool {
+ if err == nil {
+ return false
+ }
+
+ return strings.HasSuffix(err.Error(), "already exists")
+}
+
func init() {
if err := storkvolume.Register(driverName, &portworx{}); err != nil {
logrus.Panicf("Error registering portworx volume driver: %v", err)
