Skip to content

Commit

Permalink
Update VolumeSnapshot status for failed snapshots (#4)
Browse files Browse the repository at this point in the history
* Update VolumeSnapshot status for failed snapshots

Signed-off-by: Harsh Desai <harsh@portworx.com>

* rename bind snapshot method

Signed-off-by: Harsh Desai <harsh@portworx.com>
  • Loading branch information
Harsh Desai authored and disrani-px committed Oct 11, 2018
1 parent 9000cd3 commit bc02da2
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions snapshot/pkg/controller/snapshotter/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ func (vs *volumeSnapshotter) takeSnapshot(
glog.Warningf("failed to snapshot %#v, err: %v", spec, err)
} else {
glog.Infof("snapshot created: %v. Conditions: %#v", snapDataSource, snapConditions)
return snapDataSource, snapConditions, nil
}
return nil, nil, nil

return snapDataSource, snapConditions, err
}

// This is the function responsible for determining the correct volume plugin to use,
Expand Down Expand Up @@ -379,7 +379,7 @@ func (vs *volumeSnapshotter) updateSnapshotIfExists(uniqueSnapshotName string, s
// triggered through cloud provider, bind it and return pending state
if snapshotDataObj = vs.getSnapshotDataFromSnapshotName(uniqueSnapshotName); snapshotDataObj != nil {
glog.Infof("Find snapshot data object %s from snapshot %s", snapshotDataObj.Metadata.Name, uniqueSnapshotName)
snapshotObj, err := vs.bindandUpdateVolumeSnapshot(snapshot, snapshotDataObj.Metadata.Name, nil)
snapshotObj, err := vs.updateVolumeSnapshot(snapshot, snapshotDataObj.Metadata.Name, nil)
if err != nil {
return statusError, snapshot, err
}
Expand All @@ -401,7 +401,7 @@ func (vs *volumeSnapshotter) updateSnapshotIfExists(uniqueSnapshotName string, s
return statusError, snapshot, err
}
glog.Infof("updateSnapshotIfExists: update VolumeSnapshot status and bind VolumeSnapshotData to VolumeSnapshot %s.", uniqueSnapshotName)
snapshotObj, err := vs.bindandUpdateVolumeSnapshot(snapshot, snapshotDataObj.Metadata.Name, conditions)
snapshotObj, err := vs.updateVolumeSnapshot(snapshot, snapshotDataObj.Metadata.Name, conditions)
if err != nil {
return statusError, nil, err
}
Expand Down Expand Up @@ -502,7 +502,18 @@ func (vs *volumeSnapshotter) createSnapshot(uniqueSnapshotName string, snapshot

snapshotDataSource, snapStatus, err = vs.takeSnapshot(snapshot, pv, tags)
if err != nil || snapshotDataSource == nil {
return fmt.Errorf("Failed to take snapshot of the volume %s: %q", pv.Name, err)
if snapStatus != nil && len(*snapStatus) > 0 {
_, updateErr := vs.updateVolumeSnapshot(snapshot, "", snapStatus)
if updateErr != nil {
glog.Errorf("createSnapshot: Error updating failed volume snapshot %s: %v", uniqueSnapshotName, updateErr)
}
}

if err != nil {
return fmt.Errorf("Failed to take snapshot of the volume %s: %q", pv.Name, err)
} else {
return fmt.Errorf("Failed to take snapshot of the volume %s", pv.Name)
}
}

glog.Infof("createSnapshot: create VolumeSnapshotData object for VolumeSnapshot %s.", uniqueSnapshotName)
Expand All @@ -512,7 +523,7 @@ func (vs *volumeSnapshotter) createSnapshot(uniqueSnapshotName string, snapshot
}

glog.Infof("createSnapshot: Update VolumeSnapshot status and bind VolumeSnapshotData to VolumeSnapshot %s.", uniqueSnapshotName)
snapshotObj, err := vs.bindandUpdateVolumeSnapshot(snapshot, snapshotDataObj.Metadata.Name, snapStatus)
snapshotObj, err := vs.updateVolumeSnapshot(snapshot, snapshotDataObj.Metadata.Name, snapStatus)
if err != nil {
glog.Errorf("createSnapshot: Error updating volume snapshot %s: %v", uniqueSnapshotName, err)
return fmt.Errorf("Failed to update VolumeSnapshot for snapshot %s", uniqueSnapshotName)
Expand Down Expand Up @@ -853,8 +864,8 @@ func (vs *volumeSnapshotter) UpdateVolumeSnapshotStatus(snapshot *crdv1.VolumeSn
return snapshot, nil
}

// Bind the VolumeSnapshot and VolumeSnapshotData and udpate the status
func (vs *volumeSnapshotter) bindandUpdateVolumeSnapshot(snapshot *crdv1.VolumeSnapshot, snapshotDataName string, status *[]crdv1.VolumeSnapshotCondition) (*crdv1.VolumeSnapshot, error) {
// Bind the VolumeSnapshot and VolumeSnapshotData if snapshotDataName is given and updates the status
func (vs *volumeSnapshotter) updateVolumeSnapshot(snapshot *crdv1.VolumeSnapshot, snapshotDataName string, status *[]crdv1.VolumeSnapshotCondition) (*crdv1.VolumeSnapshot, error) {
var snapshotObj crdv1.VolumeSnapshot

glog.Infof("In bindVolumeSnapshotDataToVolumeSnapshot")
Expand Down

0 comments on commit bc02da2

Please sign in to comment.