rbd: store imageID if image is present

Added a check to make sure that the image
ID is stored if the image is already found.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-06-30 21:27:43 +05:30 committed by mergify[bot]
parent b085577a4f
commit f711d15551

View File

@ -280,6 +280,24 @@ func (rv *rbdVolume) Exists(ctx context.Context) (bool, error) {
return false, err return false, err
} }
rv.ImageID, err = j.GetStoredImageID(ctx, rv.JournalPool, rv.ReservedID, rv.conn.Creds)
if _, ok := err.(util.ErrKeyNotFound); ok {
err = rv.getImageID()
if err != nil {
klog.Errorf(util.Log(ctx, "failed to get image id %s: %v"), rv, err)
return false, err
}
err = j.StoreImageID(ctx, rv.JournalPool, rv.ReservedID, rv.ImageID, rv.conn.Creds)
if err != nil {
klog.Errorf(util.Log(ctx, "failed to store volume id %s: %v"), rv, err)
return false, err
}
}
if err != nil {
klog.Errorf(util.Log(ctx, "failed to get stored image id: %v"), err)
return false, err
}
// size checks // size checks
if rv.VolSize < requestSize { if rv.VolSize < requestSize {
err = fmt.Errorf("image with the same name (%s) but with different size already exists", err = fmt.Errorf("image with the same name (%s) but with different size already exists",