Skip to content
This repository was archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
Add openebs snapshot feature (#37)
Browse files Browse the repository at this point in the history
* Add OpenEBS Plugin for snapshot-controller and snapshot-provisioner
* Add e2e test for openebs-snapshot and creating a PV from snapshot
* Update README with snapshot clone/restore steps
* Add unit test for snapshot API requests.

Signed-off-by: prateekpandey14 <[email protected]>
  • Loading branch information
prateekpandey14 authored and kmova committed Jun 1, 2018
1 parent f95698c commit 68abdaf
Show file tree
Hide file tree
Showing 22 changed files with 1,557 additions and 13 deletions.
11 changes: 9 additions & 2 deletions openebs-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
DST_REPO="$GOPATH/src/github.com/kubernetes-incubator"
export DST_REPO

echo "Building openebs-provisioner"
export DIMAGE="openebs/openebs-k8s-provisioner"
cd $DST_REPO/external-storage/
make push-openebs-provisioner
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

$DST_REPO/external-storage/openebs/ci/travis-ci.sh
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "Building snapshot-controller and snapshot-provisioner"
cd $DST_REPO/external-storage/snapshot
export REGISTRY="openebs/"
export VERSION="ci"
make container

cd $DST_REPO/external-storage/
$DST_REPO/external-storage/openebs/ci/travis-ci.sh
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
6 changes: 6 additions & 0 deletions openebs-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export DIMAGE="openebs/openebs-k8s-provisioner"
cd $DST_REPO/external-storage/
make deploy-openebs-provisioner

echo "Pushing images to docker hub"
export DIMAGE="openebs/snapshot-controller"
./openebs/buildscripts/push
export DIMAGE="openebs/snapshot-provisioner"
./openebs/buildscripts/push




Expand Down
14 changes: 7 additions & 7 deletions openebs/ci/helm_install_openebs.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash

kubectl -n kube-system create sa tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
kubectl -n kube-system patch deploy/tiller-deploy -p '{"spec": {"template": {"spec": {"serviceAccountName": "tiller"}}}}'
kubectl -n kube-system create sa tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
kubectl -n kube-system patch deploy/tiller-deploy -p '{"spec": {"template": {"spec": {"serviceAccountName": "tiller"}}}}'

#Replace this with logic to wait till helm is initialized
sleep 30
kubectl get pods --all-namespaces
kubectl get pods --all-namespaces

helm repo add openebs-charts https://openebs.github.io/charts/
helm repo update
helm install openebs-charts/openebs --set apiserver.imageTag="0.5.2",apiserver.replicas="1",provisioner.imageTag="ci",provisioner.replicas="1",jiva.replicas="1",rbacEnable="false"
helm install openebs-charts/openebs --namespace default --set apiserver.imageTag="ci",apiserver.replicas="1",provisioner.imageTag="ci",provisioner.replicas="1",jiva.replicas="1"

#Replace this with logic to wait/verify openebs control plane is initialized
sleep 30
kubectl get pods --all-namespaces -o yaml
kubectl get svc --all-namespaces -o yaml
kubectl get pods --all-namespaces
kubectl get svc --all-namespaces
34 changes: 34 additions & 0 deletions openebs/ci/snapshot/busybox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: default
spec:
containers:
- command:
- sh
- -c
- 'date > /mnt/store1/date.txt; hostname >> /mnt/store1/hostname.txt; sync; sleep 5; sync; tail -f /dev/null;'
image: busybox
imagePullPolicy: Always
name: busybox
volumeMounts:
- mountPath: /mnt/store1
name: demo-vol1
volumes:
- name: demo-vol1
persistentVolumeClaim:
claimName: demo-vol1-claim
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: demo-vol1-claim
namespace: default
spec:
storageClassName: openebs-standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5G
21 changes: 21 additions & 0 deletions openebs/ci/snapshot/busybox_clone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox-clone
namespace: default
spec:
containers:
- command:
- sh
- -c
- 'tail -f /dev/null'
image: busybox
imagePullPolicy: Always
name: busybox
volumeMounts:
- mountPath: /mnt/store2
name: demo-snap-vol
volumes:
- name: demo-snap-vol
persistentVolumeClaim:
claimName: demo-snap-vol-claim
189 changes: 189 additions & 0 deletions openebs/ci/snapshot/openebs-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Define the Service Account
# Define the RBAC rules for the Service Account
# Launch the maya-apiserver ( deployment )
# Launch the maya-storagemanager ( deameon set )

# Create Maya Service Account
apiVersion: v1
kind: ServiceAccount
metadata:
name: openebs-maya-operator
namespace: default
---
# Define Role that allows operations on K8s pods/deployments
# in "default" namespace
# TODO : change to new namespace, for isolated data network
# TODO : the rules should be updated with required group/resources/verb
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: openebs-maya-operator
rules:
- apiGroups: ["*"]
resources: ["nodes","nodes/proxy"]
verbs: ["get","list","watch","create","update"]
- apiGroups: ["*"]
resources: ["namespaces","services","pods","deployments", "events", "endpoints"]
verbs: ["*"]
- apiGroups: ["*"]
resources: ["persistentvolumes","persistentvolumeclaims"]
verbs: ["*"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["*"]
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: [ "get", "list", "create" ]
- apiGroups: ["*"]
resources: ["storagepools"]
verbs: ["get", "list"]
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
---
# Bind the Service Account with the Role Privileges.
# TODO: Check if default account also needs to be there
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: openebs-maya-operator
namespace: default
subjects:
- kind: ServiceAccount
name: openebs-maya-operator
namespace: default
- kind: User
name: system:serviceaccount:default:default
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: openebs-maya-operator
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: maya-apiserver
namespace: default
spec:
replicas: 1
template:
metadata:
labels:
name: maya-apiserver
spec:
serviceAccountName: openebs-maya-operator
containers:
- name: maya-apiserver
imagePullPolicy: IfNotPresent
image: openebs/m-apiserver:ci
ports:
- containerPort: 5656
env:
- name: OPENEBS_IO_JIVA_CONTROLLER_IMAGE
value: "openebs/jiva:ci"
- name: OPENEBS_IO_JIVA_REPLICA_IMAGE
value: "openebs/jiva:ci"
- name: OPENEBS_IO_VOLUME_MONITOR_IMAGE
value: "openebs/m-exporter:ci"
- name: OPENEBS_IO_JIVA_REPLICA_COUNT
value: "1"
---
apiVersion: v1
kind: Service
metadata:
name: maya-apiserver-service
spec:
ports:
- name: api
port: 5656
protocol: TCP
targetPort: 5656
selector:
name: maya-apiserver
sessionAffinity: None
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: openebs-provisioner
namespace: default
spec:
replicas: 1
template:
metadata:
labels:
name: openebs-provisioner
spec:
serviceAccountName: openebs-maya-operator
containers:
- name: openebs-provisioner
imagePullPolicy: IfNotPresent
image: openebs/openebs-k8s-provisioner:ci
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: OPENEBS_MONITOR_URL
value: "http://127.0.0.1:32515/dashboard/db/openebs-volume-stats?orgId=1"
- name: OPENEBS_MONITOR_VOLKEY
value: "&var-OpenEBS"
- name: MAYA_PORTAL_URL
value: "https://mayaonline.io/"
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
# name must match the spec fields below, and be in the form: <plural>.<group>
name: storagepoolclaims.openebs.io
spec:
# group name to use for REST API: /apis/<group>/<version>
group: openebs.io
# version name to use for REST API: /apis/<group>/<version>
version: v1alpha1
# either Namespaced or Cluster
scope: Cluster
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
plural: storagepoolclaims
# singular name to be used as an alias on the CLI and for display
singular: storagepoolclaim
# kind is normally the CamelCased singular type. Your resource manifests use this.
kind: StoragePoolClaim
# shortNames allow shorter string to match your resource on the CLI
shortNames:
- spc
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
# name must match the spec fields below, and be in the form: <plural>.<group>
name: storagepools.openebs.io
spec:
# group name to use for REST API: /apis/<group>/<version>
group: openebs.io
# version name to use for REST API: /apis/<group>/<version>
version: v1alpha1
# either Namespaced or Cluster
scope: Cluster
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
plural: storagepools
# singular name to be used as an alias on the CLI and for display
singular: storagepool
# kind is normally the CamelCased singular type. Your resource manifests use this.
kind: StoragePool
# shortNames allow shorter string to match your resource on the CLI
shortNames:
- sp
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: openebs-standard
provisioner: openebs.io/provisioner-iscsi
parameters:
openebs.io/storage-pool: "default"
openebs.io/jiva-replica-count: "1"
openebs.io/capacity: 5G
82 changes: 82 additions & 0 deletions openebs/ci/snapshot/snapshot-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: snapshot-controller-runner
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: snapshot-controller-role
namespace: default
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "delete"]
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["list", "watch", "create", "update", "patch"]
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["create", "list", "watch", "delete"]
- apiGroups: ["volumesnapshot.external-storage.k8s.io"]
resources: ["volumesnapshots"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["volumesnapshot.external-storage.k8s.io"]
resources: ["volumesnapshotdatas"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: [""]
resources: ["services"]
verbs: ["get"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: snapshot-controller
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: snapshot-controller-role
subjects:
- kind: ServiceAccount
name: snapshot-controller-runner
namespace: default
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: snapshot-controller
namespace: default
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: snapshot-controller
spec:
serviceAccountName: snapshot-controller-runner
containers:
- name: snapshot-controller
image: openebs/snapshot-controller:ci
imagePullPolicy: "IfNotPresent"
- name: snapshot-provisioner
image: openebs/snapshot-provisioner:ci
imagePullPolicy: "IfNotPresent"
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: snapshot-promoter
provisioner: volumesnapshot.external-storage.k8s.io/snapshot-promoter
7 changes: 7 additions & 0 deletions openebs/ci/snapshot/snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: volumesnapshot.external-storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: snapshot-demo
namespace: default
spec:
persistentVolumeClaimName: demo-vol1-claim
Loading

0 comments on commit 68abdaf

Please sign in to comment.