From 008b2dd1d4aa14e514bbbe7495417f8c754a0cc3 Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Thu, 18 Jan 2024 09:21:15 +0800 Subject: [PATCH] fix: issue with pre-release Helm version (#1293) --- pkg/helmexec/exec.go | 6 ++++++ pkg/helmexec/exec_test.go | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pkg/helmexec/exec.go b/pkg/helmexec/exec.go index 700c6957..99ae43af 100644 --- a/pkg/helmexec/exec.go +++ b/pkg/helmexec/exec.go @@ -121,6 +121,12 @@ func New(helmBinary string, options HelmExecOptions, logger *zap.SugaredLogger, if err != nil { panic(err) } + + if version.Prerelease() != "" { + logger.Warnf("Helm version %s is a pre-release version. This may cause problems when deploying Helm charts.\n", version) + *version, _ = version.SetPrerelease("") + } + return &execer{ helmBinary: helmBinary, options: options, diff --git a/pkg/helmexec/exec_test.go b/pkg/helmexec/exec_test.go index 2a703c4e..a7e02012 100644 --- a/pkg/helmexec/exec_test.go +++ b/pkg/helmexec/exec_test.go @@ -804,6 +804,17 @@ exec: helm --kube-context dev chart pull chart chartFlags: []string{"--untardir", "/tmp/dir"}, listResult: `Pulling repo/helm-charts:0.14.0 exec: helm --kube-context dev pull oci://repo/helm-charts --version 0.14.0 --destination path1 --untar --untardir /tmp/dir +`, + }, + { + name: "more then v3.7.0 with rc", + helmBin: "helm", + helmVersion: "v3.14.0-rc.1+g69dcc92", + chartName: "repo/helm-charts:0.14.0", + chartPath: "path1", + chartFlags: []string{"--untardir", "/tmp/dir"}, + listResult: `Pulling repo/helm-charts:0.14.0 +exec: helm --kube-context dev pull oci://repo/helm-charts --version 0.14.0 --destination path1 --untar --untardir /tmp/dir `, }, } @@ -811,13 +822,7 @@ exec: helm --kube-context dev pull oci://repo/helm-charts --version 0.14.0 --des tt := tests[i] t.Run(tt.name, func(t *testing.T) { buffer.Reset() - helm := &execer{ - helmBinary: tt.helmBin, - version: semver.MustParse(tt.helmVersion), - logger: logger, - kubeContext: "dev", - runner: &mockRunner{}, - } + helm := New(tt.helmBin, HelmExecOptions{}, logger, "dev", &mockRunner{output: []byte(tt.helmVersion)}) err := helm.ChartPull(tt.chartName, tt.chartPath, tt.chartFlags...) if err != nil { t.Errorf("unexpected error: %v", err)