rbd: configureEncryption() in genSnapFromSnapID()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos
2021-03-30 22:08:24 +02:00
committed by mergify[bot]
parent 6fd3f57f40
commit fd5f4dbafd
2 changed files with 28 additions and 8 deletions

View File

@ -723,7 +723,7 @@ func (rv *rbdVolume) checkImageChainHasFeature(ctx context.Context, feature uint
// genSnapFromSnapID generates a rbdSnapshot structure from the provided identifier, updating
// the structure with elements from on-disk snapshot metadata as well.
func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID string, cr *util.Credentials) error {
func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID string, cr *util.Credentials, secrets map[string]string) error {
var (
options map[string]string
vi util.CSIIdentifier
@ -774,6 +774,7 @@ func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID str
rbdSnap.RbdImageName = imageAttributes.SourceName
rbdSnap.RbdSnapName = imageAttributes.ImageName
rbdSnap.ReservedID = vi.ObjectUUID
rbdSnap.Owner = imageAttributes.Owner
// convert the journal pool ID to name, for use in DeleteSnapshot cases
if imageAttributes.JournalPoolID != util.InvalidPoolID {
rbdSnap.JournalPool, err = util.GetPoolName(rbdSnap.Monitors, cr, imageAttributes.JournalPoolID)
@ -783,6 +784,25 @@ func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID str
}
}
err = rbdSnap.Connect(cr)
defer func() {
if err != nil {
rbdSnap.Destroy()
}
}()
if err != nil {
return fmt.Errorf("failed to connect to %q: %w",
rbdSnap.String(), err)
}
if imageAttributes.KmsID != "" {
err = rbdSnap.configureEncryption(imageAttributes.KmsID, secrets)
if err != nil {
return fmt.Errorf("failed to configure encryption for "+
"%q: %w", rbdSnap.String(), err)
}
}
return err
}