Skip to content

Commit

Permalink
wip(charts): use 'context' and 'args' in template functions [pack]
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed Feb 17, 2022
1 parent 890a8a4 commit 03cee7a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
18 changes: 9 additions & 9 deletions charts/common/templates/_envsubstConfig.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{/*
Builds an initContainer definition to perform envsubst on a configMap and store the result to some other volume.
@param .context The caller's context
@param .args.env An object with key-value pairs to define environment variables
@param .args.targetVolumeName The target volume where to copy the configMap content
@param .args.helperSuffix A suffix to use when when requiring more than one invocation of the helper
@param .context The caller's context
@param .args.env An object with key-value pairs to define environment variables
@param .args.targetVolume The target volume where to copy the configMap content
@param .args.helperSuffix A suffix to use when when requiring more than one invocation of the helper
*/}}
{{- define "common.envsubstConfig.renderInitContainer" -}}
- name: envsubst-config{{ default "" .args.helperSuffix }}
Expand Down Expand Up @@ -35,17 +35,17 @@ Builds an initContainer definition to perform envsubst on a configMap and store
name: envsubst-config-source-config{{ default "" .args.helperSuffix }}
readOnly: true
- mountPath: /target
name: {{ .args.targetVolumeName }}
name: {{ .args.targetVolume }}
{{- end -}}

{{/*
Builds a volume definition that should be used with common.envsubstConfig.renderInitContainer
@param .context The caller's context
@param .args.configMapName The configMap to use as source for the copy
@param .args.helperSuffix A suffix to use when when requiring more than one invocation of the helper
@param .context The caller's context
@param .args.sourceConfigMap The configMap to use as source for the copy
@param .args.helperSuffix A suffix to use when when requiring more than one invocation of the helper
*/}}
{{- define "common.envsubstConfig.renderVolume" -}}
- name: envsubst-config-source-config{{ default "" .args.helperSuffix }}
configMap:
name: {{ include "common.tplvalues.render" ( dict "value" .args.configMapName "context" .context ) }}
name: {{ include "common.tplvalues.render" ( dict "value" .args.sourceConfigMap "context" .context ) }}
{{- end -}}
38 changes: 19 additions & 19 deletions charts/common/templates/_kleaner-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Builds a cronjob to clean specified filesystem paths.
@param .root The caller's root scope
@param .values The parameters for the cleaner cronjob. The template expects the following:
@param .context The caller's context
@param .args The parameters for the cleaner cronjob. The template expects the following:
- name The name to give to the cronjob
- cron The schedule expression "0 * * * *"
- cleanupPaths A string with all the paths to scan
Expand All @@ -14,37 +14,37 @@ Builds a cronjob to clean specified filesystem paths.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ .root.Release.Name }}-{{ .values.name }}
namespace: {{ .root.Release.Namespace | quote }}
name: {{ .context.Release.Name }}-{{ .args.name }}
namespace: {{ .context.Release.Namespace | quote }}
spec:
schedule: "{{ .values.cron }}"
schedule: "{{ .args.cron }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: {{ .values.name }}
- name: {{ .args.name }}
image: busybox
command:
- sh
- -c
- for CLEANUP_PATH in {{ .values.cleanupPaths }}; do find $CLEANUP_PATH -type f -mtime +{{ .values.olderThanDays }} -print && find $CLEANUP_PATH -type d -mtime +2 -empty -print {{ if not default false .values.dryRun }}-delete{{ end }} ; done
{{- if .values.volumeMounts }}
- for CLEANUP_PATH in {{ .args.cleanupPaths }}; do find $CLEANUP_PATH -type f -mtime +{{ .args.olderThanDays }} -print && find $CLEANUP_PATH -type d -mtime +2 -empty -print {{ if not default false .args.dryRun }}-delete{{ end }} ; done
{{- if .args.volumeMounts }}
volumeMounts:
{{- include "common.tplvalues.render" ( dict "value" .values.volumeMounts "context" .root ) | nindent 14 }}
{{- include "common.tplvalues.render" ( dict "value" .args.volumeMounts "context" .context ) | nindent 14 }}
{{- end }}
restartPolicy: Never
{{- if .values.volumes }}
{{- if .args.volumes }}
volumes:
{{- include "common.tplvalues.render" ( dict "value" .values.volumes "context" .root ) | nindent 10 }}
{{- include "common.tplvalues.render" ( dict "value" .args.volumes "context" .context ) | nindent 10 }}
{{- end }}
{{- end -}}

{{/*
Builds a cronjob to clean specified object storage paths.
@param .root The caller's root scope
@param .values The parameters for the cleaner cronjob. The template expects the following:
@param .context The caller's context
@param .args The parameters for the cleaner cronjob. The template expects the following:
- name The name to give to the cronjob
- cron The schedule expression "0 * * * *"
- rcloneConfigSecret The name of the secret where rclone.conf can be found
Expand All @@ -56,22 +56,22 @@ Builds a cronjob to clean specified object storage paths.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ .root.Release.Name }}-{{ .values.name }}
namespace: {{ .root.Release.Namespace | quote }}
name: {{ .context.Release.Name }}-{{ .args.name }}
namespace: {{ .context.Release.Namespace | quote }}
spec:
schedule: "{{ .values.cron }}"
schedule: "{{ .args.cron }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: {{ .values.name }}
- name: {{ .args.name }}
image: rclone/rclone
command:
- sh
- -c
- for CLEANUP_PATH in {{ .values.cleanupPaths }}; do rclone --min-age {{ .values.olderThanDays }}d {{ if default false .values.dryRun }}--dry-run{{ end }} delete $CLEANUP_PATH --rmdirs; done
- for CLEANUP_PATH in {{ .args.cleanupPaths }}; do rclone --min-age {{ .args.olderThanDays }}d {{ if default false .args.dryRun }}--dry-run{{ end }} delete $CLEANUP_PATH --rmdirs; done
volumeMounts:
- mountPath: /config/rclone/rclone.conf
name: rclone-config
Expand All @@ -81,5 +81,5 @@ spec:
volumes:
- name: rclone-config
secret:
secretName: {{ .values.rcloneConfigSecret }}
secretName: {{ include "common.tplvalues.render" ( dict "value" .args.rcloneConfigSecret "context" .context) }}
{{- end -}}
12 changes: 6 additions & 6 deletions charts/common/templates/_rclone.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Builds an initContainer using rclone to pull an archive of the config from an object storage.
@param .context The caller's context
@param .args The parameters for the template, expects the following:
- source The source file to copy from the object storage (can be templated)
- targetVolumeName The name of the volume on which the config will be extracted
- sourceArchive The source file to copy from the object storage (can be templated)
- targetVolume The name of the volume on which the config will be extracted
*/}}
{{- define "common.rcloneConfig.renderInitContainer" -}}
{{- $source := include "common.tplvalues.render" (dict "value" .args.source "context" .context) }}
{{- $source := include "common.tplvalues.render" (dict "value" .args.sourceArchive "context" .context) }}
- name: rclone-config
image: rclone/rclone
command:
Expand All @@ -19,17 +19,17 @@ Builds an initContainer using rclone to pull an archive of the config from an ob
subPath: rclone.conf
readOnly: true
- mountPath: /target
name: {{ .args.targetVolumeName }}
name: {{ .args.targetVolume }}
{{- end -}}
{{/*
Builds a volume to mount the rclone config.
@param .context The caller's context
@param .args The parameters for the template, expects the following:
- configSecretName The name of the secret containing the rclone.conf (can be templated)
- rcloneSecret The name of the secret containing the rclone.conf (can be templated)
*/}}
{{- define "common.rcloneConfig.renderVolume" -}}
- name: rclone-config
secret:
secretName: {{ include "common.tplvalues.render" (dict "value" .args.configSecretName "context" .context) }}
secretName: {{ include "common.tplvalues.render" (dict "value" .args.rcloneSecret "context" .context) }}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/mapcache/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ spec:
{{- if .Values.localCacheSource }}
- name: rclone-config
secret:
secretName: {{ include "common.tplvalues.render" ( dict "value" .Values.rcloneConfigSecretName "context" $) }}
secretName: {{ include "common.tplvalues.render" ( dict "value" .Values.rcloneSecret "context" $) }}
{{- end }}
{{- if .Values.extraVolumes }}
{{- include "common.tplvalues.render" ( dict "value" .Values.extraVolumes "context" $ ) | nindent 8 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/mapcache/templates/seed-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ spec:
emptyDir: {}
- name: rclone-config
secret:
secretName: {{ include "common.tplvalues.render" ( dict "value" .Values.rcloneConfigSecretName "context" $) }}
secretName: {{ include "common.tplvalues.render" ( dict "value" .Values.rcloneSecret "context" $) }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/mapcache/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ seedJob:

# localCacheSource: ""

# rcloneConfigSecretName: ""
# rcloneConfigSecret: ""

# configVolume is the specification for the volume where the config lies
configVolume: {}
Expand Down

0 comments on commit 03cee7a

Please sign in to comment.