From e2704403af3a592be97154a76f60dcf4e0daecf5 Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 28 May 2026 18:25:08 +0100 Subject: [PATCH] Add missed changes Signed-off-by: Evans Mungai --- internal/version/version.go | 17 ++++++++++----- internal/version/version_helmtest.go | 31 ---------------------------- pkg/chart/common/capabilities.go | 3 ++- 3 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 internal/version/version_helmtest.go diff --git a/internal/version/version.go b/internal/version/version.go index dfd58c081..1259e8437 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -23,6 +23,8 @@ import ( "strings" "github.com/Masterminds/semver/v3" + + "helm.sh/helm/v4/internal/test" ) var ( @@ -42,9 +44,14 @@ var ( gitTreeState = "" ) -var ( - KubeVersionMajorTesting uint64 - KubeVersionMinorTesting uint64 +// Stub Kubernetes version values for use by any test path that needs a +// stable kube major/minor — for example, substituting into capabilities or +// client-go version strings so test output doesn't drift with the +// k8s.io/client-go version pinned in go.mod. Callers decide when to use +// them; they are not tied to any particular build tag or gating mechanism. +const ( + KubeVersionMajorTesting uint64 = 1 + KubeVersionMinorTesting uint64 = 20 ) // BuildInfo describes the compile time information. @@ -81,7 +88,7 @@ func Get() BuildInfo { // Test builds don't include debug info / module info // (And even if they did, we probably want a stable version during tests anyway) // Return a default value for test builds - if KubeVersionMajorTesting != 0 && KubeVersionMinorTesting != 0 { + if test.IsTestMode() { return fmt.Sprintf("v%d.%d", KubeVersionMajorTesting, KubeVersionMinorTesting) } @@ -112,7 +119,7 @@ func Get() BuildInfo { } // HACK(bacongobbler): strip out GoVersion during a test run for consistent test output - if KubeVersionMajorTesting != 0 && KubeVersionMinorTesting != 0 { + if test.IsTestMode() { v.GoVersion = "" } return v diff --git a/internal/version/version_helmtest.go b/internal/version/version_helmtest.go deleted file mode 100644 index 0354d0985..000000000 --- a/internal/version/version_helmtest.go +++ /dev/null @@ -1,31 +0,0 @@ -//go:build helmtest - -/* -Copyright The Helm Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package version - -// This file is only compiled when the `helmtest` build tag is set (applied by -// the Makefile to all test invocations). It seeds the testing-version -// sentinels so that production code paths in this package and in -// pkg/chart/common substitute stable values instead of attempting to read -// build info from a `go test` binary (which has no module info and would -// panic during package init). - -func init() { - KubeVersionMajorTesting = 1 - KubeVersionMinorTesting = 20 -} diff --git a/pkg/chart/common/capabilities.go b/pkg/chart/common/capabilities.go index 135476107..e88f8ad99 100644 --- a/pkg/chart/common/capabilities.go +++ b/pkg/chart/common/capabilities.go @@ -28,6 +28,7 @@ import ( apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" k8sversion "k8s.io/apimachinery/pkg/util/version" + "helm.sh/helm/v4/internal/test" helmversion "helm.sh/helm/v4/internal/version" ) @@ -140,7 +141,7 @@ func makeDefaultCapabilities() (*Capabilities, error) { // Test builds don't include debug info / module info // (And even if they did, we probably want stable capabilities for tests anyway) // Return a default value for test builds - if helmversion.KubeVersionMajorTesting != 0 && helmversion.KubeVersionMinorTesting != 0 { + if test.IsTestMode() { return newCapabilities(helmversion.KubeVersionMajorTesting, helmversion.KubeVersionMinorTesting) }