generated from onedr0p/cluster-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRestoreTasks.yml
38 lines (36 loc) · 1.72 KB
/
RestoreTasks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
version: "3"
tasks:
volume:
desc: Create a job to restore a kopia snapshot (ex. task PVC=plex-config-v1 restore:volume)
interactive: true
cmds:
- 'echo "Namespace: {{.NAMESPACE}} | App: {{.APP}}"'
- flux -n {{.NAMESPACE}} suspend helmrelease {{.APP}}
- kubectl -n {{.NAMESPACE}} scale deployment {{.APP}} --replicas 0
- kubectl -n {{.NAMESPACE}} wait pod --for delete --selector="app.kubernetes.io/name={{.APP}}" --timeout=2m
- envsubst < <(cat ./hack/restore-job.yaml) | kubectl apply -f -
- kubectl -n {{.NAMESPACE}} wait job --for condition=complete {{.APP}}-{{.PVC}}-restore-snapshot --timeout=60m
- flux -n {{.NAMESPACE}} resume helmrelease {{.APP}}
- kubectl -n {{.NAMESPACE}} logs job {{.APP}}-{{.PVC}}-restore-snapshot
- kubectl -n {{.NAMESPACE}} delete job {{.APP}}-{{.PVC}}-restore-snapshot
vars:
NAMESPACE:
sh: kubectl get pvc -A | grep {{.PVC}} | awk '{print $1}'
APP:
sh: kubectl -n {{.NAMESPACE}} get pvc {{.PVC}} -o jsonpath='{.metadata.labels.app\.kubernetes\.io\/name}'
env:
PVC: "{{.PVC}}"
NAMESPACE:
sh: kubectl get pvc -A | grep {{.PVC}} | awk '{print $1}'
APP:
sh: kubectl -n {{.NAMESPACE}} get pvc {{.PVC}} -o jsonpath='{.metadata.labels.app\.kubernetes\.io\/name}'
KOPIA_PASSWORD:
sh: sops -d cluster/config/cluster-secrets.sops.yaml | grep SECRET_KOPIA_REPO_PASSWORD | awk '{print $2}'
preconditions:
- sh: kubectl -n {{.NAMESPACE}} get pvc {{.PVC}}
msg: "Error: pvc/{{.PVC}} in namespace/{{.NAMESPACE}} not found"
- sh: '[ ! "{{.SNAPSHOT}}" = "" ]'
msg: "SNAPSHOT is required"
- sh: '[ ! "{{.PVC}}" = "" ]'
msg: "PVC is required"