Skip to content

Commit

Permalink
VolumeSnapshot (#787)
Browse files Browse the repository at this point in the history
Tasks:
- [x] Create VolumeSnapshot
- [x] Restore VolumeSnapshot
  • Loading branch information
suaas21 authored and tamalsaha committed May 23, 2019
1 parent a8f3172 commit ac829f3
Show file tree
Hide file tree
Showing 53 changed files with 3,208 additions and 132 deletions.
5 changes: 5 additions & 0 deletions api/crds/v1beta1/backupconfiguration.yaml
Expand Up @@ -1960,6 +1960,11 @@ spec:
name:
type: string
type: object
replicas:
description: replicas are the desired number of replicas whose data
should be backed up. If unspecified, defaults to 1.
format: int32
type: integer
snapshotClassName:
description: Name of the VolumeSnapshotClass used by the VolumeSnapshot.
If not specified, a default snapshot class will be used if it
Expand Down
7 changes: 7 additions & 0 deletions apis/stash/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/stash/v1beta1/restore_session_types.go
Expand Up @@ -92,6 +92,7 @@ type HostRestorePhase string
const (
HostRestoreSucceeded HostRestorePhase = "Succeeded"
HostRestoreFailed HostRestorePhase = "Failed"
HostRestoreUnknown HostRestorePhase = "Unknown"
)

type RestoreSessionStatus struct {
Expand Down
4 changes: 4 additions & 0 deletions apis/stash/v1beta1/types.go
Expand Up @@ -26,6 +26,10 @@ type BackupTarget struct {
// Specify the volumes that contains the target directories
// +optional
VolumeMounts []core.VolumeMount `json:"volumeMounts,omitempty"`
//replicas are the desired number of replicas whose data should be backed up.
// If unspecified, defaults to 1.
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// Name of the VolumeSnapshotClass used by the VolumeSnapshot. If not specified, a default snapshot class will be used if it is available.
// Use this field only if the "driver" field is set to "volumeSnapshotter".
// +optional
Expand Down
5 changes: 5 additions & 0 deletions apis/stash/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions chart/stash/templates/cluster-role.yaml
Expand Up @@ -113,3 +113,10 @@ rules:
{{- range $x := .Values.additionalPodSecurityPolicies }}
- {{ $x }}
{{- end }}
- apiGroups:
- snapshot.storage.k8s.io
resources:
- volumesnapshots
- volumesnapshotcontents
- volumesnapshotclasses
verbs: ["create", "get", "list", "watch", "patch"]
11 changes: 4 additions & 7 deletions docs/examples/volume-snapshot/backupconfiguration.yaml
Expand Up @@ -5,16 +5,13 @@ metadata:
namespace: demo
spec:
schedule: "* * * * *"
driver: volumeSnapshotter
snapshotClassName: myVolumeSnapshotClassName
driver: VolumeSnapshotter
target:
ref:
apiVersion: apps/v1
kind: Deployment
name: stash-demo
pvcNames:
- my-first-pvc
- my-second-pvc
kind: StatefulSet
name: web
snapshotClassName: default-snapshot-class
retentionPolicy:
name: 'keep-last-5'
keepLast: 5
Expand Down
44 changes: 44 additions & 0 deletions docs/examples/volume-snapshot/daemon.yaml
@@ -0,0 +1,44 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: backup-pvc
namespace: demo
spec:
storageClassName: "standard"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 6Gi
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app: demo
name: stash-demo
namespace: demo
spec:
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
name: stash-demo
spec:
containers:
- args: ["touch source/data/sample-file.txt && sleep 3000"]
command: ["/bin/sh", "-c"]
image: busybox
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
- mountPath: /source/data
name: source-data
restartPolicy: Always
volumes:
- name: source-data
persistentVolumeClaim:
claimName: backup-pvc
45 changes: 45 additions & 0 deletions docs/examples/volume-snapshot/deployment.yaml
@@ -0,0 +1,45 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: backup-pvc
namespace: demo
spec:
accessModes:
- ReadWriteOnce
storageClassName: "standard"
resources:
requests:
storage: 6Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: stash-demo
name: stash-demo
namespace: demo
spec:
replicas: 1
selector:
matchLabels:
app: stash-demo
template:
metadata:
labels:
app: stash-demo
name: busybox
spec:
containers:
- args: ["touch source/data/sample-file.txt && sleep 3000"]
command: ["/bin/sh", "-c"]
image: busybox
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
- mountPath: /source/data
name: source-data
restartPolicy: Always
volumes:
- name: source-data
persistentVolumeClaim:
claimName: backup-pvc
12 changes: 12 additions & 0 deletions docs/examples/volume-snapshot/pvc.yaml
@@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: backup-pvc
namespace: demo
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
storage: 6Gi
44 changes: 18 additions & 26 deletions docs/examples/volume-snapshot/restoresession.yaml
@@ -1,31 +1,23 @@
apiVersion: stash.appscode.com/v1beta1
kind: RestoreSession
metadata:
name: demo-restore-from-volumesnapshot
name: restore
namespace: demo
spec:
volumeClaimTemplates:
- metadata:
name: my-first-pvc-restored
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "standard"
resources:
requests:
storage: 1Gi
dataSource:
kind: VolumeSnapshot
name: my-first-pvc-snapshot
apiGroup: snapshot.storage.k8s.io
- metadata:
name: my-second-pvc-restored
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "standard"
resources:
requests:
storage: 1Gi
dataSource:
kind: VolumeSnapshot
name: my-second-pvc-snapshot
apiGroup: snapshot.storage.k8s.io
driver: VolumeSnapshotter
target:
# replicas : 3 #for Statefulset
volumeClaimTemplates:
- metadata:
name: pvc
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "standard"
resources:
requests:
storage: 6Gi
dataSource:
kind: VolumeSnapshot
# name: ${CLAIM_NAME}-${POD_ORDINAL}-1558421829 #for Statefulset
name: ${CLAIM_NAME}-1558421829
apiGroup: snapshot.storage.k8s.io
53 changes: 53 additions & 0 deletions docs/examples/volume-snapshot/statefulset.yaml
@@ -0,0 +1,53 @@
apiVersion: v1
kind: Service
metadata:
name: svc
labels:
app: demo
namespace: demo
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: stash
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: stash-demo
namespace: demo
spec:
selector:
matchLabels:
app: demo
serviceName: svc
replicas: 3
template:
metadata:
labels:
app: demo # Pod template's label selector
spec:
containers:
- args: ["touch source/data/sample-file.txt && sleep 3000"]
command: ["/bin/sh", "-c"]
name: nginx
image: nginx
ports:
- containerPort: 80
name: web
volumeMounts:
- name: source-data
mountPath: /source/data
volumeClaimTemplates:
- metadata:
name: source-data
namespace: demo
spec:
accessModes:
- ReadWriteOnce
storageClassName: "standard"
resources:
requests:
storage: 6Gi
10 changes: 10 additions & 0 deletions docs/examples/volume-snapshot/storageclass.yaml
@@ -0,0 +1,10 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard
parameters:
type: pd-standard
provisioner: pd.csi.storage.gke.io
reclaimPolicy: Delete
volumeBindingMode: Immediate

23 changes: 23 additions & 0 deletions docs/examples/volume-snapshot/vs.yaml
@@ -0,0 +1,23 @@
apiVersion: snapshot.storage.k8s.io/v1alpha1
kind: VolumeSnapshot
metadata:
creationTimestamp: "2019-05-16t06-06-11z"
finalizers:
- snapshot.storage.kubernetes.io/volumesnapshot-protection
generation: 4
name: pvc-1558421829
namespace: demo
resourceVersion: "963212"
selfLink: /apis/snapshot.storage.k8s.io/v1alpha1/namespaces/demo/volumesnapshots/pvc-2019-05-16t06-06-09-stash
uid: b47259fe-77a0-11e9-91dc-42010a80001a
spec:
snapshotClassName: default-snapshot-class
snapshotContentName: snapcontent-b47259fe-77a0-11e9-91dc-42010a80001a
source:
apiGroup: null
kind: PersistentVolumeClaim
name: pvc
status:
creationTime: "2019-05-16T06:06:12Z"
readyToUse: true
restoreSize: 6Gi
2 changes: 2 additions & 0 deletions docs/reference/stash.md
Expand Up @@ -53,6 +53,7 @@ Stash is a Kubernetes operator for restic. For more information, visit here: htt
* [stash check](/docs/reference/stash_check.md) - Check restic backup
* [stash cli](/docs/reference/stash_cli.md) - Stash CLI
* [stash create-backupsession](/docs/reference/stash_create-backupsession.md) - create a BackupSession
* [stash create-vs](/docs/reference/stash_create-vs.md) - Take snapshot of PersistentVolumeClaims
* [stash docker](/docs/reference/stash_docker.md) - Run restic commands inside Docker
* [stash forget](/docs/reference/stash_forget.md) - Delete snapshots from a restic repository
* [stash recover](/docs/reference/stash_recover.md) - Recover restic backup
Expand All @@ -62,6 +63,7 @@ Stash is a Kubernetes operator for restic. For more information, visit here: htt
* [stash restore-mysql](/docs/reference/stash_restore-mysql.md) - Restores MySQL DB Backup
* [stash restore-pg](/docs/reference/stash_restore-pg.md) - Restores Postgres DB Backup
* [stash restore-pvc](/docs/reference/stash_restore-pvc.md) - Takes a restore of Persistent Volume Claim
* [stash restore-vs](/docs/reference/stash_restore-vs.md) - Restore PVC from VolumeSnapshot
* [stash run](/docs/reference/stash_run.md) - Launch Stash Controller
* [stash run-backup](/docs/reference/stash_run-backup.md) - Take backup of workload directories
* [stash scaledown](/docs/reference/stash_scaledown.md) - Scale down workload
Expand Down

0 comments on commit ac829f3

Please sign in to comment.