Skip to content

Fix nil pointer panic when schedule has no ScheduleCommon#1155

Open
arska wants to merge 3 commits intomasterfrom
fix/nil-schedule-crash-1041
Open

Fix nil pointer panic when schedule has no ScheduleCommon#1155
arska wants to merge 3 commits intomasterfrom
fix/nil-schedule-crash-1041

Conversation

@arska
Copy link
Copy Markdown
Member

@arska arska commented Mar 22, 2026

Summary

  • Fix crash when a Schedule resource specifies a job type (e.g. backup:) with fields but omits the schedule: field
  • The embedded *ScheduleCommon pointer is nil in this case, causing GetSchedule() to panic
  • Add nil checks to GetSchedule() for all five schedule types

Fixes #1041

Test plan

  • Added unit tests that reproduce the panic with nil ScheduleCommon
  • Verified tests fail before fix (panic) and pass after
  • All existing api/v1 tests still pass

🤖 Generated with Claude Code

@arska arska requested a review from a team as a code owner March 22, 2026 14:22
@arska arska added bug Something isn't working area:operator labels Mar 22, 2026
@arska arska requested review from bastjan and zugao and removed request for a team March 22, 2026 14:22
@arska arska self-assigned this Mar 22, 2026
@tobru tobru requested a review from Kidswiss March 23, 2026 09:44
@tobru
Copy link
Copy Markdown
Contributor

tobru commented Mar 23, 2026

@Kidswiss mind giving this a review? I think it's OK, but I need another eye.

@arska arska force-pushed the fix/nil-schedule-crash-1041 branch from 1f5c83c to 297b9b2 Compare March 23, 2026 11:58
@arska arska removed request for bastjan and zugao March 23, 2026 12:47
Comment thread api/v1/archive_types.go Outdated
@arska
Copy link
Copy Markdown
Member Author

arska commented Mar 23, 2026

Applied the suggestion across all 5 schedule types — using in.ScheduleCommon.Schedule makes the intent much clearer. Thanks @bastjan!

@arska
Copy link
Copy Markdown
Member Author

arska commented Mar 23, 2026

@bastjan, golangci-lint disagrees. Should we go back or change linter settings?

@bastjan
Copy link
Copy Markdown
Member

bastjan commented Mar 23, 2026

I tend to prefer code clarity over "nice to have" lints.

@arska arska added the discussion-needed PR needs design or technical discussion before proceeding label Mar 23, 2026
@arska arska force-pushed the fix/nil-schedule-crash-1041 branch from 63ff5f9 to 2de4eca Compare March 23, 2026 13:41
arska and others added 2 commits March 23, 2026 14:57
When a Schedule resource specifies a job type (e.g. backup:) with
fields but omits the schedule: field, the embedded *ScheduleCommon
pointer is nil. Calling GetSchedule() on it caused a nil pointer
dereference crash.

Add nil checks to GetSchedule() for all five schedule types:
BackupSchedule, RestoreSchedule, ArchiveSchedule, CheckSchedule,
and PruneSchedule.

Fixes #1041

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Aarno Aukia <aarno.aukia@vshn.ch>
Use in.ScheduleCommon.Schedule instead of in.Schedule to make
it clear the field comes from the embedded pointer, and why
the nil check is needed.

Suggested-by: @bastjan

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Aarno Aukia <aarno.aukia@vshn.ch>
@arska arska force-pushed the fix/nil-schedule-crash-1041 branch from 2de4eca to 389f11f Compare March 23, 2026 13:57
Disable staticcheck QF1008 ("could remove embedded field from
selector") to allow using in.ScheduleCommon.Schedule instead of
in.Schedule. The explicit form makes it clear why the nil check
is needed — the Schedule field comes from an embedded pointer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Aarno Aukia <aarno.aukia@vshn.ch>
@arska
Copy link
Copy Markdown
Member Author

arska commented Mar 23, 2026

Added a lint exclusion for QF1008 in .golangci.yml — code clarity wins over the lint suggestion here. Lint should pass now.

Copy link
Copy Markdown
Contributor

@Kidswiss Kidswiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to mark the SchedulerCommon.Schedule as required in addition. IMHO doesn't make much sense to specify a schedule and then NOT adding the actual schedule.

Since the parent fields are optional, this will result in a conditional require.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:operator bug Something isn't working discussion-needed PR needs design or technical discussion before proceeding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Operator crashes if a schedule has no backup schedule defined

4 participants