{{/* Make sure all variables are set properly */}}
{{- include "common.values.setup" . }}

{{/* Append the configMap to the additionalVolumes */}}
{{- define "transmission.configmap.volume" -}}
name: transmission-settings
configMap:
  name: {{ template "common.names.fullname" . }}-config
{{- end -}}

{{- $volume := include "transmission.configmap.volume" . | fromYaml -}}
{{- if $volume -}}
    {{- $additionalVolumes := append .Values.additionalVolumes $volume }}
    {{- $_ := set .Values "additionalVolumes" (deepCopy $additionalVolumes) -}}
{{- end -}}

{{/* Append the configMap volume to the additionalVolumeMounts */}}
{{- define "transmission.configmap.volumeMount" -}}
name: transmission-settings
mountPath: /config/settings.json
subPath: settings.json
{{- end -}}

{{- $volumeMount := include "transmission.configmap.volumeMount" . | fromYaml -}}
{{- if $volumeMount -}}
    {{- $additionalVolumeMounts := append .Values.additionalVolumeMounts $volumeMount }}
    {{- $_ := set .Values "additionalVolumeMounts" (deepCopy $additionalVolumeMounts) -}}
{{- end -}}


{{/* Render the templates */}}
{{ include "common.all" . }}

{{/* Render the configmap */}}
{{ include "transmission.configmap" . }}
