Skip to content

Commit

Permalink
travis(ci): adding ci for velero-plugin (#40)
Browse files Browse the repository at this point in the history
Signed-off-by: mayank <[email protected]>
  • Loading branch information
mynktl authored and vishnuitta committed Sep 24, 2019
1 parent 71e64c7 commit e59b9c1
Show file tree
Hide file tree
Showing 757 changed files with 242,415 additions and 2,605 deletions.
27 changes: 26 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sudo: required
dist: trusty
dist: xenial
services:
- docker
language: go
Expand All @@ -13,10 +13,35 @@ addons:
install:
- make bootstrap
- make format
before_script:
# Install kubectl binary
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Install minikube
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.35.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
# Initialize minukube and kubernetes config directory
- mkdir -p $HOME/.kube $HOME/.minikube
# Start minukube server
- sudo minikube start --vm-driver=none --kubernetes-version=v1.13.0
- sudo chown -R $USER $HOME/.kube $HOME/.minikube
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done
script:
- make check
- make all-ci
- make container
- kubectl cluster-info
- |
if [ -z $TRAVIS_BRANCH ] || [ $TRAVIS_BRANCH == "master" ]; then
export VELERO_RELEASE=v1.0.0
export OPENEBS_RELEASE="1.1.0"
else
vR=`echo $TRAVIS_BRANCH |awk -F 'velero_' '{print $2}'`
export VELERO_RELEASE=v${vR}
oR=`echo $TRAVIS_BRANCH |awk -F '-' '{print $1}'`
export OPENEBS_RELEASE=${oR}
fi
- ./script/install-openebs.sh
- ./script/install-velero.sh
- travis_wait make test
after_success:
- make deploy-image
notifications:
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ BUILD_IMAGE ?= gcr.io/heptio-images/golang:1.9-alpine3.6
# list only velero-plugin source code directories
PACKAGES = $(shell go list ./... | grep -v 'vendor')


IMAGE ?= openebs/velero-plugin

ifeq (${IMAGE_TAG}, )
Expand Down Expand Up @@ -88,11 +87,7 @@ bootstrap:
done

vet:
go vet \
./velero-blockstore-cstor \
./pkg/clouduploader \
./pkg/cstor \
./pkg/snapshot
go vet ${PACKAGES}

# Target to run gometalinter in Travis (deadcode, golint, errcheck, unconvert, goconst)
golint-travis:
Expand All @@ -105,6 +100,9 @@ golint:

check: golint-travis format vet

test:
CGO_ENABLED=0 go test -v ${PACKAGES} -timeout 20m

deploy-image:
@DIMAGE=${IMAGE} ./push

Expand Down
73 changes: 73 additions & 0 deletions script/install-openebs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

# Copyright 2019 The OpenEBS Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [ -z $VELERO_RELEASE ] || [ -z $OPENEBS_RELEASE ]; then
exit
fi

echo "Installing iscsi packages"
sudo apt-get install --yes -qq open-iscsi
sudo service iscsid start
sudo systemctl status iscsid --no-pager
echo "Installation complete"

#TODO add openebs release
kubectl apply -f https://raw.githubusercontent.com/openebs/openebs/master/k8s/openebs-operator.yaml

function waitForDeployment() {
DEPLOY=$1
NS=$2
CREATE=true

if [ $# -eq 3 ] && ! $3 ; then
CREATE=false
fi

for i in $(seq 1 50) ; do
kubectl get deployment -n ${NS} ${DEPLOY}
kstat=$?
if [ $kstat -ne 0 ] && ! $CREATE ; then
return
elif [ $kstat -eq 0 ] && ! $CREATE; then
sleep 3
continue
fi

replicas=$(kubectl get deployment -n ${NS} ${DEPLOY} -o json | jq ".status.readyReplicas")
if [ "$replicas" == "1" ]; then
break
else
echo "Waiting for ${DEPLOY} to be ready"
if [ ${DEPLOY} != "maya-apiserver" ] && [ ${DEPLOY} != "openebs-provisioner" ]; then
dumpMayaAPIServerLogs 10
fi
sleep 10
fi
done
}

function dumpMayaAPIServerLogs() {
LC=$1
MAPIPOD=$(kubectl get pods -o jsonpath='{.items[?(@.spec.containers[0].name=="maya-apiserver")].metadata.name}' -n openebs)
kubectl logs --tail=${LC} $MAPIPOD -n openebs
printf "\n\n"
}

waitForDeployment maya-apiserver openebs
waitForDeployment openebs-provisioner openebs
waitForDeployment openebs-ndm-operator openebs

kubectl get pods --all-namespaces
110 changes: 110 additions & 0 deletions script/install-velero.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

# Copyright 2019 The OpenEBS Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [ -z $VELERO_RELEASE ] || [ -z $OPENEBS_RELEASE ]; then
exit
fi

function waitForDeployment() {
DEPLOY=$1
NS=$2
CREATE=true

if [ $# -eq 3 ] && ! $3 ; then
CREATE=false
fi

for i in $(seq 1 50) ; do
kubectl get deployment -n ${NS} ${DEPLOY}
kstat=$?
if [ $kstat -ne 0 ] && ! $CREATE ; then
return
elif [ $kstat -eq 0 ] && ! $CREATE; then
sleep 3
continue
fi

replicas=$(kubectl get deployment -n ${NS} ${DEPLOY} -o json | jq ".status.readyReplicas")
if [ "$replicas" == "1" ]; then
break
else
echo "Waiting for ${DEPLOY} to be ready"
if [ ${DEPLOY} != "maya-apiserver" ] && [ ${DEPLOY} != "openebs-provisioner" ]; then
dumpMayaAPIServerLogs 10
fi
sleep 10
fi
done
}

MAPI_SVC_ADDR=`kubectl get service -n openebs maya-apiserver-service -o json | grep clusterIP | awk -F\" '{print $4}'`
export MAPI_ADDR="http://${MAPI_SVC_ADDR}:5656"
export KUBERNETES_SERVICE_HOST="127.0.0.1"
export KUBECONFIG=$HOME/.kube/config

wget -O velero.tar.gz https://github.com/heptio/velero/releases/download/${VELERO_RELEASE}/velero-${VELERO_RELEASE}-linux-amd64.tar.gz
mkdir velero
tar xf velero.tar.gz -C velero
velero=$PWD/velero/velero-${VELERO_RELEASE}-linux-amd64/velero
if [ ! -f ${velero} ]; then
echo "${velero} file does not exist"
exit
fi

if [ ! -f minio ]; then
wget https://dl.min.io/server/minio/release/linux-amd64/minio
fi

if [ ! -f mc ]; then
wget https://dl.min.io/client/mc/release/linux-amd64/mc
fi
chmod +x minio
chmod +x mc

BACKUP_DIR=$PWD/data

export MINIO_ACCESS_KEY=minio
export MINIO_SECRET_KEY=minio123

ip addr show docker0 >> /dev/null
if [ $? -ne 0 ]; then
exit 1
fi

MINIO_SERVER_IP=`ip addr show docker0 |grep docker0 |grep inet |awk -F ' ' '{print $2}' |awk -F '/' '{print $1}'`
if [ $? -ne 0 ] || [ -z ${MINIO_SERVER_IP} ]; then
exit 1
fi

./minio server --address ${MINIO_SERVER_IP}:9000 ${BACKUP_DIR} &
MINIO_PID=$!
sleep 5

BUCKET=velero
REGION=minio
./mc config host add velero http://${MINIO_SERVER_IP}:9000 minio minio123
./mc mb -p velero/velero

${velero} install \
--provider aws \
--bucket $BUCKET \
--secret-file ./script/minio-credentials \
--backup-location-config region=${REGION},s3ForcePathStyle="true",s3Url=http://${MINIO_SERVER_IP}:9000 \
--wait

sed "s/MINIO_ENDPOINT/http:\/\/$MINIO_SERVER_IP\:9000/" script/volumesnapshotlocation.yaml > /tmp/s.yaml
kubectl apply -f /tmp/s.yaml
${velero} plugin add openebs/velero-plugin:ci
4 changes: 4 additions & 0 deletions script/minio-credentials
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[default]
aws_access_key_id=minio
aws_secret_access_key=minio123

103 changes: 103 additions & 0 deletions script/minio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
apiVersion: apps/v1beta1
kind: Deployment
metadata:
namespace: velero
name: minio
labels:
component: minio
spec:
strategy:
type: Recreate
template:
metadata:
labels:
component: minio
spec:
volumes:
- name: storage
emptyDir: {}
- name: config
emptyDir: {}
containers:
- name: minio
image: minio/minio:latest
imagePullPolicy: IfNotPresent
args:
- server
- /storage
- --config-dir=/config
env:
- name: MINIO_ACCESS_KEY
value: "minio"
- name: MINIO_SECRET_KEY
value: "minio123"
ports:
- containerPort: 9000
volumeMounts:
- name: storage
mountPath: "/storage"
- name: config
mountPath: "/config"

---
apiVersion: v1
kind: Service
metadata:
namespace: velero
name: minio
labels:
component: minio
spec:
# ClusterIP is recommended for production environments.
# Change to NodePort if needed per documentation,
# but only if you run Minio in a test/trial environment, for example with Minikube.
type: ClusterIP
ports:
- port: 9000
targetPort: 9000
protocol: TCP
selector:
component: minio

---
apiVersion: v1
kind: Secret
metadata:
namespace: velero
name: cloud-credentials
labels:
component: minio
stringData:
cloud: |
[default]
aws_access_key_id = minio
aws_secret_access_key = minio123
---
apiVersion: batch/v1
kind: Job
metadata:
namespace: velero
name: minio-setup
labels:
component: minio
spec:
template:
metadata:
name: minio-setup
spec:
restartPolicy: OnFailure
volumes:
- name: config
emptyDir: {}
containers:
- name: mc
image: minio/mc:latest
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- "mc --debug --config-dir=/config config host add velero http://minio:9000 minio minio123 && mc --config-dir=/config mb -p velero/velero"
volumeMounts:
- name: config
mountPath: "/config"
28 changes: 28 additions & 0 deletions script/volumesnapshotlocation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2018 the Heptio Ark contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: velero.io/v1
kind: VolumeSnapshotLocation
metadata:
name: default
namespace: velero
spec:
provider: openebs.io/cstor-blockstore
config:
bucket: velero
provider: aws
region: minio
s3Url: MINIO_ENDPOINT
s3ForcePathStyle: "true"
Loading

0 comments on commit e59b9c1

Please sign in to comment.