Skip to content

Commit

Permalink
feat(controller): allow any snapshot as volume data source for encryp…
Browse files Browse the repository at this point in the history
…ted volume
  • Loading branch information
peknur committed Sep 26, 2024
1 parent 1782937 commit 7507d97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added
- controller: allow any snapshot as volume data source for encrypted volume

## [1.2.0]

### Added
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *Controller) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequ
return nil, status.Error(codes.Internal, err.Error())
}
if len(volumes) > 0 {
return createVolumeExistsResponse(ctx, req, volumes, log)
return createVolumeExistsResponse(req, volumes, log)
}

tier, err := createVolumeRequestTier(req)
Expand Down Expand Up @@ -115,7 +115,7 @@ func (c *Controller) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequ
}, nil
}

func createVolumeExistsResponse(ctx context.Context, req *csi.CreateVolumeRequest, volumes []*upcloud.StorageDetails, log *logrus.Entry) (resp *csi.CreateVolumeResponse, err error) {
func createVolumeExistsResponse(req *csi.CreateVolumeRequest, volumes []*upcloud.StorageDetails, log *logrus.Entry) (resp *csi.CreateVolumeResponse, err error) {
if len(volumes) > 1 {
return nil, fmt.Errorf("fatal: duplicate volume %q exists", req.GetName())
}
Expand Down Expand Up @@ -168,8 +168,8 @@ func (c *Controller) createVolumeFromSource(ctx context.Context, req *csi.Create
}
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
if src.Encrypted.Bool() != createVolumeRequestEncryptionAtRest(req) {
// To prevent unexpected dst device properties, only allow cloning from device with same encryption policy.
if src.Type != upcloud.StorageTypeBackup && (src.Encrypted.Bool() != createVolumeRequestEncryptionAtRest(req)) {
// To prevent unexpected dst device properties, only allow cloning from backups or device with same encryption policy.
return nil, status.Errorf(codes.InvalidArgument, "source and destination volumes needs to have same encryption policy")
}
log.Info("checking that source storage is online")
Expand All @@ -181,7 +181,7 @@ func (c *Controller) createVolumeFromSource(ctx context.Context, req *csi.Create
Zone: c.zone,
Tier: tier,
Title: req.GetName(),
Encrypted: src.Encrypted,
Encrypted: upcloud.FromBool(createVolumeRequestEncryptionAtRest(req)),
}
logger.WithServiceRequest(log, volumeReq).Info("cloning volume")
vol, err := c.svc.CloneStorage(ctx, volumeReq, c.storageLabels...)
Expand Down

0 comments on commit 7507d97

Please sign in to comment.