fix: fall back to default kube version when build info is unavailable

When Helm is compiled 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.

Signed-off-by: MD-Mushfiqur123 <mushfiqur123@users.noreply.github.com>
pull/32157/head
Md_Mushfiqur Rahim 2 months ago
parent f798aa5336
commit cb602c4638

@ -17,6 +17,7 @@ package common
import (
"fmt"
"log/slog"
"slices"
"strconv"
"strings"
@ -152,7 +153,10 @@ 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.
slog.Warn("failed to retrieve k8s.io/client-go version, falling back to default Kubernetes version", slog.Any("error", err))
return newCapabilities(1, 20)
}
v, err := semver.NewVersion(vstr)

Loading…
Cancel
Save