Skip to content

Commit 5bcbfea

Browse files
committed
build: derive default Capabilities.KubeVersion from client-go
Helm's chartutil declares k8sVersionMajor/Minor as build-time overridable variables whose in-source values are "1" and "20". Helm's own Makefile replaces them via -ldflags, deriving them from the k8s.io/client-go version it builds against, so the helm CLI reports a current default. This provider builds with no -ldflags for them, so it inherits the literal source values and DefaultCapabilities.KubeVersion resolves to v1.20.0. That surfaces in data.helm_template, which renders with ClientOnly and therefore falls back to DefaultCapabilities. Any chart declaring a kubeVersion constraint above 1.20 refuses to render, and the error names the bogus version rather than the constraint's real problem: Error running Helm install: chart requires kubeVersion: >=1.29.0-0 which is incompatible with Kubernetes v1.20.0 The same chart renders fine with the helm CLI, because that binary is the one build where the ldflags are set. Set the two flags in both build paths, mirroring Helm's Makefile: the release build in .github/workflows/build.yml, and the GNUmakefile so local builds behave like released ones. client-go v0.x.y corresponds to Kubernetes v1.x.y, hence the +1 on the major. With k8s.io/client-go v0.35.1 the default becomes v1.35.0.
1 parent a4f1c1d commit 5bcbfea

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

.github/workflows/build.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,22 @@ jobs:
132132
arch: ${{ matrix.goarch }}
133133
reproducible: report
134134
instructions: |
135+
# Derive Helm's default Capabilities.KubeVersion from the
136+
# k8s.io/client-go version this provider builds against, mirroring
137+
# Helm's own Makefile. Without these, chartutil keeps its in-source
138+
# values of 1 and 20, so anything rendering a chart without a
139+
# cluster connection reports Kubernetes v1.20.0 and charts declaring
140+
# a kubeVersion constraint refuse to render. client-go v0.x.y
141+
# corresponds to Kubernetes v1.x.y, hence the +1.
142+
K8S_MODULES_VER="$(go list -f '{{.Version}}' -m k8s.io/client-go)"
143+
K8S_MODULES_VER="${K8S_MODULES_VER#v}"
144+
K8S_MODULES_MAJOR_VER="$(( $(echo "$K8S_MODULES_VER" | cut -d. -f1) + 1 ))"
145+
K8S_MODULES_MINOR_VER="$(echo "$K8S_MODULES_VER" | cut -d. -f2)"
135146
go build \
136147
-o "$BIN_PATH" \
137148
-trimpath \
138149
-buildvcs=false \
139-
-ldflags "-s -w -X 'main.Version=${{ needs.set-product-version.outputs.product-version }}'"
150+
-ldflags "-s -w -X 'main.Version=${{ needs.set-product-version.outputs.product-version }}' -X 'helm.sh/helm/v3/pkg/chartutil.k8sVersionMajor=$K8S_MODULES_MAJOR_VER' -X 'helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor=$K8S_MODULES_MINOR_VER'"
140151
cp LICENSE "$TARGET_DIR/LICENSE.txt"
141152
142153
whats-next:

GNUmakefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,23 @@ endif
2020
LAST_RELEASE?=$$(git describe --tags $$(git rev-list --tags --max-count=1))
2121
THIS_RELEASE?=$$(git rev-parse --abbrev-ref HEAD)
2222

23+
# Derive Helm's default Capabilities.KubeVersion from the k8s.io/client-go
24+
# version this provider builds against, mirroring Helm's own Makefile. Without
25+
# these, chartutil.k8sVersionMajor/Minor keep their in-source values of 1 and
26+
# 20, so anything rendering a chart without a cluster connection reports
27+
# Kubernetes v1.20.0 and charts declaring a kubeVersion constraint refuse to
28+
# render. client-go v0.x.y corresponds to Kubernetes v1.x.y, hence the +1.
29+
K8S_MODULES_VER=$(subst ., ,$(subst v,,$(shell go list -f '{{.Version}}' -m k8s.io/client-go)))
30+
K8S_MODULES_MAJOR_VER=$(shell echo $$(($(firstword $(K8S_MODULES_VER)) + 1)))
31+
K8S_MODULES_MINOR_VER=$(word 2,$(K8S_MODULES_VER))
32+
33+
LDFLAGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
34+
LDFLAGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
35+
2336
default: build
2437

2538
build: fmtcheck
26-
go build -v .
39+
go build -v -ldflags "$(LDFLAGS)" .
2740

2841
# expected to be invoked by make changelog LAST_RELEASE=gitref THIS_RELEASE=gitref
2942
changelog:
@@ -89,7 +102,7 @@ packages:
89102
for arch in $(PKG_ARCH); do \
90103
mkdir -p $(BUILD_PATH)/$(PROVIDER)_$${os}_$${arch} && \
91104
cd $(BASE_PATH) && \
92-
CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} go build -o $(BUILD_PATH)/$(PROVIDER)_$${os}_$${arch}/$(PROVIDER)_$(VERSION) . && \
105+
CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} go build -ldflags "$(LDFLAGS)" -o $(BUILD_PATH)/$(PROVIDER)_$${os}_$${arch}/$(PROVIDER)_$(VERSION) . && \
93106
cd $(BUILD_PATH) && \
94107
tar -cvzf $(BUILD_PATH)/$(PROVIDER)_$(BRANCH)_$${os}_$${arch}.tar.gz $(PROVIDER)_$${os}_$${arch}/; \
95108
done; \

0 commit comments

Comments
 (0)