Skip to content

Commit

Permalink
get maintenance result only for failed jobs
Browse files Browse the repository at this point in the history
Signed-off-by: Lyndon-Li <[email protected]>
  • Loading branch information
Lyndon-Li committed Jan 15, 2025
1 parent 3900f2f commit 6f33dc6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
24 changes: 17 additions & 7 deletions pkg/repository/maintenance/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,16 @@ func WaitJobComplete(cli client.Client, ctx context.Context, jobName, ns string,
return velerov1api.BackupRepositoryMaintenanceStatus{}, errors.Wrap(err, "error to wait for maintenance job complete")
}

Check warning on line 251 in pkg/repository/maintenance/maintenance.go

View check run for this annotation

Codecov / codecov/patch

pkg/repository/maintenance/maintenance.go#L245-L251

Added lines #L245 - L251 were not covered by tests

log.Info("Maintenance repo complete")
log.Infof("Maintenance repo complete, succeeded %v, failed %v", maintenanceJob.Status.Succeeded, maintenanceJob.Status.Failed)

result, err := getResultFromJob(cli, maintenanceJob)
if err != nil {
log.WithError(err).Warn("Failed to get maintenance job result")
result := ""
if maintenanceJob.Status.Failed > 0 {
if r, err := getResultFromJob(cli, maintenanceJob); err != nil {
log.WithError(err).Warn("Failed to get maintenance job result")
result = "Repo maintenance failed but result is not retrieveable"
} else {
result = r
}

Check warning on line 262 in pkg/repository/maintenance/maintenance.go

View check run for this annotation

Codecov / codecov/patch

pkg/repository/maintenance/maintenance.go#L253-L262

Added lines #L253 - L262 were not covered by tests
}

return composeStatusFromJob(maintenanceJob, result), nil

Check warning on line 265 in pkg/repository/maintenance/maintenance.go

View check run for this annotation

Codecov / codecov/patch

pkg/repository/maintenance/maintenance.go#L265

Added line #L265 was not covered by tests
Expand Down Expand Up @@ -303,9 +308,14 @@ func WaitAllJobsComplete(ctx context.Context, cli client.Client, repo *velerov1a
job = updated

Check warning on line 308 in pkg/repository/maintenance/maintenance.go

View check run for this annotation

Codecov / codecov/patch

pkg/repository/maintenance/maintenance.go#L308

Added line #L308 was not covered by tests
}

message, err := getResultFromJob(cli, job)
if err != nil {
return nil, errors.Wrapf(err, "error getting maintenance job[%s] result", job.Name)
message := ""
if job.Status.Failed > 0 {
if msg, err := getResultFromJob(cli, job); err != nil {
log.WithError(err).Warnf("Failed to get result of maintenance job %s", job.Name)
message = "Repo maintenance failed but result is not retrieveable"
} else {
message = msg
}
}

history = append(history, composeStatusFromJob(job, message))
Expand Down
26 changes: 24 additions & 2 deletions pkg/repository/maintenance/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,35 @@ func TestWaitAllJobsComplete(t *testing.T) {
expectedError: "error waiting maintenance job[job1] complete: context deadline exceeded",
},
{
name: "get result error",
name: "get result error on succeded job",

Check failure on line 605 in pkg/repository/maintenance/maintenance_test.go

View workflow job for this annotation

GitHub Actions / Run Codespell

succeded ==> succeeded

Check failure on line 605 in pkg/repository/maintenance/maintenance_test.go

View workflow job for this annotation

GitHub Actions / Run Linter Check

`succeded` is a misspelling of `succeeded` (misspell)
ctx: context.TODO(),
runtimeScheme: scheme,
kubeClientObj: []runtime.Object{
jobSucceeded1,
},
expectedError: "error getting maintenance job[job1] result: no pod found for job job1",
expectedStatus: []velerov1api.BackupRepositoryMaintenanceStatus{
{
Result: velerov1api.BackupRepositoryMaintenanceSucceeded,
StartTimestamp: &metav1.Time{Time: now},
CompleteTimestamp: &metav1.Time{Time: now.Add(time.Hour)},
},
},
},
{
name: "get result error on failed job",
ctx: context.TODO(),
runtimeScheme: scheme,
kubeClientObj: []runtime.Object{
jobFailed1,
},
expectedStatus: []velerov1api.BackupRepositoryMaintenanceStatus{
{
Result: velerov1api.BackupRepositoryMaintenanceFailed,
StartTimestamp: &metav1.Time{Time: now.Add(time.Hour)},
CompleteTimestamp: &metav1.Time{Time: now.Add(time.Hour * 2)},
Message: "Repo maintenance failed but result is not retrieveable",
},
},
},
{
name: "less than limit",
Expand Down

0 comments on commit 6f33dc6

Please sign in to comment.