diff --git a/OWNERS b/OWNERS index ec88bedd..fc9547f5 100644 --- a/OWNERS +++ b/OWNERS @@ -2,7 +2,9 @@ approvers: - rawlingsj - jstrachan - rajdavies +- tomhobson reviewers: - rawlingsj - jstrachan - rajdavies +- tomhobson diff --git a/cmd/app/main-win.go b/cmd/app/main-win.go index 12896ada..9be96746 100644 --- a/cmd/app/main-win.go +++ b/cmd/app/main-win.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package app diff --git a/cmd/app/main.go b/cmd/app/main.go index b99edcb3..57578513 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -1,4 +1,5 @@ //nolint +//go:build !windows // +build !windows package app diff --git a/hack/linter.sh b/hack/linter.sh index cdeceac5..002cfb9d 100755 --- a/hack/linter.sh +++ b/hack/linter.sh @@ -10,8 +10,8 @@ fi DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if ! [ -x "$(command -v golangci-lint)" ]; then - echo "Installing GolangCI-Lint" - ${DIR}/install_golint.sh -b $GOPATH/bin v1.42.1 + echo "Looks like golangci-lint isn't installed, to run \'make lint\' please install it." + exit 127 fi export GO111MODULE=on diff --git a/pkg/promote/promote_integration_test.go b/pkg/promote/promote_integration_test.go index 4bd9ee3c..a772e6b8 100644 --- a/pkg/promote/promote_integration_test.go +++ b/pkg/promote/promote_integration_test.go @@ -1,3 +1,4 @@ +//go:build integration // +build integration package promote_test diff --git a/pkg/promote/promote_test.go b/pkg/promote/promote_test.go index 60608408..8c87156c 100644 --- a/pkg/promote/promote_test.go +++ b/pkg/promote/promote_test.go @@ -1,3 +1,4 @@ +//go:build unit // +build unit package promote_test diff --git a/pkg/rules/factory/factory_test.go b/pkg/rules/factory/factory_test.go index 609fcb1f..18a75864 100644 --- a/pkg/rules/factory/factory_test.go +++ b/pkg/rules/factory/factory_test.go @@ -30,7 +30,7 @@ func TestRuleFactory(t *testing.T) { t.Logf("creating tests at %s", tmpDir) - sourceData := filepath.Join("test_data") + sourceData := "test_data" fileSlice, err := ioutil.ReadDir(sourceData) assert.NoError(t, err) diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml new file mode 100644 index 00000000..3e9d8d08 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml @@ -0,0 +1,16 @@ +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +releases: +- name: dbmigrator + labels: + job: dbmigrator + chart: ./dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta + namespace: jx diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml.1.expected b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml.1.expected new file mode 100644 index 00000000..8e37b66e --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml.1.expected @@ -0,0 +1,21 @@ +filepath: "" +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: ./dbmigrator + name: dbmigrator + labels: + job: dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta + namespace: jx +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml.2.expected b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml.2.expected new file mode 100644 index 00000000..9c33e0f0 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/helmfile.yaml.2.expected @@ -0,0 +1,21 @@ +filepath: "" +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: ./dbmigrator + name: dbmigrator + labels: + job: dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.4 + name: myapp-beta + namespace: jx +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/options.yaml b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/options.yaml new file mode 100644 index 00000000..2778174f --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option-reversed/options.yaml @@ -0,0 +1,2 @@ +# test for when running `jx promote --release myapp-beta` +release: myapp-beta \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml new file mode 100644 index 00000000..3e9d8d08 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml @@ -0,0 +1,16 @@ +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +releases: +- name: dbmigrator + labels: + job: dbmigrator + chart: ./dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta + namespace: jx diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml.1.expected b/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml.1.expected new file mode 100644 index 00000000..8e37b66e --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml.1.expected @@ -0,0 +1,21 @@ +filepath: "" +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: ./dbmigrator + name: dbmigrator + labels: + job: dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta + namespace: jx +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml.2.expected b/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml.2.expected new file mode 100644 index 00000000..9c33e0f0 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option/helmfile.yaml.2.expected @@ -0,0 +1,21 @@ +filepath: "" +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: ./dbmigrator + name: dbmigrator + labels: + job: dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.4 + name: myapp-beta + namespace: jx +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-double-release-name-option/options.yaml b/pkg/rules/factory/test_data/helmfile-double-release-name-option/options.yaml new file mode 100644 index 00000000..2778174f --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release-name-option/options.yaml @@ -0,0 +1,2 @@ +# test for when running `jx promote --release myapp-beta` +release: myapp-beta \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml new file mode 100644 index 00000000..3e9d8d08 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml @@ -0,0 +1,16 @@ +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +releases: +- name: dbmigrator + labels: + job: dbmigrator + chart: ./dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta + namespace: jx diff --git a/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml.1.expected b/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml.1.expected new file mode 100644 index 00000000..8e37b66e --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml.1.expected @@ -0,0 +1,21 @@ +filepath: "" +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: ./dbmigrator + name: dbmigrator + labels: + job: dbmigrator +- chart: dev/myapp + version: 1.2.3 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta + namespace: jx +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml.2.expected b/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml.2.expected new file mode 100644 index 00000000..73780e30 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-double-release/helmfile.yaml.2.expected @@ -0,0 +1,21 @@ +filepath: "" +repositories: +- name: yourorg + url: https://yourorg.example.com/charts +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: ./dbmigrator + name: dbmigrator + labels: + job: dbmigrator +- chart: dev/myapp + version: 1.2.4 + name: myapp + namespace: jx +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta + namespace: jx +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfile.yaml new file mode 100644 index 00000000..44542970 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfile.yaml @@ -0,0 +1,6 @@ +filepath: "" +helmfiles: +- path: helmfiles/nginx/helmfile.yaml +- path: helmfiles/jx/helmfile.yaml +templates: {} +renderedvalues: {} diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfile.yaml.expected b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfile.yaml.expected new file mode 100644 index 00000000..43342997 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfile.yaml.expected @@ -0,0 +1,6 @@ +filepath: "" +helmfiles: +- path: helmfiles/nginx/helmfile.yaml +- path: helmfiles/jx/helmfile.yaml +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml new file mode 100644 index 00000000..a075b421 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml @@ -0,0 +1,15 @@ +filepath: "" +namespace: jx +repositories: + - name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: + - chart: dev/myapp + version: 1.2.3 + name: myapp + - chart: dev/myapp + version: 1.2.3 + name: myapp-beta +templates: {} +missingFileHandler: "" +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml.1.expected b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml.1.expected new file mode 100644 index 00000000..ce491ccc --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml.1.expected @@ -0,0 +1,14 @@ +filepath: "" +namespace: jx +repositories: +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: dev/myapp + version: 1.2.3 + name: myapp +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml.2.expected b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml.2.expected new file mode 100644 index 00000000..001cf68a --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/jx/helmfile.yaml.2.expected @@ -0,0 +1,14 @@ +filepath: "" +namespace: jx +repositories: +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: dev/myapp + version: 1.2.3 + name: myapp +- chart: dev/myapp + version: 1.2.4 + name: myapp-beta +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/nginx/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/nginx/helmfile.yaml new file mode 100644 index 00000000..b2ef2a15 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/helmfiles/nginx/helmfile.yaml @@ -0,0 +1,21 @@ +filepath: "" +environments: + default: + values: + - ../../jx-values.yaml + - ../../versionStream/src/fake-secrets.yaml.gotmpl +namespace: nginx +repositories: +- name: stable + url: https://charts.helm.sh/stable +releases: +- chart: stable/nginx-ingress + version: 1.39.1 + name: nginx-ingress + values: + - ../../versionStream/charts/stable/nginx-ingress/values.yaml.gotmpl + forceNamespace: "" + skipDeps: null +templates: {} +missingFileHandler: "" +renderedvalues: {} diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/options.yaml b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/options.yaml new file mode 100644 index 00000000..2778174f --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release-name-option/options.yaml @@ -0,0 +1,2 @@ +# test for when running `jx promote --release myapp-beta` +release: myapp-beta \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfile.yaml new file mode 100644 index 00000000..44542970 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfile.yaml @@ -0,0 +1,6 @@ +filepath: "" +helmfiles: +- path: helmfiles/nginx/helmfile.yaml +- path: helmfiles/jx/helmfile.yaml +templates: {} +renderedvalues: {} diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfile.yaml.expected b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfile.yaml.expected new file mode 100644 index 00000000..43342997 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfile.yaml.expected @@ -0,0 +1,6 @@ +filepath: "" +helmfiles: +- path: helmfiles/nginx/helmfile.yaml +- path: helmfiles/jx/helmfile.yaml +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml new file mode 100644 index 00000000..0f99894d --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml @@ -0,0 +1,15 @@ +namespace: jx +repositories: + - name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: + - chart: dev/myapp + version: 1.2.3 + name: myapp + - chart: dev/myapp + version: 1.2.3 + name: myapp-beta +templates: {} +missingFileHandler: "" +renderedvalues: {} + diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml.1.expected b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml.1.expected new file mode 100644 index 00000000..ce491ccc --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml.1.expected @@ -0,0 +1,14 @@ +filepath: "" +namespace: jx +repositories: +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: dev/myapp + version: 1.2.3 + name: myapp +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml.2.expected b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml.2.expected new file mode 100644 index 00000000..10cd678c --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/jx/helmfile.yaml.2.expected @@ -0,0 +1,14 @@ +filepath: "" +namespace: jx +repositories: +- name: dev + url: http://chartmuseum-jx.34.78.195.22.nip.io +releases: +- chart: dev/myapp + version: 1.2.4 + name: myapp +- chart: dev/myapp + version: 1.2.3 + name: myapp-beta +templates: {} +renderedvalues: {} \ No newline at end of file diff --git a/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/nginx/helmfile.yaml b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/nginx/helmfile.yaml new file mode 100644 index 00000000..b2ef2a15 --- /dev/null +++ b/pkg/rules/factory/test_data/helmfile-nested-double-release/helmfiles/nginx/helmfile.yaml @@ -0,0 +1,21 @@ +filepath: "" +environments: + default: + values: + - ../../jx-values.yaml + - ../../versionStream/src/fake-secrets.yaml.gotmpl +namespace: nginx +repositories: +- name: stable + url: https://charts.helm.sh/stable +releases: +- chart: stable/nginx-ingress + version: 1.39.1 + name: nginx-ingress + values: + - ../../versionStream/charts/stable/nginx-ingress/values.yaml.gotmpl + forceNamespace: "" + skipDeps: null +templates: {} +missingFileHandler: "" +renderedvalues: {} diff --git a/pkg/rules/helmfile/helmfile_rule.go b/pkg/rules/helmfile/helmfile_rule.go index b9994888..539cd057 100644 --- a/pkg/rules/helmfile/helmfile_rule.go +++ b/pkg/rules/helmfile/helmfile_rule.go @@ -124,60 +124,38 @@ func modifyHelmfileApps(r *rules.PromoteRule, helmfile *state.HelmState, promote keepOldReleases := r.Config.Spec.HelmfileRule.KeepOldReleases || contains(r.Config.Spec.HelmfileRule.KeepOldVersions, details.Name) if nestedHelmfile { - - if len(helmfile.Releases) == 0 { - // for nested helmfiles when adding the first release, set it up as the override - // then when future releases are added they can omit the namespace if their namespace matches this override - // if different namespaces are required for releases, manual edits should be done to - // set the namespace of EVERY release and make OverrideNamespace blank - if promoteNs != "" && helmfile.OverrideNamespace == "" { - helmfile.OverrideNamespace = promoteNs - } - } - - found := false - if !keepOldReleases { - for i := range helmfile.Releases { - release := &helmfile.Releases[i] - if release.Name == app || release.Name == details.Name || (r.ReleaseName != "" && release.Name == r.ReleaseName) { - release.Version = version - return nil - } - } - } - if !found { - ns := "" - if promoteNs != helmfile.OverrideNamespace { - ns = promoteNs - } - newReleaseName := details.LocalName - if r.ReleaseName != "" { - newReleaseName = r.ReleaseName - } - if keepOldReleases { - newReleaseName = fmt.Sprintf("%s-%s", newReleaseName, strings.Replace(version, ".", "-", -1)) - } - helmfile.Releases = append(helmfile.Releases, state.ReleaseSpec{ - Name: newReleaseName, - Chart: details.Name, - Namespace: ns, - Version: version, - }) - } + // This is edge case so moved to a separate function + promoteNestedHelmfileReleases(r, details, promoteNs, helmfile, keepOldReleases) return nil } - found := false + + // Time to use scoring instead of just a simple found. + highestScorer := new(state.ReleaseSpec) + highestScore := 0 if !keepOldReleases { for i := range helmfile.Releases { + score := 0 release := &helmfile.Releases[i] - if (release.Name == app || release.Name == details.Name || (r.ReleaseName != "" && release.Name == r.ReleaseName)) && (release.Namespace == promoteNs || isRemoteEnv) { - release.Version = version - return nil + + if release.Name == r.AppName && (release.Namespace == promoteNs || isRemoteEnv) { + score++ + } + + if (r.ReleaseName != "" && release.Name == r.ReleaseName) && (release.Namespace == promoteNs || isRemoteEnv) { + // This scores higher as it's a direct match + score += 2 + } + + if score > highestScore { + highestScorer = release + highestScore = score } } } - if !found { + if highestScore > 0 { + highestScorer.Version = r.Version + } else { newReleaseName := details.LocalName if r.ReleaseName != "" { newReleaseName = r.ReleaseName @@ -196,6 +174,63 @@ func modifyHelmfileApps(r *rules.PromoteRule, helmfile *state.HelmState, promote return nil } +func promoteNestedHelmfileReleases(r *rules.PromoteRule, details *envctx.ChartDetails, promoteNs string, helmfile *state.HelmState, keepOldReleases bool) { + if len(helmfile.Releases) == 0 { + // for nested helmfiles when adding the first release, set it up as the override + // then when future releases are added they can omit the namespace if their namespace matches this override + // if different namespaces are required for releases, manual edits should be done to + // set the namespace of EVERY release and make OverrideNamespace blank + if promoteNs != "" && helmfile.OverrideNamespace == "" { + helmfile.OverrideNamespace = promoteNs + } + } + + // Time to use scoring instead of just a simple found. + highestScorer := new(state.ReleaseSpec) + highestScore := 0 + if !keepOldReleases { + for i := range helmfile.Releases { + score := 0 + release := &helmfile.Releases[i] + + if release.Name == r.AppName { + score++ + } + + if r.ReleaseName != "" && release.Name == r.ReleaseName { + score += 2 + } + + if score > highestScore { + highestScorer = release + highestScore = score + } + } + } + + if highestScore > 0 { + highestScorer.Version = r.Version + } else { + ns := "" + if promoteNs != helmfile.OverrideNamespace { + ns = promoteNs + } + newReleaseName := details.LocalName + if r.ReleaseName != "" { + newReleaseName = r.ReleaseName + } + if keepOldReleases { + newReleaseName = fmt.Sprintf("%s-%s", newReleaseName, strings.Replace(r.Version, ".", "-", -1)) + } + helmfile.Releases = append(helmfile.Releases, state.ReleaseSpec{ + Name: newReleaseName, + Chart: details.Name, + Namespace: ns, + Version: r.Version, + }) + } +} + // defaultPrefix lets find a chart prefix / repository name for the URL that does not clash with // any other existing repositories in the helmfile func defaultPrefix(appsConfig *state.HelmState, envctx *envctx.EnvironmentContext, d *envctx.ChartDetails, defaultPrefix string) {