diff --git a/changelogs/unreleased/8271-mcluseau b/changelogs/unreleased/8271-mcluseau new file mode 100644 index 00000000000..189d797bc89 --- /dev/null +++ b/changelogs/unreleased/8271-mcluseau @@ -0,0 +1 @@ +fix(pkg/repository/maintenance): don't panic when there's no container statuses diff --git a/pkg/repository/maintenance.go b/pkg/repository/maintenance.go index 1a137cba90e..7105c8315d5 100644 --- a/pkg/repository/maintenance.go +++ b/pkg/repository/maintenance.go @@ -117,7 +117,15 @@ 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) + } + + // we only have one maintenance container + return statuses[0].State.Terminated.Message, nil } func GetLatestMaintenanceJob(cli client.Client, ns string) (*batchv1.Job, error) {