Skip to content

Commit

Permalink
Post backup/restore status update (#691)
Browse files Browse the repository at this point in the history
* Post backup/restore status update
* Add status package
* Handle backup/restore error
* Fail pod for back/restore error
  • Loading branch information
Dipta Das authored and tamalsaha committed Mar 21, 2019
1 parent ef3ca6b commit 30e1722
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 530 deletions.
7 changes: 7 additions & 0 deletions apis/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package apis

const (
Namespace = "NAMESPACE"
BackupSession = "BACKUP_SESSION"
RestoreSession = "RESTORE_SESSION"

RepositoryName = "REPOSITORY_NAME"
RepositoryProvider = "REPOSITORY_PROVIDER"
RepositorySecretName = "REPOSITORY_SECRET_NAME"
RepositoryBucket = "REPOSITORY_BUCKET"
Expand All @@ -25,4 +30,6 @@ const (
RetentionKeepTags = "RETENTION_KEEP_TAGS"
RetentionPrune = "RETENTION_PRUNE"
RetentionDryRun = "RETENTION_DRY_RUN"

StatusSubresourceEnabled = "ENABLE_STATUS_SUBRESOURCE"
)
35 changes: 35 additions & 0 deletions docs/examples/pvc/backup-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfiguration
metadata:
name: pvc-backup-config
namespace: demo
spec:
runtimeSettings:
pod:
serviceAccountName: pvc-backup-restore
task:
name: pvc-backup-task
repository:
name: hello-repo
schedule: "0 * * * *"
target:
ref:
apiVersion: v1
kind: PersistentVolumeClaim
name: test-pvc-source
mountPath: /etc/target
directories:
- /unknown-path/target/dir-01
- /unknown-path/target/dir-02
retentionPolicy:
keepLast: 5
prune: true
---
apiVersion: stash.appscode.com/v1beta1
kind: BackupSession
metadata:
name: pvc-backup-02
namespace: demo
spec:
backupConfiguration:
name: pvc-backup-config
3 changes: 3 additions & 0 deletions docs/examples/pvc/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ metadata:
name: pvc-backup-config
namespace: demo
spec:
runtimeSettings:
pod:
serviceAccountName: pvc-backup-restore
task:
name: pvc-backup-task
repository:
Expand Down
60 changes: 40 additions & 20 deletions docs/examples/pvc/functions.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: update-status
spec:
image: diptadas/stash:status
args:
- update-status
- --namespace=${NAMESPACE="default"}
- --repository=${REPOSITORY_NAME:=}
- --backup-session=${BACKUP_SESSION:=}
- --restore-session=${RESTORE_SESSION:=}
- --output-dir=${outputDir}
- --enable-status-subresource=${ENABLE_STATUS_SUBRESOURCE:=false}
volumeMounts:
- name: ${outputVolume}
mountPath: ${outputDir}
---
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: pvc-backup
spec:
image: diptadas/stash:pvc
image: diptadas/stash:status
args:
- backup-pvc
- --provider=${REPOSITORY_PROVIDER}
- --bucket=${REPOSITORY_BUCKET=""}
- --endpoint=${REPOSITORY_ENDPOINT=""}
- --path=${REPOSITORY_PREFIX=""}
- --bucket=${REPOSITORY_BUCKET:=}
- --endpoint=${REPOSITORY_ENDPOINT:=}
- --path=${REPOSITORY_PREFIX:=}
- --secret-dir=/etc/repository/secret # specified
- --scratch-dir=/tmp/restic/scratch # specified
- --enable-cache=false # specified
- --hostname=${HOSTNAME}
- --backup-dirs=${TARGET_DIRECTORIES}
- --retention-keep-last=${RETENTION_KEEP_LAST=0}
- --retention-keep-hourly=${RETENTION_KEEP_HOURLY=0}
- --retention-keep-daily=${RETENTION_KEEP_DAILY=0}
- --retention-keep-weekly=${RETENTION_KEEP_WEEKLY=0}
- --retention-keep-monthly=${RETENTION_KEEP_MONTHLY=0}
- --retention-keep-yearly=${RETENTION_KEEP_YEARLY=0}
- --retention-keep-tags=${RETENTION_KEEP_TAGS=""}
- --retention-prune=${RETENTION_PRUNE=false}
- --retention-dry-run=${RETENTION_DRY_RUN=false}
- --retention-keep-last=${RETENTION_KEEP_LAST:=0}
- --retention-keep-hourly=${RETENTION_KEEP_HOURLY:=0}
- --retention-keep-daily=${RETENTION_KEEP_DAILY:=0}
- --retention-keep-weekly=${RETENTION_KEEP_WEEKLY:=0}
- --retention-keep-monthly=${RETENTION_KEEP_MONTHLY:=0}
- --retention-keep-yearly=${RETENTION_KEEP_YEARLY:=0}
- --retention-keep-tags=${RETENTION_KEEP_TAGS:=}
- --retention-prune=${RETENTION_PRUNE:=false}
- --retention-dry-run=${RETENTION_DRY_RUN:=false}
- --output-dir=${outputDir}
#- --metrics-enabled
#- --metrics-pushgateway-url
Expand All @@ -36,25 +53,26 @@ spec:
mountPath: ${TARGET_MOUNT_PATH}
- name: ${secretVolume}
mountPath: /etc/repository/secret
- name: ${outputVolume}
mountPath: ${outputDir}
---
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: pvc-restore
spec:
image: diptadas/stash:pvc
image: diptadas/stash:status
args:
- restore-pvc
- --provider=${REPOSITORY_PROVIDER}
- --bucket=${REPOSITORY_BUCKET=""}
- --endpoint=${REPOSITORY_ENDPOINT=""}
- --path=${REPOSITORY_PREFIX=""}
- --bucket=${REPOSITORY_BUCKET:=}
- --endpoint=${REPOSITORY_ENDPOINT:=}
- --path=${REPOSITORY_PREFIX:=}
- --secret-dir=/etc/repository/secret # specified
- --scratch-dir=/tmp/restic/scratch # specified
- --enable-cache=false # specified
- --hostname=${HOSTNAME}
- --restore-dirs=${RESTORE_DIRECTORIES}
- --snapshots=${RESTORE_SNAPSHOTS=""}
- --snapshots=${RESTORE_SNAPSHOTS:=}
- --output-dir=${outputDir}
#- --metrics-enabled
#- --metrics-pushgateway-url
Expand All @@ -67,3 +85,5 @@ spec:
mountPath: ${TARGET_MOUNT_PATH}
- name: ${secretVolume}
mountPath: /etc/repository/secret
- name: ${outputVolume}
mountPath: ${outputDir}
41 changes: 41 additions & 0 deletions docs/examples/pvc/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: update-status-roles
labels:
app: stash
rules:
- apiGroups:
- stash.appscode.com
resources:
- "*"
verbs: ["*"]
- apiGroups:
- ""
resources:
- "events"
verbs: ["create"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: pvc-backup-restore
namespace: demo
labels:
app: stash
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: update-status-binding
namespace: demo
labels:
app: stash
roleRef:
kind: ClusterRole
apiGroup: rbac.authorization.k8s.io
name: update-status-roles
subjects:
- kind: ServiceAccount
name: pvc-backup-restore
namespace: demo
24 changes: 24 additions & 0 deletions docs/examples/pvc/restore-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: stash.appscode.com/v1beta1
kind: RestoreSession
metadata:
name: pvc-restore-02
namespace: demo
spec:
runtimeSettings:
pod:
serviceAccountName: pvc-backup-restore
task:
name: pvc-restore-task
repository:
name: hello-repo
target:
ref:
apiVersion: v1
kind: PersistentVolumeClaim
name: test-pvc-dest
mountPath: /etc/target
rules:
- hosts:
- demo-host
paths:
- /etc/target/unknown-path
3 changes: 3 additions & 0 deletions docs/examples/pvc/restore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ metadata:
name: pvc-restore-01
namespace: demo
spec:
runtimeSettings:
pod:
serviceAccountName: pvc-backup-restore
task:
name: pvc-restore-task
repository:
Expand Down
22 changes: 21 additions & 1 deletion docs/examples/pvc/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ spec:
value: target-volume # specified
- name: secretVolume
value: secret-volume # specified
- name: outputVolume
value: output-volume # specified
- name: update-status
params:
- name: outputDir
value: /etc/backup # specified
- name: outputVolume
value: output-volume # specified
volumes:
- name: target-volume
persistentVolumeClaim:
Expand All @@ -23,6 +31,8 @@ spec:
secretName: ${REPOSITORY_SECRET_NAME}
- name: scratch-volume
emptyDir: {}
- name: output-volume
emptyDir: {}
---
apiVersion: stash.appscode.com/v1beta1
kind: Task
Expand All @@ -40,6 +50,14 @@ spec:
value: target-volume # specified
- name: secretVolume
value: secret-volume # specified
- name: outputVolume
value: output-volume # specified
- name: update-status
params:
- name: outputDir
value: /etc/backup # specified
- name: outputVolume
value: output-volume # specified
volumes:
- name: target-volume
persistentVolumeClaim:
Expand All @@ -48,4 +66,6 @@ spec:
secret:
secretName: ${REPOSITORY_SECRET_NAME}
- name: scratch-volume
emptyDir: {}
emptyDir: {}
- name: output-volume
emptyDir: {}
Loading

0 comments on commit 30e1722

Please sign in to comment.