Skip to content

fix(template): add helpful hint to kubeVersion error when using defaults - #31501

Closed
benoittgt wants to merge 1 commit into
helm:mainfrom
benoittgt:improve-message-when-invalid-kube-version
Closed

benoittgt wants to merge 1 commit into
helm:mainfrom
benoittgt:improve-message-when-invalid-kube-version

Conversation

@benoittgt

@benoittgt benoittgt commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Closes: #31502

On Slack a user reported that he didn't understand why helm template was reporting v1.20.0 incompatibility. He had no Kubernetes cluster connection. This is because we fallback on default Kube version in capabilities.go.

This change tracks whether the KubeVersion is a default fallback and adds a helpful hint to the error message only when the default is used (not when users explicitly set --kube-version).

Before:

Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0

After (with default):

Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0 (no cluster connected, using default version; specify target version with --kube-version)

After (with explicit --kube-version 1.27.0):

Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.27.0

Testing:

$ cat /tmp/test-chart/Chart.yaml 
apiVersion: v2
name: test-chart
version: 1.0.0
kubeVersion: ">= 1.28.0-0"

$ bin/helm template test-release /tmp/test-chart
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0 (no cluster connected, using default version; specify target version with --kube-version)

$ bin/helm template test-release /tmp/test-chart --kube-version 1.27.0
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.27.0

$ bin/helm template test-release /tmp/test-chart --kube-version 1.20.0
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0

$ bin/helm template test-release /tmp/test-chart --kube-version 1.28.0
---
apiVersion: v1
kind: ConfigMap
...

Special notes for your reviewer:

🙇

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

On Slack a user reported that he didn't understand why `helm template`
was reporting v1.20.0. He had no Kubernetes cluster connection. This is
because we fallback on default Kube version in capabilities.go.

This change tracks whether the KubeVersion is a default fallback and
adds a helpful hint to the error message only when the default is used
(not when users explicitly set --kube-version).

Before:
```
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0
```

After (with default):
```
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0 (no cluster connected, using default version; specify target version with --kube-version)
```

After (with explicit --kube-version 1.27.0):
```
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.27.0
```

Testing:
```sh
$ bin/helm template test-release /tmp/test-chart
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0 (no cluster connected, using default version; specify target version with --kube-version)

$ bin/helm template test-release /tmp/test-chart --kube-version 1.27.0
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.27.0

$ bin/helm template test-release /tmp/test-chart --kube-version 1.20.0
Error: chart requires kubeVersion: >= 1.28.0-0 which is incompatible with Kubernetes v1.20.0

$ bin/helm template test-release /tmp/test-chart --kube-version 1.28.0
---
apiVersion: v1
kind: ConfigMap
...
```

Signed-off-by: Benoit Tigeot <[email protected]>
@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 13, 2025

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

benoittgt added a commit to benoittgt/helm that referenced this pull request Nov 14, 2025
The Makefile LDFLAGS were pointing to an incorrect package path
(helm.sh/helm/v4/pkg/chart/common/util) that doesn't exist, causing
the k8sVersionMajor and k8sVersionMinor variables to silently fail
to be set. This left the hardcoded defaults (1.20) in place.

After this fix, `helm template` now correctly defaults to Kubernetes
v1.34.0 (matching the bundled client-go version) instead of v1.20.0,
ensuring charts render with current stable API versions.

Testing scenario:

```sh
cat > /tmp/test-chart-fail/Chart.yaml << 'EOF'
apiVersion: v2
name: test-chart-fail
version: 1.0.0
kubeVersion: ">= 1.35.0-0"
EOF

cat > /tmp/test-chart-fail/templates/deployment.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: nginx
        image: nginx:latest
EOF

./bin/helm template test-release /tmp/test-chart-fail

Exit code 1
Error: chart requires kubeVersion: >= 1.35.0-0 which is incompatible with Kubernetes v1.34.0
```

Fixes helm#31508
Closes helm#31501
Closes helm#31502

Signed-off-by: Benoit Tigeot <[email protected]>
benoittgt added a commit to benoittgt/helm that referenced this pull request Nov 14, 2025
The Makefile LDFLAGS were pointing to an incorrect package path
(helm.sh/helm/v4/pkg/chart/common/util) that doesn't exist, causing
the k8sVersionMajor and k8sVersionMinor variables to silently fail
to be set. This left the hardcoded defaults (1.20) in place.

After this fix, `helm template` now correctly defaults to Kubernetes
v1.34.0 (matching the bundled client-go version) instead of v1.20.0,
ensuring charts render with current stable API versions.

Testing scenario:

```sh
cat > /tmp/test-chart/Chart.yaml << 'EOF'
apiVersion: v2
name: test-chart
version: 1.0.0
kubeVersion: ">= 1.28.0-0"
EOF

./bin/helm template test-release /tmp/test-chart

cat > /tmp/test-chart-fail/Chart.yaml << 'EOF'
apiVersion: v2
name: test-chart-fail
version: 1.0.0
kubeVersion: ">= 1.35.0-0"
EOF

./bin/helm template test-release /tmp/test-chart-fail

Exit code 1
Error: chart requires kubeVersion: >= 1.35.0-0 which is incompatible with Kubernetes v1.34.0
```

Fixes helm#31508
Closes helm#31501
Closes helm#31502

Signed-off-by: Benoit Tigeot <[email protected]>
@benoittgt

Copy link
Copy Markdown
Contributor Author

I think that #31512 is a better approach.

@benoittgt benoittgt closed this Nov 14, 2025
mattfarina pushed a commit that referenced this pull request Nov 24, 2025
The Makefile LDFLAGS were pointing to an incorrect package path
(helm.sh/helm/v4/pkg/chart/common/util) that doesn't exist, causing
the k8sVersionMajor and k8sVersionMinor variables to silently fail
to be set. This left the hardcoded defaults (1.20) in place.

After this fix, `helm template` now correctly defaults to Kubernetes
v1.34.0 (matching the bundled client-go version) instead of v1.20.0,
ensuring charts render with current stable API versions.

Testing scenario:

```sh
cat > /tmp/test-chart/Chart.yaml << 'EOF'
apiVersion: v2
name: test-chart
version: 1.0.0
kubeVersion: ">= 1.28.0-0"
EOF

./bin/helm template test-release /tmp/test-chart

cat > /tmp/test-chart-fail/Chart.yaml << 'EOF'
apiVersion: v2
name: test-chart-fail
version: 1.0.0
kubeVersion: ">= 1.35.0-0"
EOF

./bin/helm template test-release /tmp/test-chart-fail

Exit code 1
Error: chart requires kubeVersion: >= 1.35.0-0 which is incompatible with Kubernetes v1.34.0
```

Fixes #31508
Closes #31501
Closes #31502

Signed-off-by: Benoit Tigeot <[email protected]>
(cherry picked from commit b6a8c65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Helm 4] "helm template" raises meaningless error

2 participants