Skip to content

Commit

Permalink
fix(pkg/repository/maintenance): don't panic when there's no containe…
Browse files Browse the repository at this point in the history
…r statuses

Signed-off-by: Mikaël Cluseau <[email protected]>
  • Loading branch information
mcluseau committed Oct 8, 2024
1 parent 42de654 commit 1e3e027
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelogs/unreleased/8271-mcluseau
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix(pkg/repository/maintenance): don't panic when there's no container statuses
15 changes: 14 additions & 1 deletion pkg/repository/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,20 @@ func GetMaintenanceResultFromJob(cli client.Client, job *batchv1.Job) (string, e
}

// we only have one maintenance pod for the job
return podList.Items[0].Status.ContainerStatuses[0].State.Terminated.Message, nil
pod := podList.Items[0]

statuses := pod.Status.ContainerStatuses
if len(statuses) == 0 {
return "", fmt.Errorf("no container statuses found for job %s", job.Name)

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

View check run for this annotation

Codecov / codecov/patch

pkg/repository/maintenance.go#L124

Added line #L124 was not covered by tests
}

// we only have one maintenance container
terminated := statuses[0].State.Terminated
if terminated == nil {
return "", fmt.Errorf("container for job %s is not terminated", job.Name)

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

View check run for this annotation

Codecov / codecov/patch

pkg/repository/maintenance.go#L130

Added line #L130 was not covered by tests
}

return terminated.Message, nil
}

func GetLatestMaintenanceJob(cli client.Client, ns string) (*batchv1.Job, error) {
Expand Down

0 comments on commit 1e3e027

Please sign in to comment.