Skip to content

Helm 4 template uses K8s 1.20 default instead of client-go version #31508

Closed

Description

@rassie

What happened?

Helm 4's helm template command defaults to Kubernetes 1.20 instead of matching the client-go version (currently 1.34). This causes charts that use .Capabilities.KubeVersion to render old/deprecated API versions.

Charts using capability detection (like Bitnami's common library) render policy/v1beta1 instead of policy/v1 for PodDisruptionBudgets, batch/v1beta1 instead of batch/v1 for CronJobs, etc.

Root cause: The Makefile (lines 70-71) has incorrect LDFLAGS paths. They target helm.sh/helm/v4/pkg/chart/common/util.k8sVersionMajor but the variables are actually in pkg/chart/common/capabilities.go (package common, not common/util). The LDFLAGS silently fail, leaving the hardcoded 1.20 defaults instead of the client-go version.

This was introduced in commit 9dcc49c "Move lint pkg to be part of each chart version".

What did you expect to happen?

helm template should default to the Kubernetes version matching the bundled client-go library (v0.34.x = K8s 1.34), allowing charts to render current stable API versions when no cluster is available or --kube-version is not specified.

How can we reproduce it (as minimally and precisely as possible)?

# Create test chart
mkdir -p /tmp/testchart/templates
cat > /tmp/testchart/Chart.yaml << 'EOF'
apiVersion: v2
name: testchart
version: 0.1.0
EOF

cat > /tmp/testchart/templates/test.yaml << 'EOF'
KubeVersion: {{ .Capabilities.KubeVersion.Version }}
Major: {{ .Capabilities.KubeVersion.Major }}
Minor: {{ .Capabilities.KubeVersion.Minor }}
EOF

# Test with no cluster access to force default capabilities
KUBECONFIG=/dev/null helm template test /tmp/testchart

Expected output:

KubeVersion: v1.34.0
Major: 1
Minor: 34

Actual output:

KubeVersion: v1.20.0
Major: 1
Minor: 20

Real-world impact test:

KUBECONFIG=/dev/null helm template test bitnami/keycloak --version 24.2.1 | grep -A2 "kind: PodDisruptionBudget"

Shows apiVersion: policy/v1beta1 (deprecated in K8s 1.21) instead of policy/v1.

Verification of fix:

--- a/Makefile
+++ b/Makefile
@@ -67,8 +67,8 @@ LDFLAGS += -X helm.sh/helm/v4/pkg/chart/v2/lint/rules.k8sVersionMajor=$(K8S_MOD
 LDFLAGS += -X helm.sh/helm/v4/pkg/chart/v2/lint/rules.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
 LDFLAGS += -X helm.sh/helm/v4/pkg/internal/v3/lint/rules.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
 LDFLAGS += -X helm.sh/helm/v4/pkg/internal/v3/lint/rules.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
-LDFLAGS += -X helm.sh/helm/v4/pkg/chart/common/util.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
-LDFLAGS += -X helm.sh/helm/v4/pkg/chart/common/util.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
+LDFLAGS += -X helm.sh/helm/v4/pkg/chart/common.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
+LDFLAGS += -X helm.sh/helm/v4/pkg/chart/common.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
 LDFLAGS += -X helm.sh/helm/v4/internal/version.kubeClientVersionMajor=$(K8S_MODULES_MAJOR_VER)
 LDFLAGS += -X helm.sh/helm/v4/internal/version.kubeClientVersionMinor=$(K8S_MODULES_MINOR_VER)

After applying the fix and rebuilding:

$ make build
$ KUBECONFIG=/dev/null ./bin/helm template test /tmp/testchart
---
# Source: testchart/templates/test.yaml
KubeVersion: v1.34.0
Major: 1
Minor: 34

Helm version

Details
$ helm version
version.BuildInfo{Version:"v4.0.0+g99cd196", GitCommit:"99cd1964357c793351be481d55abbe21c6b2f4ec", GitTreeState:"clean", GoVersion:"go1.23.6"}

Kubernetes version

Details
$ kubectl version
Client Version: v1.34.2
Kustomize Version: v5.6.0
Server Version: v1.34.0+k3s1

Activity

  1. TerryHowe commented on Nov 14, 2025

    @TerryHowe
    Contributor

    Nice detail in this issue, but I think dup of #31502

    Fixed probably by #31501
    Related probably #31296

  2. rassie commented on Nov 14, 2025

    @rassie
    Author

    @TerryHowe While #31296 is more related to making the process less Makefile dependant, it raises an important issue where Brew might have been the culprit -- I'm also using Brew's version. I'll investigate locally. Thanks for the pointers!

  3. rassie commented on Nov 14, 2025

    @rassie
    Author

    Re-checked with official Helm 4 binary -- same problem persists. I consider #31502 and #31501 somewhat related, but they are more concerned with errors/warnings when falling back to 1.20.x, but less concerned with always falling back without extra CLI arguments, as happening now.

  4. benoittgt commented on Nov 14, 2025

    @benoittgt
    Contributor

    I agree that my proposal is really the lower effort and we could have a much more smarter way to choose the default version.

  5. benoittgt commented on Nov 14, 2025

    @benoittgt
    Contributor

    @rassie with all the work in the initial PR, do you want to open a PR? Otherwise I can do it.

  6. rassie commented on Nov 14, 2025

    @rassie
    Author

    @rassie with all the work in the initial PR, do you want to open a PR? Otherwise I can do it.

    Go ahead, I won't be at my machine for the next 18 hours.

  7. added 2 commits that reference this issue on Nov 14, 2025
    bcac2c6
    b6a8c65
  8. benoittgt commented on Nov 15, 2025

    @benoittgt
    Contributor

    Thanks a lot @rassie for the quality of the issue and the patch suggestion.

  9. added
    bug
    on Nov 15, 2025
  10. added this to the 4.0.1 milestone on Nov 15, 2025
  11. eumel8 commented on Nov 23, 2025

    @eumel8

    @gjenkins8 : can we have a 4.0.1 pre-release build with this fix? I think many people struggle on this error and don't want to wait until official release date in 3 weeks.

  12. removed this from the 4.0.1 milestone on Nov 23, 2025
  13. added a commit that references this issue on Nov 24, 2025
    2c0dcda
  14. eumel8 commented on Nov 24, 2025

    @eumel8

    fixed and released 4.0.1 today, thanks to the Helm team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions