Skip to content

Commit

Permalink
test: added test to reproduce values bug #4478
Browse files Browse the repository at this point in the history
Refs #4478

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed May 20, 2022
1 parent 39a79d2 commit 4cf589c
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mycm
data:
testkey: testvalue
4 changes: 4 additions & 0 deletions integration/suites/deploy/helm_values1-001/.helm/values.yaml
@@ -0,0 +1,4 @@
arr:
- one
- two
- three
3 changes: 3 additions & 0 deletions integration/suites/deploy/helm_values1-001/werf.yaml
@@ -0,0 +1,3 @@
project: helm-values
configVersion: 1
---
@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mycm
data:
testkey: testvalue
3 changes: 3 additions & 0 deletions integration/suites/deploy/helm_values1-002/werf.yaml
@@ -0,0 +1,3 @@
project: helm-values
configVersion: 1
---
95 changes: 95 additions & 0 deletions integration/suites/deploy/helm_values_test.go
@@ -0,0 +1,95 @@
package deploy_test

import (
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/werf/kubedog/pkg/kube"
"github.com/werf/werf/pkg/util"
"github.com/werf/werf/test/pkg/utils"
"github.com/werf/werf/test/pkg/utils/liveexec"
"sigs.k8s.io/yaml"
)

func getValues(params ...string) map[string]interface{} {
output := utils.SucceedCommandOutputString(
SuiteData.GetProjectWorktree(SuiteData.ProjectName),
SuiteData.WerfBinPath,
append([]string{"helm", "get", "values", SuiteData.ProjectName, "--namespace", SuiteData.ProjectName}, params...)...,
)

lines := util.SplitLines(output)
lines = lines[1:]
output = strings.Join(lines, "\n")

var data map[string]interface{}
err := yaml.Unmarshal([]byte(output), &data)
Expect(err).To(Succeed())

return data
}

func getUserSuppliedValues() map[string]interface{} {
return getValues()
}

func getComputedValues() map[string]interface{} {
return getValues("--all")
}

var _ = Describe("Helm values", func() {
BeforeEach(func() {
Expect(kube.Init(kube.InitOptions{})).To(Succeed())
})

Context("explicit values param may break default values changes in further deploys: https://github.com/werf/werf/issues/4478", func() {
It("ignores chagnes in the .helm/values.yaml", func() {
By("Installing release first time with basic .helm/values.yaml")
SuiteData.CommitProjectWorktree(SuiteData.ProjectName, "helm_values1-001", "initial commit")
Expect(werfConverge(SuiteData.GetProjectWorktree(SuiteData.ProjectName), liveexec.ExecCommandOptions{})).To(Succeed())

{
uv := getUserSuppliedValues()
Expect(len(uv)).To(Equal(0))

cv := getComputedValues()
Expect(cv).To(Equal(map[string]interface{}{
"arr": []interface{}{"one", "two", "three"},
}))
}

By("Upgrading release with explicit --values param and the same values file")
Expect(werfConverge(SuiteData.GetProjectWorktree(SuiteData.ProjectName), liveexec.ExecCommandOptions{}, "--values", ".helm/values.yaml")).To(Succeed())

{
uv := getUserSuppliedValues()
Expect(uv).To(Equal(map[string]interface{}{
"arr": []interface{}{"one", "two", "three"},
}))

cv := getComputedValues()
Expect(cv).To(Equal(map[string]interface{}{
"arr": []interface{}{"one", "two", "three"},
}))
}

By("Upgrading release without explicit values param and changed values file")
SuiteData.CommitProjectWorktree(SuiteData.ProjectName, "helm_values1-002", "append new value into default values array")
Expect(werfConverge(SuiteData.GetProjectWorktree(SuiteData.ProjectName), liveexec.ExecCommandOptions{})).To(Succeed())

{
uv := getUserSuppliedValues()
Expect(uv).To(Equal(map[string]interface{}{
"arr": []interface{}{"one", "two", "three"},
}))

cv := getComputedValues()
Expect(cv).To(Equal(map[string]interface{}{
"arr": []interface{}{"one", "two", "three"},
}))
}
})
})
})

0 comments on commit 4cf589c

Please sign in to comment.