Skip to content

CronJob details and list crash when spec.suspend is not set (undefined) #5083

@RobertSkawinski

Description

@RobertSkawinski

Describe the bug

Headlamp crashes with "Uh-oh! Something went wrong" when viewing CronJob details or the CronJob list if a CronJob does not have spec.suspend explicitly set in its manifest. Kubernetes defaults spec.suspend to false but does not always include it in the API response, causing undefined.toString() to throw a TypeError.

To Reproduce

  1. Have a CronJob in the cluster that does not explicitly set spec.suspend (e.g. installed by a Helm chart that omits the field)
  2. Navigate to Workloads → CronJobs
  3. Click on the CronJob to open its details
  4. UI crashes with "Uh-oh! Something went wrong"

Error from browser console

TypeError: can't access property "suspend", c.spec is undefined
HBe https://headlamp.poc1.swuppi.dev/assets/index-CE3nuifS.js:1167

Root cause

Three locations access spec.suspend without a null/undefined check:

frontend/src/components/cronjob/List.tsx:69

getValue: cronJob => cronJob.spec.suspend.toString(),
frontend/src/components/cronjob/Details.tsx:152


const isCronSuspended = cronJob?.spec.suspend;
frontend/src/components/cronjob/Details.tsx:241


value: item.spec.suspend.toString(),

When the Kubernetes API omits spec.suspend (which is valid — it defaults to false), these calls throw a TypeError because .toString() is called on undefined.

Suggested fix

Use nullish coalescing to default to false when the field is missing:

List.tsx:69


- getValue: cronJob => cronJob.spec.suspend.toString(),
+ getValue: cronJob => (cronJob.spec.suspend ?? false).toString(),
Details.tsx:152


- const isCronSuspended = cronJob?.spec.suspend;
+ const isCronSuspended = cronJob?.spec?.suspend ?? false;
Details.tsx:241


- value: item.spec.suspend.toString(),
+ value: (item.spec.suspend ?? false).toString(),

Environment

Installation type: In-cluster
Headlamp version: v0.41.0
Kubernetes version: 1.31
The bug also exists on main (checked 2026-04-07)

!! This code analysis has been done by AI: Claude - A developer is needed to verify if this change does not break something.

Metadata

Metadata

Assignees

Labels

CronJobfrontendIssues related to the frontendkind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions