From 5beaa1799dca82b0e76fa7e07c557dccc6d8cac2 Mon Sep 17 00:00:00 2001 From: Suleiman Dibirov Date: Sat, 8 Jun 2024 16:20:58 +0300 Subject: [PATCH] updated test Signed-off-by: Suleiman Dibirov --- cmd/helm/template_test.go | 9 +++++++-- .../template-chart-with-ingress-with-list-host.txt | 13 +++++++++++++ .../templates/certificate.yaml | 13 +++++++++++++ .../chart-with-ingress-with-list-host/values.yaml | 9 +++++++++ pkg/chartutil/coalesce.go | 10 ++++------ 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/templates/certificate.yaml diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index c63c14545..c4efb8a79 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -72,8 +72,13 @@ func TestTemplateCmd(t *testing.T) { golden: "output/template-chart-with-ingress-with-map-host.txt", }, { - name: "check chart with map type ingress host and set ingress.hosts[1].host=changed_host.com", - cmd: fmt.Sprintf("template '%s' --set ingress.enabled=true --set ingress.hosts[1].host=changed_host.com", "testdata/testcharts/chart-with-ingress-with-list-host"), + name: "check chart with map type ingress host and set ingress.hosts[1].host=changed_host.com and -f values.yaml", + cmd: fmt.Sprintf( + "template '%s' %s %s", + "testdata/testcharts/chart-with-ingress-with-list-host", + "--set ingress.enabled=true --set ingress.hosts[1].host=changed_host.com", + "--set certificate.dnsNames[1][1]=changed_dns_host.local", + ), golden: "output/template-chart-with-ingress-with-list-host.txt", }, { diff --git a/cmd/helm/testdata/output/template-chart-with-ingress-with-list-host.txt b/cmd/helm/testdata/output/template-chart-with-ingress-with-list-host.txt index f81ea04df..0cfe955f7 100644 --- a/cmd/helm/testdata/output/template-chart-with-ingress-with-list-host.txt +++ b/cmd/helm/testdata/output/template-chart-with-ingress-with-list-host.txt @@ -10,3 +10,16 @@ spec: - host: "myhost1.local" - host: "changed_host.com" - host: "myhost3.local" +--- +# Source: chart-with-ingress-with-list-host/templates/certificate.yaml +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: chart-with-ingress-with-list-host +spec: + dnsNames: + - "podinfo" + - "[myhost1.local changed_dns_host.local myhost3.local]" + issuerRef: + kind: ClusterIssuer + name: self-signed diff --git a/cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/templates/certificate.yaml b/cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/templates/certificate.yaml new file mode 100644 index 000000000..ad85b21c4 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/templates/certificate.yaml @@ -0,0 +1,13 @@ +{{- if .Values.certificate.create -}} +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: {{ .Chart.Name }} +spec: + dnsNames: + {{- range .Values.certificate.dnsNames }} + - {{ . | quote }} + {{- end }} + issuerRef: + {{- .Values.certificate.issuerRef | toYaml | trimSuffix "\n" | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/values.yaml b/cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/values.yaml index fc7c64b00..6c6a6fd6e 100644 --- a/cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/values.yaml +++ b/cmd/helm/testdata/testcharts/chart-with-ingress-with-list-host/values.yaml @@ -12,3 +12,12 @@ ingress: - host: myhost2.local - host: myhost3.local tls: [] + +certificate: + create: true + issuerRef: + kind: ClusterIssuer + name: self-signed + dnsNames: + - podinfo + - [myhost1.local, myhost2.local, myhost3.local] \ No newline at end of file diff --git a/pkg/chartutil/coalesce.go b/pkg/chartutil/coalesce.go index ea47771a0..dd8299943 100644 --- a/pkg/chartutil/coalesce.go +++ b/pkg/chartutil/coalesce.go @@ -312,36 +312,34 @@ func coalesceListsFullKey(printf printFn, dst, src []interface{}, prefix string, // Because dest has higher precedence than src, dest values override src // values. for key, val := range src { + fullkey := concatPrefix(prefix, fmt.Sprintf("%v", key)) + if key == len(dst) { dst = append(dst, val) } else if dst[key] == nil { dst[key] = val } else if istable(val) { if !istable(dst[key]) { - fullkey := concatPrefix(prefix, fmt.Sprintf("%v", key)) printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val) } dst[key] = coalesceTablesFullKey( printf, dst[key].(map[string]interface{}), val.(map[string]interface{}), - prefix, + fullkey, merge, ) } else if islist(val) { if !islist(dst[key]) { - fullkey := concatPrefix(prefix, fmt.Sprintf("%v", key)) printf("warning: cannot overwrite list with non list for %s (%v)", fullkey, val) } dst[key] = coalesceListsFullKey( printf, dst[key].([]interface{}), val.([]interface{}), - prefix, + fullkey, merge, ) - } else { - dst[key] = val } } return dst