From 5220dd2d0bdf36365a91e4dfbe01d6f333ad4df4 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Fri, 6 Mar 2026 12:19:30 -0700 Subject: [PATCH] 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)