Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
feat(ci): Add csi-sanity tests and fix common errors in csi-driver (#3)
Browse files Browse the repository at this point in the history
Initial tests for Jiva volumes provisioned via CSI driver. 

Signed-off-by: Utkarsh Mani Tripathi <[email protected]>
  • Loading branch information
Utkarsh Mani Tripathi authored and kmova committed Dec 31, 2019
1 parent a1e1a3a commit 4575013
Show file tree
Hide file tree
Showing 17 changed files with 686 additions and 88 deletions.
34 changes: 21 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go:
env:
global:
- GOARCH=$(go env GOARCH)
- GOPATH=$(go env GOPATH)
- GO_FOR_RELEASE=1.13
- CHANGE_MINIKUBE_NONE_USER=true
- MINIKUBE_WANTUPDATENOTIFICATION=false
Expand All @@ -24,27 +25,34 @@ install:
- make bootstrap

before_install:
- git clone https://www.github.com/openebs/jiva-operator $GOPATH/src/github.com/openebs/jiva-operator
- sudo apt-get install -y open-iscsi
- sudo service iscsid start
# Download kubectl, which is a requirement for using minikube.
#- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.14.8/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Download minikube.
#- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.5.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
#- mkdir -p $HOME/.kube $HOME/.minikube
#- touch $KUBECONFIG
#- sudo minikube start --vm-driver=none --kubernetes-version=v1.14.0
#- "sudo chown -R travis: /home/travis/.minikube/"
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.5.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- mkdir -p $HOME/.kube $HOME/.minikube
- touch $KUBECONFIG
- sudo minikube start --vm-driver=none --kubernetes-version=v1.14.8
- "sudo chown -R travis: /home/travis/.minikube/"
script:
#- kubectl cluster-info
- kubectl cluster-info
# Verify kube-addon-manager.
# kube-addon-manager is responsible for managing other kubernetes components, such as kube-dns, dashboard, storage-provisioner..
#- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lcomponent=kube-addon-manager -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for kube-addon-manager to be available"; kubectl get pods --all-namespaces; done
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lcomponent=kube-addon-manager -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for kube-addon-manager to be available"; kubectl get pods --all-namespaces; done
- make image
#- ./ci/travis-ci.sh
- cd $GOPATH/src/github.com/openebs/jiva-operator
- wget https://raw.githubusercontent.com/openebs/openebs/master/k8s/openebs-operator.yaml
- kubectl apply -f openebs-operator.yaml
- kubectl apply -f deploy/crds/openebs_v1alpha1_jivavolume_crd.yaml
- kubectl apply -f deploy/
- cd ${TRAVIS_BUILD_DIR}
- kubectl apply -f deploy/jiva-csi-ubuntu-16.04.yaml
- ./ci/ci.sh
after_success:
- make push-tag
notifications:
email:
recipients:
- [email protected]
webhooks:
urls:
- https://webhooks.gitter.im/e/d885a0beef16020c3878
- [email protected]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[![Slack](https://img.shields.io/badge/chat!!!-slack-ff1493.svg?style=flat-square)]( https://openebs-community.slack.com)
[![Twitter](https://img.shields.io/twitter/follow/openebs.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=openebs)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/openebs/openebs/blob/master/CONTRIBUTING.md)


[![Go Report Card](https://goreportcard.com/badge/github.com/openebs/jiva-csi)](https://goreportcard.com/report/github.com/openebs/jiva-csi)
[![Build Status](https://travis-ci.org/openebs/jiva-csi.svg?branch=master)](https://travis-ci.org/openebs/jiva-csi)

## Overview

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

#set -ex

function initializeTestEnv() {
echo "===================== Initialize test env ======================"
# Pull image so that provisioning won't take long time
docker pull openebs/jiva:ci
cat <<EOT >> /tmp/parameters.json
{
"cas-type": "jiva",
"replicaCount": "1"
}
EOT
sudo rm -rf /tmp/csi.sock
}


function dumpLogs() {
echo "========================== Dump logs ==========================="
local RESOURCE=$1
local COMPONENT=$2
local NS=$3
local LABEL=$4
local CONTAINER=$5
local POD=$(kubectl get pod -n $NS -l $LABEL -o jsonpath='{range .items[*]}{@.metadata.name}')
if [ -z $CONTAINER ];
then
kubectl logs --tail=50 $POD -n $NS
else
kubectl logs --tail=50 $POD -n $NS -c $CONTAINER
fi
}

function dumpAllLogs() {
echo "========================= Dump All logs ========================"
kubectl get pods -n openebs
kubectl describe pods -n openebs
kubectl describe pods -n kube-system
dumpLogs "ds" "openebs-jiva-csi-node" "kube-system" "app=openebs-jiva-csi-node" "openebs-jiva-csi-plugin"
dumpLogs "sts" "openebs-jiva-csi-controller" "kube-system" "app=openebs-jiva-csi-controller" "openebs-jiva-csi-plugin"
dumpLogs "deploy" "openebs-localpv-provisioner" "openebs" "name=openebs-localpv-provisioner"
}

function waitForComponent() {
echo "====================== Wait for component ======================"
local RESOURCE=$1
local COMPONENT=$2
local NS=$3
local CONTAINER=$4
local replicas=""

for i in $(seq 1 50) ; do
kubectl get $RESOURCE -n ${NS} ${COMPONENT}
if [ "$RESOURCE" == "ds" ] || [ "$RESOURCE" == "daemonset" ];
then
replicas=$(kubectl get $RESOURCE -n ${NS} ${COMPONENT} -o json | jq ".status.numberReady")
else
replicas=$(kubectl get $RESOURCE -n ${NS} ${COMPONENT} -o json | jq ".status.readyReplicas")
fi
if [ "$replicas" == "1" ];
then
echo "${COMPONENT} is ready"
break
else
echo "Waiting for ${COMPONENT} to be ready"
if [ $i -eq "50" ];
then
dumpAllLogs
fi
fi
sleep 10
done
}

function initializeCSISanitySuite() {
echo "=============== Initialize CSI Sanity test suite ==============="
CSI_TEST_REPO=https://github.com/kubernetes-csi/csi-test.git
CSI_REPO_PATH="$GOPATH/src/github.com/kubernetes-csi/csi-test"
if [ ! -d "$CSI_REPO_PATH" ] ; then
git clone $CSI_TEST_REPO $CSI_REPO_PATH
else
cd "$CSI_REPO_PATH"
git pull $CSI_REPO_PATH
fi

cd "$CSI_REPO_PATH/cmd/csi-sanity"
make clean
make

SOCK_PATH=/var/lib/kubelet/pods/`kubectl get pod -n kube-system openebs-jiva-csi-controller-0 -o 'jsonpath={.metadata.uid}'`/volumes/kubernetes.io~empty-dir/socket-dir/csi.sock
sudo chmod -R 777 /var/lib/kubelet
sudo ln -s $SOCK_PATH /tmp/csi.sock
sudo chmod -R 777 /tmp/csi.sock
}

function waitForAllComponentsToBeReady() {
waitForComponent "deploy" "openebs-ndm-operator" "openebs"
waitForComponent "ds" "openebs-ndm" "openebs"
waitForComponent "deploy" "openebs-localpv-provisioner" "openebs"
waitForComponent "sts" "openebs-jiva-csi-controller" "kube-system" "openebs-jiva-csi-plugin"
waitForComponent "ds" "openebs-jiva-csi-node" "kube-system" "openebs-jiva-csi-plugin"
}

function startTestSuite() {
echo "================== Start csi-sanity test suite ================="
./csi-sanity --ginkgo.v --csi.controllerendpoint=///tmp/csi.sock --csi.endpoint=/var/lib/kubelet/plugins/jiva.csi.openebs.io/csi.sock --csi.testvolumeparameters=/tmp/parameters.json
if [ $? -ne 0 ];
then
dumpAllLogs
exit 1
fi
exit 0
}

initializeTestEnv
waitForAllComponentsToBeReady
initializeCSISanitySuite
startTestSuite
8 changes: 7 additions & 1 deletion cmd/csi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func (w *log2LogrusWriter) Write(b []byte) (int, error) {
return n, nil
}

var enableISCSIDebug bool
var (
enableISCSIDebug bool
)

/*
* main routine to start the jiva-csi-driver. The same
Expand Down Expand Up @@ -99,6 +101,10 @@ func main() {
&enableISCSIDebug, "enableiscsidebug", false, "Enable iscsi debug logs",
)

cmd.Flags().IntVar(
&driver.MaxRetryCount, "retrycount", 5, "Max retry count to check if volume is ready",
)

err := cmd.Execute()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%s", err.Error())
Expand Down
Loading

0 comments on commit 4575013

Please sign in to comment.