fix: fixes a regexp issue for release summary (#666)

There was an issue a the regexp reding the version from helm output.

Fixes #665
This commit is contained in:
sgandon 2019-06-10 02:18:41 +02:00 committed by KUOKA Yusuke
parent 34c793d87e
commit 56c27c2bd9
2 changed files with 21 additions and 8 deletions

View File

@ -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

View File

@ -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]