pull/8556/merge
Holder 8 months ago committed by GitHub
commit cdf749a8c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -113,6 +113,11 @@ func TestTemplateCmd(t *testing.T) {
cmd: fmt.Sprintf("template '%s' --show-only templates/service.yaml --show-only charts/subcharta/templates/service.yaml", chartPath), cmd: fmt.Sprintf("template '%s' --show-only templates/service.yaml --show-only charts/subcharta/templates/service.yaml", chartPath),
golden: "output/template-show-only-multiple.txt", golden: "output/template-show-only-multiple.txt",
}, },
{
name: "check chart with multiple dependencies that share global value",
cmd: fmt.Sprintf("template '%s' --set global.ingress.annotations.test=global", "testdata/testcharts/chart-with-subchart-global"),
golden: "output/template-with-subchart-global-value.txt",
},
{ {
name: "template with show-only glob", name: "template with show-only glob",
cmd: fmt.Sprintf("template '%s' --show-only templates/subdir/role*", chartPath), cmd: fmt.Sprintf("template '%s' --show-only templates/subdir/role*", chartPath),

@ -0,0 +1,48 @@
---
# Source: chart-with-subchart-global/charts/dep1/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: RELEASE-NAME-dep1
labels:
helm.sh/chart: dep1-0.1.0
app.kubernetes.io/name: dep1
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
annotations:
some-annotation: dep1
test: global
spec:
rules:
- host: "localhost1"
http:
paths:
- path: /
backend:
serviceName: RELEASE-NAME-dep1
servicePort: 80
---
# Source: chart-with-subchart-global/charts/dep2/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: RELEASE-NAME-dep2
labels:
helm.sh/chart: dep2-0.1.0
app.kubernetes.io/name: dep2
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
annotations:
some-annotation: dep2
test: global
spec:
rules:
- host: "localhost2"
http:
paths:
- path: /
backend:
serviceName: RELEASE-NAME-dep2
servicePort: 80

@ -0,0 +1,9 @@
dependencies:
- name: dep1
repository: file://../dep1
version: 0.1.0
- name: dep2
repository: file://../dep2
version: 0.1.0
digest: sha256:3278a7071cc4f6cecc966ec807fd378018d2f7f07f5f136b538596c1d9066c51
generated: "2020-08-03T18:59:45.008862+03:00"

@ -0,0 +1,15 @@
apiVersion: v2
name: chart-with-subchart-global
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0
dependencies:
- name: dep1
version: 0.1.0
repository: file://./dep1
- name: dep2
version: 0.1.0
repository: file://./dep2

@ -0,0 +1,23 @@
apiVersion: v2
name: dep1
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0

@ -0,0 +1,42 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "dep1.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "dep1.labels" . | nindent 4 }}
{{/* // Here I'm try to merge global & unique for chart annotations*/}}
{{- with merge .Values.global.ingress.annotations .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}

@ -0,0 +1,23 @@
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
service:
type: ClusterIP
port: 80
ingress:
enabled: true
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

@ -0,0 +1,23 @@
apiVersion: v2
name: dep2
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0

@ -0,0 +1,42 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "dep2.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "dep2.labels" . | nindent 4 }}
{{/* // Here I'm try to merge global & unique for chart annotations*/}}
{{- with merge .Values.global.ingress.annotations .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}

@ -0,0 +1,24 @@
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
service:
type: ClusterIP
port: 80
ingress:
enabled: true
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

@ -0,0 +1,22 @@
global:
ingress:
annotations: {}
dep1:
ingress:
enabled: true
annotations:
"some-annotation": "dep1"
hosts:
- host: localhost1
paths:
- /
dep2:
ingress:
enabled: true
annotations:
"some-annotation": "dep2"
hosts:
- host: localhost2
paths:
- /

@ -26,6 +26,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/mitchellh/copystructure"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
@ -291,7 +292,11 @@ func (e Engine) render(tpls map[string]renderable) (rendered map[string]string,
continue continue
} }
// At render time, add information about the template that is being rendered. // At render time, add information about the template that is being rendered.
vals := tpls[filename].vals structureCopy, err := copystructure.Copy(tpls[filename].vals)
if err != nil {
return map[string]string{}, err
}
vals := structureCopy.(chartutil.Values)
vals["Template"] = chartutil.Values{"Name": filename, "BasePath": tpls[filename].basePath} vals["Template"] = chartutil.Values{"Name": filename, "BasePath": tpls[filename].basePath}
var buf strings.Builder var buf strings.Builder
if err := t.ExecuteTemplate(&buf, filename, vals); err != nil { if err := t.ExecuteTemplate(&buf, filename, vals); err != nil {

Loading…
Cancel
Save