Skip to content

Commit

Permalink
Merge pull request #6012 from sseago/itemoperation-new-phase
Browse files Browse the repository at this point in the history
BIA/RIAv2 -- distinguish between New and InProgress operations
  • Loading branch information
reasonerjt authored Mar 22, 2023
2 parents 29b5894 + 433d2d5 commit 58ad428
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/6012-sseago
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distinguish between New and InProgress operations
4 changes: 2 additions & 2 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ func TestBackupWithAsyncOperations(t *testing.T) {
OperationID: "pod-1-1",
},
Status: itemoperation.OperationStatus{
Phase: "InProgress",
Phase: "New",
},
},
},
Expand Down Expand Up @@ -2507,7 +2507,7 @@ func TestBackupWithAsyncOperations(t *testing.T) {
OperationID: "pod-2-1",
},
Status: itemoperation.OperationStatus{
Phase: "InProgress",
Phase: "New",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (ib *itemBackupper) executeActions(
OperationID: operationID,
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &now,
},
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/controller/backup_operations_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ func getBackupItemOperationProgress(
var completedCount, failedCount int

for _, operation := range operationsList {
if operation.Status.Phase == itemoperation.OperationPhaseInProgress {
if operation.Status.Phase == itemoperation.OperationPhaseNew ||
operation.Status.Phase == itemoperation.OperationPhaseInProgress {
bia, err := pluginManager.GetBackupItemActionV2(operation.Spec.BackupItemAction)
if err != nil {
operation.Status.Phase = itemoperation.OperationPhaseFailed
Expand Down Expand Up @@ -322,12 +323,14 @@ func getBackupItemOperationProgress(
changes = true
}
started := metav1.NewTime(operationProgress.Started)
if operation.Status.Started == nil || *(operation.Status.Started) != started {
if operation.Status.Started == nil && !operationProgress.Started.IsZero() ||
operation.Status.Started != nil && *(operation.Status.Started) != started {
operation.Status.Started = &started
changes = true
}
updated := metav1.NewTime(operationProgress.Updated)
if operation.Status.Updated == nil || *(operation.Status.Updated) != updated {
if operation.Status.Updated == nil && !operationProgress.Updated.IsZero() ||
operation.Status.Updated != nil && *(operation.Status.Updated) != updated {
operation.Status.Updated = &updated
changes = true
}
Expand Down Expand Up @@ -356,6 +359,11 @@ func getBackupItemOperationProgress(
failedCount++
continue
}
if operation.Status.Phase == itemoperation.OperationPhaseNew &&
operation.Status.Started != nil {
operation.Status.Phase = itemoperation.OperationPhaseInProgress
changes = true
}
// if we reach this point, the operation is still running
inProgressOperations = true
} else if operation.Status.Phase == itemoperation.OperationPhaseCompleted {
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/backup_operations_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestBackupOperationsReconcile(t *testing.T) {
OperationID: "operation-11",
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &metav1Now,
},
},
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestBackupOperationsReconcile(t *testing.T) {
OperationID: "operation-12",
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &metav1Now,
},
},
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestBackupOperationsReconcile(t *testing.T) {
OperationID: "operation-13",
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &metav1Now,
},
},
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestBackupOperationsReconcile(t *testing.T) {
OperationID: "operation-14",
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &metav1Now,
},
},
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestBackupOperationsReconcile(t *testing.T) {
OperationID: "operation-15",
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &metav1Now,
},
},
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestBackupOperationsReconcile(t *testing.T) {
OperationID: "operation-16",
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &metav1Now,
},
},
Expand Down
14 changes: 11 additions & 3 deletions pkg/controller/restore_operations_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ func getRestoreItemOperationProgress(
var completedCount, failedCount int

for _, operation := range operationsList {
if operation.Status.Phase == itemoperation.OperationPhaseInProgress {
if operation.Status.Phase == itemoperation.OperationPhaseNew ||
operation.Status.Phase == itemoperation.OperationPhaseInProgress {
ria, err := pluginManager.GetRestoreItemActionV2(operation.Spec.RestoreItemAction)
if err != nil {
operation.Status.Phase = itemoperation.OperationPhaseFailed
Expand Down Expand Up @@ -306,12 +307,14 @@ func getRestoreItemOperationProgress(
changes = true
}
started := metav1.NewTime(operationProgress.Started)
if operation.Status.Started == nil || *(operation.Status.Started) != started {
if operation.Status.Started == nil && !operationProgress.Started.IsZero() ||
operation.Status.Started != nil && *(operation.Status.Started) != started {
operation.Status.Started = &started
changes = true
}
updated := metav1.NewTime(operationProgress.Updated)
if operation.Status.Updated == nil || *(operation.Status.Updated) != updated {
if operation.Status.Updated == nil && !operationProgress.Updated.IsZero() ||
operation.Status.Updated != nil && *(operation.Status.Updated) != updated {
operation.Status.Updated = &updated
changes = true
}
Expand Down Expand Up @@ -340,6 +343,11 @@ func getRestoreItemOperationProgress(
failedCount++
continue
}
if operation.Status.Phase == itemoperation.OperationPhaseNew &&
operation.Status.Started != nil {
operation.Status.Phase = itemoperation.OperationPhaseInProgress
changes = true
}
// if we reach this point, the operation is still running
inProgressOperations = true
} else if operation.Status.Phase == itemoperation.OperationPhaseCompleted {
Expand Down
6 changes: 5 additions & 1 deletion pkg/itemoperation/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func (in *OperationStatus) DeepCopyInto(out *OperationStatus) {
}

const (
// OperationPhaseNew means the item operation has been created and started
// OperationPhaseNew means the item operation has been created but not started
// by the plugin
OperationPhaseNew OperationPhase = "New"

// OperationPhaseInProgress means the item operation has been created and started
// by the plugin
OperationPhaseInProgress OperationPhase = "InProgress"

Expand Down
2 changes: 1 addition & 1 deletion pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
OperationID: executeOutput.OperationID,
},
Status: itemoperation.OperationStatus{
Phase: itemoperation.OperationPhaseInProgress,
Phase: itemoperation.OperationPhaseNew,
Created: &now,
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ func TestRestoreWithAsyncOperations(t *testing.T) {
OperationID: "pod-1-1",
},
Status: itemoperation.OperationStatus{
Phase: "InProgress",
Phase: "New",
},
},
},
Expand All @@ -1732,7 +1732,7 @@ func TestRestoreWithAsyncOperations(t *testing.T) {
OperationID: "pod-2-1",
},
Status: itemoperation.OperationStatus{
Phase: "InProgress",
Phase: "New",
},
},
},
Expand Down

0 comments on commit 58ad428

Please sign in to comment.