Skip to content

Commit

Permalink
Implement method SnapshotCreateWaitForCompletion for AdStorage ty…
Browse files Browse the repository at this point in the history
…pe (#2494)

* Implement method `SnapshotCreateWaitForCompletion`

The method `SnapshotCreateWaitForCompletion` for `AdStorage` was just returning
`nil`. Which caused some problems because we were not able to wait for snapshot
to complete, successfully.
This commit fixes that by implementing the mentioned method.

* Correct logic that waits for snapshot to be succeeded

We checked if the snapshot was succeeded by making sure that these two
conditions were false

- err!=nil
- provisioningState!=succeeded

second condition can be false even if the provisioning state is pending,
let's say. and because of that we would return success even in the case
of err being not nil and provisioningStaet being pending. Which would
be a problem.
This fixes that.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
viveksinghggits and mergify[bot] committed Nov 28, 2023
1 parent 5c2bbf4 commit 0fe1346
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
27 changes: 18 additions & 9 deletions pkg/blockstorage/azure/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,15 @@ func (s *AdStorage) SnapshotCreate(ctx context.Context, volume blockstorage.Volu
}

func (s *AdStorage) SnapshotCreateWaitForCompletion(ctx context.Context, snap *blockstorage.Snapshot) error {
return nil
err := poll.Wait(ctx, func(ctx context.Context) (bool, error) {
snapshot, err := s.SnapshotGet(ctx, snap.ID)
if err == nil && snapshot.ProvisioningState == string(azcompute.ProvisioningStateSucceeded) {
return true, nil
}

return false, nil
})
return err
}

const (
Expand Down Expand Up @@ -440,14 +448,15 @@ func (s *AdStorage) snapshotParse(ctx context.Context, snap azcompute.Snapshot)
tags = azto.StringMap(snap.Tags)
}
return &blockstorage.Snapshot{
Encrypted: encrypted,
ID: azto.String(snap.ID),
Region: azto.String(snap.Location),
SizeInBytes: azto.Int64(snap.SnapshotProperties.DiskSizeBytes),
Tags: blockstorage.MapToKeyValue(tags),
Type: s.Type(),
Volume: vol,
CreationTime: blockstorage.TimeStamp(snapCreationTime.ToTime()),
Encrypted: encrypted,
ID: azto.String(snap.ID),
Region: azto.String(snap.Location),
SizeInBytes: azto.Int64(snap.SnapshotProperties.DiskSizeBytes),
Tags: blockstorage.MapToKeyValue(tags),
Type: s.Type(),
Volume: vol,
CreationTime: blockstorage.TimeStamp(snapCreationTime.ToTime()),
ProvisioningState: *snap.ProvisioningState,
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/blockstorage/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ type Snapshot struct {

// volume
Volume *Volume

// ProvisioningState is snapshot's provisioning state.
ProvisioningState string
}

// TimeStamp Time stamp for an event related to an object, for example when the object was created.
Expand Down

0 comments on commit 0fe1346

Please sign in to comment.