From 6e445ec679f1771fc9fc085d6d6cd29dc5c183c9 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Fri, 6 Mar 2026 08:37:45 -0700 Subject: [PATCH 1/2] fix: graceful fallback when debug.BuildInfo is unavailable When Helm is built with toolchains other than `go build` (e.g. Bazel), `debug.ReadBuildInfo()` returns false, causing a panic during DefaultCapabilities initialization. Fall back to the default Kubernetes version (v1.20.0) instead of panicking. Fixes #31904 Signed-off-by: Terry Howe --- pkg/chart/common/capabilities.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/chart/common/capabilities.go b/pkg/chart/common/capabilities.go index 20f4953cf..06a9c4df9 100644 --- a/pkg/chart/common/capabilities.go +++ b/pkg/chart/common/capabilities.go @@ -152,7 +152,9 @@ func makeDefaultCapabilities() (*Capabilities, error) { vstr, err := helmversion.K8sIOClientGoModVersion() if err != nil { - return nil, fmt.Errorf("failed to retrieve k8s.io/client-go version: %w", err) + // Build info may be unavailable when compiled with toolchains other + // than "go build" (e.g. Bazel). Fall back to a safe default. + return newCapabilities(kubeVersionMajorTesting, kubeVersionMinorTesting) } v, err := semver.NewVersion(vstr) From 5220dd2d0bdf36365a91e4dfbe01d6f333ad4df4 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Fri, 6 Mar 2026 12:19:30 -0700 Subject: [PATCH 2/2] fix: rename fallback constants and log warning on BuildInfo failure Rename kubeVersionMajorTesting/MinorTesting to kubeVersionMajorDefault/ MinorDefault to reflect their use as general fallback values, not just for testing. Log a warning when falling back to the default Kubernetes version so the behavior is diagnosable. Signed-off-by: Terry Howe --- pkg/chart/common/capabilities.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/chart/common/capabilities.go b/pkg/chart/common/capabilities.go index 06a9c4df9..4174aa929 100644 --- a/pkg/chart/common/capabilities.go +++ b/pkg/chart/common/capabilities.go @@ -17,6 +17,7 @@ package common import ( "fmt" + "log/slog" "slices" "strconv" "strings" @@ -33,8 +34,8 @@ import ( ) const ( - kubeVersionMajorTesting = 1 - kubeVersionMinorTesting = 20 + kubeVersionMajorDefault = 1 + kubeVersionMinorDefault = 20 ) var ( @@ -147,14 +148,15 @@ func makeDefaultCapabilities() (*Capabilities, error) { // (And even if they did, we probably want stable capabilities for tests anyway) // Return a default value for test builds if testing.Testing() { - return newCapabilities(kubeVersionMajorTesting, kubeVersionMinorTesting) + return newCapabilities(kubeVersionMajorDefault, kubeVersionMinorDefault) } vstr, err := helmversion.K8sIOClientGoModVersion() if err != nil { // Build info may be unavailable when compiled with toolchains other // than "go build" (e.g. Bazel). Fall back to a safe default. - return newCapabilities(kubeVersionMajorTesting, kubeVersionMinorTesting) + slog.Warn("failed to retrieve k8s.io/client-go version, falling back to default Kubernetes version", slog.Any("error", err)) + return newCapabilities(kubeVersionMajorDefault, kubeVersionMinorDefault) } v, err := semver.NewVersion(vstr)