YS can be used in combination with Helm's standard
Go template ⧉ syntax or it can replace it
entirely.
When YS is used exclusively, the Helm chart templates are not only
simpler and more concise, but they are also valid YAML files (just like the
Chart.yaml and values.yaml files).
That means they can be processed with any YAML tools, such as being validated
with a YAML linter like yamllint ⧉.
This is a side by side comparison of the Helm chart template YAML files created
by helm create <chart-name> and then converted to use YS.
The left side is the YS version and the right side is the original Go
template version.
ys-chart/templates/helpers.yaml
!YS v0:defn trunc(s):take(63 s).str(*).replace(/-$/)# Expand the name of the chart:chart-name =:trunc:Values.nameOverride ||| Chart.name# Create a default fully qualified app name.chart-fullname =:if Values.fullnameOverride.?:trunc:Values.fullnameOverrideelse:name =:Values.nameOverride ||| Chart.nameif name.has?(Release.Name):trunc:Release.Nameformat "%s-%s":Release.Name name# Selector labels:selectorLabels =::app.kubernetes.io/name::Chart.nameapp.kubernetes.io/instance::Release.Name# Chart labels:chart-labels =::helm.sh/chart::"$(Chart.name)-$(Chart.version)"::selectorLabelsapp.kubernetes.io/version::Chart.appVersionapp.kubernetes.io/managed-by::Release.Service# Create the name of the service account to use:serviceAccountName =:Values.serviceAccount.name |||:if Values.serviceAccount.create:chart-fullname'default'
go-chart/templates/_helpers.tpl
{{/*
Expand the name of the chart.
*/}}
{{- define "go-chart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to
this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "go-chart.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "go-chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 |
trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "go-chart.labels" -}}
helm.sh/chart: {{ include "go-chart.chart" . }}
{{ include "go-chart.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "go-chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "go-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "go-chart.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "go-chart.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}