From 56c27c2bd9d8d085bd7fb2af0970bebc8fbc7371 Mon Sep 17 00:00:00 2001 From: sgandon Date: Mon, 10 Jun 2019 02:18:41 +0200 Subject: [PATCH] fix: fixes a regexp issue for release summary (#666) There was an issue a the regexp reding the version from helm output. Fixes #665 --- pkg/state/state.go | 14 ++++++++------ pkg/state/state_test.go | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/state/state.go b/pkg/state/state.go index 1da68bb9..a1304024 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -3,11 +3,6 @@ package state import ( "errors" "fmt" - "github.com/roboll/helmfile/pkg/environment" - "github.com/roboll/helmfile/pkg/event" - "github.com/roboll/helmfile/pkg/helmexec" - "github.com/roboll/helmfile/pkg/remote" - "github.com/roboll/helmfile/pkg/tmpl" "io/ioutil" "os" "path" @@ -16,6 +11,12 @@ import ( "strconv" "strings" + "github.com/roboll/helmfile/pkg/environment" + "github.com/roboll/helmfile/pkg/event" + "github.com/roboll/helmfile/pkg/helmexec" + "github.com/roboll/helmfile/pkg/remote" + "github.com/roboll/helmfile/pkg/tmpl" + "regexp" "github.com/tatsushid/go-prettytable" @@ -434,7 +435,8 @@ func (st *HelmState) getDeployedVersion(context helmexec.HelmContext, helm helme //retrieve the version if out, err := helm.List(context, "^"+release.Name+"$", st.tillerFlags(release)...); err == nil { chartName := filepath.Base(release.Chart) - pat := regexp.MustCompile(chartName + "-(.*?)\\s") + //the regexp without escapes : .*\s.*\s.*\s.*\schartName-(.*?)\s + pat := regexp.MustCompile(".*\\s.*\\s.*\\s.*\\s" + chartName + "-(.*?)\\s") versions := pat.FindStringSubmatch(out) if len(versions) > 0 { return versions[1], nil diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index ced5f42f..636e2d5c 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -1,14 +1,15 @@ package state import ( - "github.com/roboll/helmfile/pkg/helmexec" - "github.com/roboll/helmfile/pkg/testhelper" "io/ioutil" "os" "path/filepath" "reflect" "testing" + "github.com/roboll/helmfile/pkg/helmexec" + "github.com/roboll/helmfile/pkg/testhelper" + "errors" "strings" @@ -1232,6 +1233,16 @@ func TestGetDeployedVersion(t *testing.T) { foo 1 Wed Apr 17 17:39:04 2019 DEPLOYED foo-bar-1.0.0-alpha+001 0.1.0 default`, installedVersion: "1.0.0-alpha+001", }, + { + name: "chart version with dash and release with dash", + release: ReleaseSpec{ + Name: "foo-bar", + Chart: "registry/foo-bar", + }, + listResult: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE + foo-bar-release 1 Wed Apr 17 17:39:04 2019 DEPLOYED foo-bar-1.0.0-alpha+001 0.1.0 default`, + installedVersion: "1.0.0-alpha+001", + }, } for i := range tests { tt := tests[i]