Reduce template code duplication. Fixes #5372

Signed-off-by: Luis Davim <luis.davim@jet.com>
pull/5373/head
Luis Davim 7 years ago
parent b7b372f693
commit 0270f2e2b5

@ -1,3 +1,4 @@
appVersion: "3.3"
description: Deploy a basic Alpine Linux pod description: Deploy a basic Alpine Linux pod
home: https://k8s.io/helm home: https://k8s.io/helm
name: alpine name: alpine

@ -4,3 +4,4 @@ name: novals
sources: sources:
- https://github.com/helm/helm - https://github.com/helm/helm
version: 0.2.0 version: 0.2.0
appVersion: 3.3

@ -10,7 +10,6 @@ metadata:
# The "release" convention makes it easy to tie a release to all of the # The "release" convention makes it easy to tie a release to all of the
# Kubernetes resources that were created as part of that release. # Kubernetes resources that were created as part of that release.
app.kubernetes.io/instance: {{.Release.Name | quote }} app.kubernetes.io/instance: {{.Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
# This makes it easy to audit chart usage. # This makes it easy to audit chart usage.
helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
annotations: annotations:

@ -114,7 +114,8 @@ metadata:
# I cannot reference .Chart.Name, but I can do $.Chart.Name # I cannot reference .Chart.Name, but I can do $.Chart.Name
helm.sh/chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}" helm.sh/chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
app.kubernetes.io/instance: "{{ $.Release.Name }}" app.kubernetes.io/instance: "{{ $.Release.Name }}"
app.kubernetes.io/version: {{ .Chart.AppVersion }} # Value from appVersion in Chart.yaml
app.kubernetes.io/version: "{{ $.Chart.AppVersion }}"
app.kubernetes.io/managed-by: "{{ $.Release.Service }}" app.kubernetes.io/managed-by: "{{ $.Release.Service }}"
type: kubernetes.io/tls type: kubernetes.io/tls
data: data:

@ -10,7 +10,7 @@ metadata:
# The "app.kubernetes.io/instance" convention makes it easy to tie a release to all of the # The "app.kubernetes.io/instance" convention makes it easy to tie a release to all of the
# Kubernetes resources that were created as part of that release. # Kubernetes resources that were created as part of that release.
app.kubernetes.io/instance: {{ .Release.Name | quote }} app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
# This makes it easy to audit chart usage. # This makes it easy to audit chart usage.
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/name: {{ template "alpine.name" . }} app.kubernetes.io/name: {{ template "alpine.name" . }}

@ -6,7 +6,6 @@ metadata:
labels: labels:
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/name: {{ template "nginx.name" . }} app.kubernetes.io/name: {{ template "nginx.name" . }}
data: data:

@ -14,7 +14,6 @@ metadata:
# to all of the Kubernetes resources that were created as part of that # to all of the Kubernetes resources that were created as part of that
# release. # release.
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
# This makes it easy to audit chart usage. # This makes it easy to audit chart usage.
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/name: {{ template "nginx.name" . }} app.kubernetes.io/name: {{ template "nginx.name" . }}

@ -10,7 +10,6 @@ metadata:
# The "app.kubernetes.io/instance" convention makes it easy to tie a release to all of the # The "app.kubernetes.io/instance" convention makes it easy to tie a release to all of the
# Kubernetes resources that were created as part of that release. # Kubernetes resources that were created as part of that release.
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
# This makes it easy to audit chart usage. # This makes it easy to audit chart usage.
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/name: {{ template "nginx.name" . }} app.kubernetes.io/name: {{ template "nginx.name" . }}

@ -7,7 +7,6 @@ metadata:
labels: labels:
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/name: {{ template "nginx.name" . }} app.kubernetes.io/name: {{ template "nginx.name" . }}
# This declares the resource to be a hook. By convention, we also name the # This declares the resource to be a hook. By convention, we also name the

@ -5,7 +5,6 @@ metadata:
labels: labels:
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/name: {{ template "nginx.name" . }} app.kubernetes.io/name: {{ template "nginx.name" . }}
annotations: annotations:

@ -10,7 +10,6 @@ metadata:
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
name: {{ template "nginx.fullname" . }} name: {{ template "nginx.fullname" . }}
spec: spec:
# Provides options for the service so chart users have the full choice # Provides options for the service so chart users have the full choice

@ -134,11 +134,7 @@ kind: Ingress
metadata: metadata:
name: {{ $fullName }} name: {{ $fullName }}
labels: labels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} {{ include "<CHARTNAME>.labels" . | indent 4 }}
helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.ingress.annotations }} {{- with .Values.ingress.annotations }}
annotations: annotations:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}
@ -174,11 +170,7 @@ kind: Deployment
metadata: metadata:
name: {{ include "<CHARTNAME>.fullname" . }} name: {{ include "<CHARTNAME>.fullname" . }}
labels: labels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} {{ include "<CHARTNAME>.labels" . | indent 4 }}
helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec: spec:
replicas: {{ .Values.replicaCount }} replicas: {{ .Values.replicaCount }}
selector: selector:
@ -228,11 +220,7 @@ kind: Service
metadata: metadata:
name: {{ include "<CHARTNAME>.fullname" . }} name: {{ include "<CHARTNAME>.fullname" . }}
labels: labels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} {{ include "<CHARTNAME>.labels" . | indent 4 }}
helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec: spec:
type: {{ .Values.service.type }} type: {{ .Values.service.type }}
ports: ports:
@ -300,6 +288,19 @@ Create chart name and version as used by the chart label.
{{- define "<CHARTNAME>.chart" -}} {{- define "<CHARTNAME>.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}} {{- end -}}
{{/*
Common labels
*/}}
{{- define "<CHARTNAME>.labels" -}}
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }}
helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion -}}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end -}}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
` `
const defaultTestConnection = `apiVersion: v1 const defaultTestConnection = `apiVersion: v1
@ -307,11 +308,7 @@ kind: Pod
metadata: metadata:
name: "{{ include "<CHARTNAME>.fullname" . }}-test-connection" name: "{{ include "<CHARTNAME>.fullname" . }}-test-connection"
labels: labels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} {{ include "<CHARTNAME>.labels" . | indent 4 }}
helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations: annotations:
"helm.sh/hook": test-success "helm.sh/hook": test-success
spec: spec:

@ -7,7 +7,6 @@ metadata:
labels: labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }} app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }} app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
kubeVersion: {{ .Capabilities.KubeVersion.Major }} kubeVersion: {{ .Capabilities.KubeVersion.Major }}
tillerVersion: {{ .Capabilities.TillerVersion }} tillerVersion: {{ .Capabilities.TillerVersion }}

Loading…
Cancel
Save