Skip to content

fix(api): nil pointer panic when Helm chart has no liveness probe#2513

Closed
A386official wants to merge 1 commit intogoodrain:mainfrom
A386official:fix/nil-pointer-liveness-probe-readiness-fallback
Closed

fix(api): nil pointer panic when Helm chart has no liveness probe#2513
A386official wants to merge 1 commit intogoodrain:mainfrom
A386official:fix/nil-pointer-liveness-probe-readiness-fallback

Conversation

@A386official
Copy link

Bug

When deploying a Helm chart application that has a readiness probe but no liveness probe configured, the API panics with a nil pointer dereference at resource_public_function.go:332, returning no useful error to the user. This was reported in #2512 with a full stack trace.

Root Cause

In PodTemplateSpecResource(), the readiness probe handling block (the else branch, entered when livenessProbe == nil) contains a copy-paste bug on line 332:

// Inside the else block — livenessProbe is nil here
readinessProbe := parameter.Template.Spec.Containers[0].ReadinessProbe
if readinessProbe != nil {
    if readinessProbe.HTTPGet != nil {
        // ...
        hcm.Port = int(readinessProbe.HTTPGet.Port.IntVal)
        if hcm.Port == 0 {
            // BUG: references livenessProbe, which is nil in this branch
            hcm.Port = int(NameAndPort[livenessProbe.HTTPGet.Port.StrVal])
        }
    }
}

The named-port fallback lookup incorrectly references livenessProbe.HTTPGet.Port.StrVal instead of readinessProbe.HTTPGet.Port.StrVal. Since livenessProbe is guaranteed to be nil in the else branch, dereferencing it causes a panic.

Fix

Change livenessProbe to readinessProbe on the affected line, matching the surrounding code's intent:

-    hcm.Port = int(NameAndPort[livenessProbe.HTTPGet.Port.StrVal])
+    hcm.Port = int(NameAndPort[readinessProbe.HTTPGet.Port.StrVal])

This is a one-line, surgical fix that corrects the variable reference to match the enclosing scope. No behavior change for the liveness probe path.

Closes #2512

When a container has only a readiness probe (no liveness probe), the
readiness probe handler incorrectly referenced `livenessProbe.HTTPGet`
instead of `readinessProbe.HTTPGet` for the named-port fallback lookup.

Since livenessProbe is nil in the else branch, this causes a nil pointer
dereference panic when parsing Helm charts without liveness probe config.

Fixes #2512

Signed-off-by: A386official <A386official@users.noreply.github.com>
@A386official A386official force-pushed the fix/nil-pointer-liveness-probe-readiness-fallback branch from b99a146 to c0d8b51 Compare February 28, 2026 09:46
@A386official A386official closed this by deleting the head repository Mar 1, 2026
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.

🐞 Bug report: 通过helm创建应用时,由于没有配置存活探针,应用创建失败,无任何提示

1 participant