From e4b778b465dbe1c3f8beda8622be9a226ad2b599 Mon Sep 17 00:00:00 2001 From: Jakob Edding <15202881+JakobEdding@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:18:27 +0200 Subject: [PATCH] Allow selecting the rclone command (#11) So far, the chart is restricted to [rclone copy](https://rclone.org/commands/rclone_copy). This PR allows the command to be set (e.g. to invoke [rclone copyurl](https://rclone.org/commands/rclone_copyurl)). `copy` is retained as the default command to avoid introducing a breaking change. --- charts/rclone-copy/templates/_helpers.tpl | 8 ++++++++ charts/rclone-copy/templates/rclone-cron.yaml | 11 +++++------ charts/rclone-copy/values.yaml | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/charts/rclone-copy/templates/_helpers.tpl b/charts/rclone-copy/templates/_helpers.tpl index 4028b9c..8d6393a 100644 --- a/charts/rclone-copy/templates/_helpers.tpl +++ b/charts/rclone-copy/templates/_helpers.tpl @@ -27,3 +27,11 @@ Create chart name and version as used by the chart label. {{- define "rclone-copy.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} + +{{- define "rclone-copy.getSourceOrUrl" -}} +{{- if .Values.sync.url -}} +{{ .Values.sync.url -}} +{{- else -}} +{{ .Values.sync.source.name }}:{{ .Values.sync.source.path -}} +{{- end -}} +{{- end -}} diff --git a/charts/rclone-copy/templates/rclone-cron.yaml b/charts/rclone-copy/templates/rclone-cron.yaml index e429e86..f546594 100644 --- a/charts/rclone-copy/templates/rclone-cron.yaml +++ b/charts/rclone-copy/templates/rclone-cron.yaml @@ -58,7 +58,7 @@ spec: - name: rclone-container image: rclone/rclone:{{ .Values.imageRelease }} imagePullPolicy: {{ .Values.imagePullPolicy | quote }} - + command: - /bin/sh args: @@ -66,8 +66,8 @@ spec: # copy as workaround for rclone.conf read only (see https://github.com/rclone/rclone/issues/3655) - >- cp /root/.config/rclone/rclone_ro.conf /root/.config/rclone/rclone.conf && - rclone copy -v {{ .Values.arguments | join " " }} --include-from /root/include-pattern.conf "{{ .Values.sync.source.name }}:{{ .Values.sync.source.path }}" "{{ .Values.sync.dest.name }}:{{ .Values.sync.dest.path }}" - + rclone {{ .Values.command }} -v {{ .Values.arguments | join " " }} --include-from /root/include-pattern.conf "{{ include "rclone-copy.getSourceOrUrl" . }}" "{{ .Values.sync.dest.name }}:{{ .Values.sync.dest.path }}" + volumeMounts: - name: config # This is the default path where the rclone implementation assumes the config is located @@ -76,7 +76,7 @@ spec: - name: include-config mountPath: "/root/include-pattern.conf" subPath: "include-pattern.conf" - + resources: {{ toYaml .Values.resources | indent 14 }} @@ -97,7 +97,7 @@ spec: key: "{{ $value.key }}" {{- end }} {{- end }} - + restartPolicy: {{ .Values.restartPolicy }} volumes: - name: config @@ -107,4 +107,3 @@ spec: configMap: name: rclone-config-{{ .Release.Name }} backoffLimit: {{ .Values.backoffLimit }} - diff --git a/charts/rclone-copy/values.yaml b/charts/rclone-copy/values.yaml index 2804680..aeb4ff3 100644 --- a/charts/rclone-copy/values.yaml +++ b/charts/rclone-copy/values.yaml @@ -1,9 +1,12 @@ nameOverride: bakdata-rclone-copy +# The rclone command to run. Default is "copy". +command: "copy" + # This is the cofiguration for the specific rclone-cronjob that you want to run. # `sync` contains the config for the source and destination of the rclone copy job. # It can be interpreted as: -# rclone copy {source.name}:{source.path} {dest.name}:{dest.path} +# rclone {command} {sync.source.name}:{sync.source.path} {sync.dest.name}:{sync.dest.path} sync: source: # This is the name for the source remote from the rclone.conf file. @@ -14,6 +17,9 @@ sync: # This is the path to the source directory. path: /tmp/sync-dir + # Alternatively for the case of `rclone copyurl`, provide a URL instead of a source + url: "" + dest: # This is the name for the destination remote from the rclone.conf file. # If the value specified here is not present in the config file, the job will fail.