1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-10-30 23:57:50 +02:00

Versioning for helm charts (#3980)

* Replace '+' to '_' in appVersion

* Add test

* Fix test

* Update test name

Co-authored-by: Vyacheslav Starostin <vyacheslav.starostin@sap.com>
Co-authored-by: Anil Keshav <anil.keshav@sap.com>
This commit is contained in:
Vyacheslav Starostin
2022-08-31 17:39:00 +06:00
committed by GitHub
parent 4b257377ec
commit 1a07ae37b7
3 changed files with 20 additions and 2 deletions

View File

@@ -818,7 +818,7 @@ func TestPropagateVersion(t *testing.T) {
err = yaml.Unmarshal(chartContent, &chartMeta)
assert.NoError(t, err)
assert.Equal(t, "1.2.4-20200101000000+theGitCommitId", chartMeta.AppVersion)
assert.Equal(t, "1.2.4-20200101000000_theGitCommitId", chartMeta.AppVersion)
assert.Equal(t, "1.2.4-20200101000000+theGitCommitId", chartMeta.Version)
})

View File

@@ -2,6 +2,7 @@ package versioning
import (
"fmt"
"strings"
"github.com/ghodss/yaml"
"helm.sh/helm/v3/pkg/chart"
@@ -65,7 +66,8 @@ func (h *HelmChart) SetVersion(version string) error {
h.metadata.Version = version
if h.updateAppVersion {
h.metadata.AppVersion = version
// k8s does not allow a plus sign in labels
h.metadata.AppVersion = strings.ReplaceAll(version, "+", "_")
}
content, err := yaml.Marshal(h.metadata)

View File

@@ -165,6 +165,22 @@ func TestHelmChartSetVersion(t *testing.T) {
assert.Equal(t, "1.2.4", helmChart.metadata.AppVersion)
})
t.Run("success case - update app version: '+' is being replaced with '_' (semver2)", func(t *testing.T) {
fileUtils := newVersioningMockUtils()
helmChart := HelmChart{
utils: fileUtils,
path: "testchart/Chart.yaml",
metadata: chart.Metadata{Version: "1.2.3"},
updateAppVersion: true,
}
// '+' is being replaced with '_' since k8s does not allow a plus sign in labels
err := helmChart.SetVersion("1.2.4-2022+123")
assert.NoError(t, err)
assert.Equal(t, "1.2.4-2022_123", helmChart.metadata.AppVersion)
})
t.Run("error case - init failed with missing chart", func(t *testing.T) {
fileUtils := newVersioningMockUtils()