cleanup: move copyEncryptionConfig() from CreateVolume to Exists()

The rbdVolume that needs its encryption configured is constructed in the
Exists() method. It is suitable to move the copyEncryptionConfig() call
there as well, so that the object is completely constructed in a single
place.

Golang-ci:gocyclo complained about the increased complexity of the
Exists() function. Moving the repairing of the ImageID into its own
helper function makes the code a little easier to understand.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos
2021-04-08 15:04:32 +02:00
committed by mergify[bot]
parent 596410ae60
commit 52433841b4
2 changed files with 33 additions and 19 deletions

View File

@ -269,14 +269,6 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
}
if parentVol != nil && parentVol.isEncrypted() {
err = parentVol.copyEncryptionConfig(&rbdVol.rbdImage)
if err != nil {
util.ErrorLog(ctx, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
}
return buildCreateVolumeResponse(req, rbdVol), nil
}