From 25d3597c9a03e522dc0ccfef6ae684216eb6a9b8 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Wed, 20 Jun 2018 11:46:45 -0700 Subject: [PATCH] add a /scratch emptyDir to ark pods to use for restic cache Signed-off-by: Steve Kriss --- examples/aws/10-deployment.yaml | 6 ++++++ examples/aws/20-restic-daemonset.yaml | 8 +++++++- examples/azure/00-ark-deployment.yaml | 7 +++++++ examples/azure/20-restic-daemonset.yaml | 7 ++++++- examples/gcp/10-deployment.yaml | 6 ++++++ examples/gcp/20-restic-daemonset.yaml | 8 +++++++- examples/ibm/10-deployment.yaml | 6 ++++++ examples/minio/20-ark-deployment.yaml | 6 ++++++ examples/minio/30-restic-daemonset.yaml | 8 +++++++- pkg/restic/command.go | 14 ++++++++++++++ 10 files changed, 72 insertions(+), 4 deletions(-) diff --git a/examples/aws/10-deployment.yaml b/examples/aws/10-deployment.yaml index e824c24c9..1742c4713 100644 --- a/examples/aws/10-deployment.yaml +++ b/examples/aws/10-deployment.yaml @@ -43,12 +43,18 @@ spec: mountPath: /credentials - name: plugins mountPath: /plugins + - name: scratch + mountPath: /scratch env: - name: AWS_SHARED_CREDENTIALS_FILE value: /credentials/cloud + - name: ARK_SCRATCH_DIR + value: /scratch volumes: - name: cloud-credentials secret: secretName: cloud-credentials - name: plugins emptyDir: {} + - name: scratch + emptyDir: {} \ No newline at end of file diff --git a/examples/aws/20-restic-daemonset.yaml b/examples/aws/20-restic-daemonset.yaml index d180a1bdb..01ff91b74 100644 --- a/examples/aws/20-restic-daemonset.yaml +++ b/examples/aws/20-restic-daemonset.yaml @@ -36,6 +36,8 @@ spec: - name: host-pods hostPath: path: /var/lib/kubelet/pods + - name: scratch + emptyDir: {} containers: - name: ark image: gcr.io/heptio-images/ark:latest @@ -49,6 +51,8 @@ spec: mountPath: /credentials - name: host-pods mountPath: /host_pods + - name: scratch + mountPath: /scratch env: - name: NODE_NAME valueFrom: @@ -59,4 +63,6 @@ spec: fieldRef: fieldPath: metadata.namespace - name: AWS_SHARED_CREDENTIALS_FILE - value: /credentials/cloud \ No newline at end of file + value: /credentials/cloud + - name: ARK_SCRATCH_DIR + value: /scratch \ No newline at end of file diff --git a/examples/azure/00-ark-deployment.yaml b/examples/azure/00-ark-deployment.yaml index 614f0a37a..93f1944a8 100644 --- a/examples/azure/00-ark-deployment.yaml +++ b/examples/azure/00-ark-deployment.yaml @@ -44,11 +44,18 @@ spec: envFrom: - secretRef: name: cloud-credentials + env: + - name: ARK_SCRATCH_DIR + value: /scratch volumeMounts: - name: plugins mountPath: /plugins + - name: scratch + mountPath: /scratch volumes: - name: plugins emptyDir: {} + - name: scratch + emptyDir: {} nodeSelector: beta.kubernetes.io/os: linux diff --git a/examples/azure/20-restic-daemonset.yaml b/examples/azure/20-restic-daemonset.yaml index 885242a91..356d33a8f 100644 --- a/examples/azure/20-restic-daemonset.yaml +++ b/examples/azure/20-restic-daemonset.yaml @@ -33,6 +33,8 @@ spec: - name: host-pods hostPath: path: /var/lib/kubelet/pods + - name: scratch + emptyDir: {} containers: - name: ark image: gcr.io/heptio-images/ark:latest @@ -44,6 +46,8 @@ spec: volumeMounts: - name: host-pods mountPath: /host_pods + - name: scratch + mountPath: /scratch envFrom: - secretRef: name: cloud-credentials @@ -66,4 +70,5 @@ spec: secretKeyRef: name: cloud-credentials key: AZURE_STORAGE_KEY - \ No newline at end of file + - name: ARK_SCRATCH_DIR + value: /scratch \ No newline at end of file diff --git a/examples/gcp/10-deployment.yaml b/examples/gcp/10-deployment.yaml index 312bfe82c..98db63486 100644 --- a/examples/gcp/10-deployment.yaml +++ b/examples/gcp/10-deployment.yaml @@ -46,12 +46,18 @@ spec: mountPath: /credentials - name: plugins mountPath: /plugins + - name: scratch + mountPath: /scratch env: - name: GOOGLE_APPLICATION_CREDENTIALS value: /credentials/cloud + - name: ARK_SCRATCH_DIR + value: /scratch volumes: - name: cloud-credentials secret: secretName: cloud-credentials - name: plugins emptyDir: {} + - name: scratch + emptyDir: {} diff --git a/examples/gcp/20-restic-daemonset.yaml b/examples/gcp/20-restic-daemonset.yaml index c88e803b8..8c63c9094 100644 --- a/examples/gcp/20-restic-daemonset.yaml +++ b/examples/gcp/20-restic-daemonset.yaml @@ -36,6 +36,8 @@ spec: - name: host-pods hostPath: path: /var/lib/kubelet/pods + - name: scratch + emptyDir: {} containers: - name: ark image: gcr.io/heptio-images/ark:latest @@ -49,6 +51,8 @@ spec: mountPath: /credentials - name: host-pods mountPath: /host_pods + - name: scratch + mountPath: /scratch env: - name: NODE_NAME valueFrom: @@ -59,4 +63,6 @@ spec: fieldRef: fieldPath: metadata.namespace - name: GOOGLE_APPLICATION_CREDENTIALS - value: /credentials/cloud \ No newline at end of file + value: /credentials/cloud + - name: ARK_SCRATCH_DIR + value: /scratch \ No newline at end of file diff --git a/examples/ibm/10-deployment.yaml b/examples/ibm/10-deployment.yaml index fc3895dcc..8d54af35b 100644 --- a/examples/ibm/10-deployment.yaml +++ b/examples/ibm/10-deployment.yaml @@ -46,12 +46,18 @@ spec: mountPath: /credentials - name: plugins mountPath: /plugins + - name: scratch + mountPath: /scratch env: - name: AWS_SHARED_CREDENTIALS_FILE value: /credentials/cloud + - name: ARK_SCRATCH_DIR + value: /scratch volumes: - name: cloud-credentials secret: secretName: cloud-credentials - name: plugins emptyDir: {} + - name: scratch + emptyDir: {} diff --git a/examples/minio/20-ark-deployment.yaml b/examples/minio/20-ark-deployment.yaml index 3b1984575..33a16f7e4 100644 --- a/examples/minio/20-ark-deployment.yaml +++ b/examples/minio/20-ark-deployment.yaml @@ -46,12 +46,18 @@ spec: mountPath: /credentials - name: plugins mountPath: /plugins + - name: scratch + mountPath: /scratch env: - name: AWS_SHARED_CREDENTIALS_FILE value: /credentials/cloud + - name: ARK_SCRATCH_DIR + value: /scratch volumes: - name: cloud-credentials secret: secretName: cloud-credentials - name: plugins emptyDir: {} + - name: scratch + emptyDir: {} diff --git a/examples/minio/30-restic-daemonset.yaml b/examples/minio/30-restic-daemonset.yaml index b4275890c..ca44967b5 100644 --- a/examples/minio/30-restic-daemonset.yaml +++ b/examples/minio/30-restic-daemonset.yaml @@ -36,6 +36,8 @@ spec: - name: host-pods hostPath: path: /var/lib/kubelet/pods + - name: scratch + emptyDir: {} containers: - name: ark image: gcr.io/heptio-images/ark:latest @@ -49,6 +51,8 @@ spec: mountPath: /credentials - name: host-pods mountPath: /host_pods + - name: scratch + mountPath: /scratch env: - name: NODE_NAME valueFrom: @@ -59,4 +63,6 @@ spec: fieldRef: fieldPath: metadata.namespace - name: AWS_SHARED_CREDENTIALS_FILE - value: /credentials/cloud \ No newline at end of file + value: /credentials/cloud + - name: ARK_SCRATCH_DIR + value: /scratch \ No newline at end of file diff --git a/pkg/restic/command.go b/pkg/restic/command.go index 782829655..705854ece 100644 --- a/pkg/restic/command.go +++ b/pkg/restic/command.go @@ -18,7 +18,9 @@ package restic import ( "fmt" + "os" "os/exec" + "path/filepath" "strings" ) @@ -48,6 +50,14 @@ func (c *Command) StringSlice() []string { if c.PasswordFile != "" { res = append(res, passwordFlag(c.PasswordFile)) } + + // If ARK_SCRATCH_DIR is defined, put the restic cache within it. If not, + // allow restic to choose the location. This makes running either in-cluster + // or local (dev) work properly. + if scratch := os.Getenv("ARK_SCRATCH_DIR"); scratch != "" { + res = append(res, cacheDirFlag(filepath.Join(scratch, ".cache", "restic"))) + } + res = append(res, c.Args...) res = append(res, c.ExtraFlags...) @@ -75,3 +85,7 @@ func repoFlag(repoIdentifier string) string { func passwordFlag(file string) string { return fmt.Sprintf("--password-file=%s", file) } + +func cacheDirFlag(dir string) string { + return fmt.Sprintf("--cache-dir=%s", dir) +}