{{- define "trackwalker.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "trackwalker.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{- define "trackwalker.labels" -}}
app.kubernetes.io/name: {{ include "trackwalker.name" .root }}
app.kubernetes.io/instance: {{ .root.Release.Name }}
app.kubernetes.io/managed-by: {{ .root.Release.Service }}
app.kubernetes.io/part-of: trackwalker
app.kubernetes.io/component: {{ .component }}
helm.sh/chart: {{ printf "%s-%s" .root.Chart.Name .root.Chart.Version | replace "+" "_" }}
{{- end -}}

{{- define "trackwalker.selectorLabels" -}}
app.kubernetes.io/name: {{ include "trackwalker.name" .root }}
app.kubernetes.io/instance: {{ .root.Release.Name }}
app.kubernetes.io/component: {{ .component }}
{{- end -}}

{{- define "trackwalker.image" -}}
{{- $repository := .image.repository -}}
{{- if .root.Values.global.imageRegistry -}}
{{- $repository = printf "%s/%s" (trimSuffix "/" .root.Values.global.imageRegistry) (trimPrefix "/" $repository) -}}
{{- end -}}
{{- if .image.digest -}}
{{- printf "%s@%s" $repository .image.digest -}}
{{- else -}}
{{- printf "%s:%s" $repository .image.tag -}}
{{- end -}}
{{- end -}}

{{- define "trackwalker.secretName" -}}
{{- required "global.existingSecret is required" .Values.global.existingSecret -}}
{{- end -}}

{{- define "trackwalker.storageClass" -}}
{{- if .Values.global.storageClass -}}
storageClassName: {{ .Values.global.storageClass }}
{{- end -}}
{{- end -}}
