Skip to content

Commit 7873bd3

Browse files
authored
Reintroduce snapshot state 'Populated' (#830)
The snapshot state 'Populated' was replaced with 'Ready' in commit `1f839f4`. However, logic to handle old snapshots still in state 'Populated' was left out. This commit adds the state 'Populated' back and adds logic to transfer snapshots in state 'Populated' to 'Ready'.
1 parent 9151ee1 commit 7873bd3

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

api/snapshot.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ type Snapshot struct {
1818
type SnapshotState string
1919

2020
const (
21-
SnapshotStatePending SnapshotState = "Pending"
22-
SnapshotStateReady SnapshotState = "Ready"
23-
SnapshotStateFailed SnapshotState = "Failed"
21+
SnapshotStatePending SnapshotState = "Pending"
22+
SnapshotStatePopulated SnapshotState = "Populated"
23+
SnapshotStateReady SnapshotState = "Ready"
24+
SnapshotStateFailed SnapshotState = "Failed"
2425
)
2526

2627
type SnapshotStatus struct {

internal/controllers/image_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ func (r *ImageReconciler) createImageFromSnapshot(ctx context.Context, log logr.
746746
return false, nil
747747
}
748748

749-
if snapshot.Status.State != providerapi.SnapshotStateReady {
749+
if snapshot.Status.State != providerapi.SnapshotStateReady && snapshot.Status.State != providerapi.SnapshotStatePopulated {
750750
log.V(1).Info("snapshot is not populated", "state", snapshot.Status.State)
751751
return false, nil
752752
}

internal/controllers/snapshot_controller.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,20 @@ func (r *SnapshotReconciler) reconcileSnapshot(ctx context.Context, id string) e
249249
return nil
250250
}
251251

252-
if snapshot.Status.State == providerapi.SnapshotStateReady {
252+
// SnapshotStatePopulated is no longer actively used. It has been replaced by SnapshotStateReady.
253+
// This block will transition any snapshots that are in SnapshotStatePopulated to SnapshotStateReady.
254+
if snapshot.Status.State == providerapi.SnapshotStatePopulated {
253255
log.V(1).Info("Snapshot already populated")
256+
snapshot.Status.State = providerapi.SnapshotStateReady
257+
if _, err = r.store.Update(ctx, snapshot); err != nil {
258+
return fmt.Errorf("failed to update snapshot: %w", err)
259+
}
260+
261+
return nil
262+
}
263+
264+
if snapshot.Status.State == providerapi.SnapshotStateReady {
265+
log.V(1).Info("Snapshot is ready")
254266
return nil
255267
}
256268

0 commit comments

Comments
 (0)