Skip to content

fix(chk): prevent nil pointer panic in poll when CR Get fails#1974

Merged
sunsingerus merged 1 commit intoAltinity:0.27.0from
wucm667:fix/chk-poll-nil-crash
May 4, 2026
Merged

fix(chk): prevent nil pointer panic in poll when CR Get fails#1974
sunsingerus merged 1 commit intoAltinity:0.27.0from
wucm667:fix/chk-poll-nil-crash

Conversation

@wucm667
Copy link
Copy Markdown

@wucm667 wucm667 commented Apr 29, 2026

Fixes #1972

What this PR fixes

The poll function in the ClickHouseKeeperInstallation controller panics when c.kube.CR().Get() returns an error because cur is nil, and the code performs an unchecked type assertion:

cur, err := c.kube.CR().Get(ctx, namespace, name)
if f(cur.(*apiChk.ClickHouseKeeperInstallation), err) {  // ← panics when cur is nil

This causes the operator to crashloop with:

panic: interface conversion: v1.ICustomResource is nil, not *v1.ClickHouseKeeperInstallation

Changes

  • Added a type assertion with ok-check in pkg/controller/chk/controller.go poll() function
  • If the CR cannot be fetched:
    • NotFound: return immediately (CR was deleted, no point polling)
    • Other error: log and continue polling with 15s backoff
  • Only call the callback f() when chk is valid

This follows the same safe pattern already used in statusUpdateProcess() in pkg/controller/chk/kube/cr.go.

The poll function in the ClickHouseKeeperInstallation controller panics
when c.kube.CR().Get() returns an error because cur is nil, and the
code performs an unchecked type assertion cur.(*ClickHouseKeeperInstallation).
This causes the operator to crashloop with:
  'panic: interface conversion: v1.ICustomResource is nil,
   not *v1.ClickHouseKeeperInstallation'

Fix by checking the type assertion result and nil before using cur.
- If NotFound: return immediately (CR was deleted, no point polling)
- If other error: log and continue polling with 15s backoff
- Only call the callback f() when chk is valid

This follows the same safe pattern used in statusUpdateProcess() in
pkg/controller/chk/kube/cr.go.

Fixes Altinity#1972

Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
@alex-zaitsev alex-zaitsev changed the base branch from 0.26.3 to 0.27.0 April 29, 2026 17:28
Copy link
Copy Markdown
Collaborator

@sunsingerus sunsingerus left a comment

Choose a reason for hiding this comment

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

LGTM. Follows the existing safe-cast pattern from pkg/controller/chk/kube/cr.go (statusUpdateProcess at lines 98-122): type-assert with ok, treat apiErrors.IsNotFound as terminal, log+retry transient errors, honor context cancellation. Closes the panic in #1972.

@sunsingerus sunsingerus merged commit 828cfcc into Altinity:0.27.0 May 4, 2026
2 checks passed
@wucm667 wucm667 deleted the fix/chk-poll-nil-crash branch May 4, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants