Skip to content

Commit

Permalink
Need to check VolumeContentSource if creating volume from snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
zhucan authored and zhuc committed Jul 23, 2019
1 parent b42fe10 commit 2905955
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,26 @@ func (p *csiProvisioner) ProvisionExt(options controller.ProvisionOptions) (*v1.
return nil, controller.ProvisioningInBackground, capErr
}

if needSnapshotSupport {
contentSource := rep.GetVolume().ContentSource
if contentSource == nil {
sourceErr := fmt.Errorf("created volume contentsource missing")
delReq := &csi.DeleteVolumeRequest{
VolumeId: rep.GetVolume().GetVolumeId(),
}
delReq.Secrets = provisionerCredentials
ctx, cancel := context.WithTimeout(context.Background(), p.timeout)
defer cancel()
_, err := p.csiClient.DeleteVolume(ctx, delReq)
if err != nil {
sourceErr = fmt.Errorf("%v. Cleanup of volume %s failed, volume is orphaned: %v", sourceErr, pvName, err)
}
return nil, sourceErr
}

klog.Infof("created volume %s from snapshot %s is successful", pvName, contentSource.GetSnapshot().SnapshotId)
}

pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: pvName,
Expand Down

0 comments on commit 2905955

Please sign in to comment.