Skip to content

Commit

Permalink
Fix double encoding of chart values and add chart values to test
Browse files Browse the repository at this point in the history
Apparently the e2e tests didn't cover ValuesContent at all...

Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Feb 1, 2024
1 parent a0b1eae commit 89052b0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
14 changes: 3 additions & 11 deletions pkg/controllers/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chart
import (
"context"
"crypto/sha256"
"encoding/base64"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -591,18 +590,18 @@ func valuesSecret(chart *v1.HelmChart) *corev1.Secret {
}

if chart.Spec.ValuesContent != "" {
secret.Data["values-01_HelmChart.yaml"] = base64encode(chart.Spec.ValuesContent)
secret.Data["values-01_HelmChart.yaml"] = []byte(chart.Spec.ValuesContent)
}
if chart.Spec.RepoCA != "" {
secret.Data["ca-file.pem"] = base64encode(chart.Spec.RepoCA)
secret.Data["ca-file.pem"] = []byte(chart.Spec.RepoCA)
}

return secret
}

func valuesSecretAddConfig(secret *corev1.Secret, config *v1.HelmChartConfig) {
if config.Spec.ValuesContent != "" {
secret.Data["values-10_HelmChartConfig.yaml"] = base64encode(config.Spec.ValuesContent)
secret.Data["values-10_HelmChartConfig.yaml"] = []byte(config.Spec.ValuesContent)
}
}

Expand Down Expand Up @@ -907,10 +906,3 @@ func setSecurityContext(job *batch.Job, chart *v1.HelmChart) {
job.Spec.Template.Spec.Containers[0].SecurityContext = chart.Spec.SecurityContext
}
}

func base64encode(s string) []byte {
b := []byte(s)
dst := make([]byte, base64.StdEncoding.EncodedLen(len(b)))
base64.StdEncoding.Encode(dst, b)
return dst
}
16 changes: 8 additions & 8 deletions pkg/controllers/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@ func TestHashObjects(t *testing.T) {
hash: "SHA256=E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
},
"Chart Only 1": {
hash: "SHA256=774949318A591C34D10D828B9D44F525DCBB34E2249BE2DB0C2FA52BC2A605FD",
hash: "SHA256=F2430D3E9731D361C834918C8811603AB6C7B1ABF794714E6A049667FA26AF56",
chartValuesContent: "foo: bar\n",
},
"Chart Only 2": {
hash: "SHA256=0A37EDD1B2E02066D78A9849F8575148F3832B753988AF32390C2A6C17D9E3F8",
hash: "SHA256=CFA019F5E68D9ECDC32113711AFE24D2A16BDCD6FDFE8C931AEB016B6571CA32",
chartValuesContent: "foo:\n a: true\n b: 1\n c: 'true'\n",
},
"Chart Only 3": {
hash: "SHA256=550D2692E1933725FF53C903624BC71D3C8F2053827462D1CF6F8AFFD7C29935",
hash: "SHA256=D29893D5711A98CE622ABB742144FD9B9CE4721EC74E5C2BE22514FDDC1B7B28",
chartValuesContent: "{}",
},
"Config Only 1": {
hash: "SHA256=965E6A0F61A897F00296B3DB056CB5CEB2751501B55B8B16BAFDA3B97CA085B3",
hash: "SHA256=741B84D32D28AAEB48BB8AB0AC5E81C721FB7F1D388230FE512CAA98F27AE161",
configValuesContent: "foo: baz\n",
},
"Config Only 2": {
hash: "SHA256=7D65D6E3BC1AF42C10A6EC8AACD6B7638C433DFB3B96A1D0DB2FBFAA5F4B7BBC",
hash: "SHA256=F1C538DA9A5416D68C9CE00CE087F5FBE262A2BF09AB4CA012A2CFB75EB7B3F2",
configValuesContent: "foo:\n a: false\n b: 0\n c: 'false'\n",
},
"Config Only 3": {
hash: "SHA256=2AE328666F8BA8A27D089C2E6CE3263FD98E827FB1371999D9C762EFB0D81E2B",
hash: "SHA256=DF34CF6AA589A222578D73E6E8CE2D8FC8B725067CEAE8346DF5074788A3FF1F",
configValuesContent: "{}",
},
"Chart and Config 1": {
hash: "SHA256=9F8063ED2A5BEA23BD634CDD649B4E0999E64977244246B8EEA1A916E568601F",
hash: "SHA256=6E4947C029CC2A4950C271F7411BEE8B54CBD16D384703B67FF36BAE282FCC75",
chartValuesContent: "foo: bar\n",
configValuesContent: "foo: baz\n",
},
"Chart and Config 2": {
hash: "SHA256=78CCC0186D0E09A881708E668C9E47810DDF53F726361027328579FA22F4A3A0",
hash: "SHA256=104D10F97C23BCC66EEA4B6F0489B6F3D6E414094C1DC300F2C123E68BD9BEF5",
chartValuesContent: "foo:\n a: true\n b: 1\n c: 'true'\n",
configValuesContent: "bar:\n a: false\n b: 0\n c: 'false'\n",
},
Expand Down
13 changes: 7 additions & 6 deletions test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func errExit(msg string, err error) {
logrus.Panicf("%s: %v", msg, err)
}

func (f *Framework) NewHelmChart(name, chart, version, helmVersion string, set map[string]intstr.IntOrString) *v1.HelmChart {
func (f *Framework) NewHelmChart(name, chart, version, helmVersion, valuesContent string, set map[string]intstr.IntOrString) *v1.HelmChart {
return &v1.HelmChart{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -124,11 +124,12 @@ func (f *Framework) NewHelmChart(name, chart, version, helmVersion string, set m
},
},
Spec: v1.HelmChartSpec{
Chart: chart,
Version: version,
Repo: "",
Set: set,
HelmVersion: helmVersion,
Chart: chart,
Version: version,
Repo: "",
ValuesContent: valuesContent,
Set: set,
HelmVersion: helmVersion,
},
}
}
Expand Down
17 changes: 15 additions & 2 deletions test/suite/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -98,6 +99,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -128,7 +130,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
Expect(err).ToNot(HaveOccurred())
})
It("Should upgrade the release successfully", func() {
Expect(pods[0].Status.ContainerStatuses[0].Image).To(BeEquivalentTo("docker.io/library/traefik:1.7.20"))
Expect(pods[0].Status.ContainerStatuses[0].Image).To(BeEquivalentTo("docker.io/rancher/library-traefik:1.7.20"))
})
AfterEach(func() {
err = framework.DeleteHelmChart(chart.Name, framework.Namespace)
Expand All @@ -153,6 +155,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -207,6 +210,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -251,6 +255,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -311,6 +316,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v2",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -378,6 +384,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v2",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -410,7 +417,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
Expect(err).ToNot(HaveOccurred())
})
It("Should upgrade the release successfully", func() {
Expect(pods[0].Status.ContainerStatuses[0].Image).To(BeEquivalentTo("docker.io/library/traefik:1.7.20"))
Expect(pods[0].Status.ContainerStatuses[0].Image).To(BeEquivalentTo("docker.io/rancher/library-traefik:1.7.20"))
})
AfterEach(func() {
err = framework.DeleteHelmChart(chart.Name, framework.Namespace)
Expand All @@ -436,6 +443,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -490,6 +498,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -543,6 +552,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -602,6 +612,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -655,6 +666,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down Expand Up @@ -717,6 +729,7 @@ var _ = Describe("Helm Tests", Ordered, func() {
"stable/traefik",
"1.86.1",
"v3",
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
map[string]intstr.IntOrString{
"rbac.enabled": {
Type: intstr.String,
Expand Down

0 comments on commit 89052b0

Please sign in to comment.