feat(zfs-localpv): initial commit

provisioning and deprovisioning of
the volumes on the node where zfs pool
has already been setup. Pool name and the volume
parameters has to be given in storage class
which will be used to provision the volume.

Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
Pawan 2019-09-12 12:32:17 +05:30 committed by Kiran Mova
parent 485e2a21f0
commit 9f5cf445df
46 changed files with 6339 additions and 0 deletions

135
buildscripts/build.sh Executable file
View file

@ -0,0 +1,135 @@
#!/usr/bin/env bash
#
# This script builds the application from source for multiple platforms.
set -e
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )"
# Change into that directory
cd "$DIR"
# Get the git commit
if [ -f $GOPATH/src/github.com/openebs/zfs-localpv/GITCOMMIT ];
then
GIT_COMMIT="$(cat $GOPATH/src/github.com/openebs/zfs-localpv/GITCOMMIT)"
else
GIT_COMMIT="$(git rev-parse HEAD)"
fi
# Set BUILDMETA based on travis tag
if [[ -n "$TRAVIS_TAG" ]] && [[ $TRAVIS_TAG != *"RC"* ]]; then
echo "released" > BUILDMETA
fi
# Get the version details
VERSION="$(cat $GOPATH/src/github.com/openebs/zfs-localpv/VERSION)"
VERSION_META="$(cat $GOPATH/src/github.com/openebs/zfs-localpv/BUILDMETA)"
# Determine the arch/os combos we're building for
UNAME=$(uname)
ARCH=$(uname -m)
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then
echo "Sorry, this OS is not supported yet."
exit 1
fi
if [ "$UNAME" = "Darwin" ] ; then
XC_OS="darwin"
elif [ "$UNAME" = "Linux" ] ; then
XC_OS="linux"
fi
if [ "${ARCH}" = "i686" ] ; then
XC_ARCH='386'
elif [ "${ARCH}" = "x86_64" ] ; then
XC_ARCH='amd64'
else
echo "Unusable architecture: ${ARCH}"
exit 1
fi
if [ -z "${PNAME}" ];
then
echo "Project name not defined"
exit 1
fi
if [ -z "${CTLNAME}" ];
then
echo "CTLNAME not defined"
exit 1
fi
# Delete the old dir
echo "==> Removing old directory..."
rm -rf bin/${PNAME}/*
mkdir -p bin/${PNAME}/
# If its dev mode, only build for ourself
if [[ "${DEV}" ]]; then
XC_OS=$(go env GOOS)
XC_ARCH=$(go env GOARCH)
fi
# Build!
echo "==> Building ${CTLNAME} using $(go version)... "
GOOS="${XC_OS}"
GOARCH="${XC_ARCH}"
output_name="bin/${PNAME}/"$GOOS"_"$GOARCH"/"$CTLNAME
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags \
"-X github.com/openebs/zfs-localpv/pkg/version.GitCommit=${GIT_COMMIT} \
-X main.CtlName='${CTLNAME}' \
-X github.com/openebs/zfs-localpv/pkg/version.Version=${VERSION} \
-X github.com/openebs/zfs-localpv/pkg/version.VersionMeta=${VERSION_META}"\
-o $output_name\
./cmd
echo ""
# Move all the compiled things to the $GOPATH/bin
GOPATH=${GOPATH:-$(go env GOPATH)}
case $(uname) in
CYGWIN*)
GOPATH="$(cygpath $GOPATH)"
;;
esac
OLDIFS=$IFS
IFS=: MAIN_GOPATH=($GOPATH)
IFS=$OLDIFS
# Create the gopath bin if not already available
mkdir -p ${MAIN_GOPATH}/bin/
# Copy our OS/Arch to the bin/ directory
DEV_PLATFORM="./bin/${PNAME}/$(go env GOOS)_$(go env GOARCH)"
for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
cp ${F} bin/${PNAME}/
cp ${F} ${MAIN_GOPATH}/bin/
done
if [[ "x${DEV}" == "x" ]]; then
# Zip and copy to the dist dir
echo "==> Packaging..."
for PLATFORM in $(find ./bin/${PNAME} -mindepth 1 -maxdepth 1 -type d); do
OSARCH=$(basename ${PLATFORM})
echo "--> ${OSARCH}"
pushd "$PLATFORM" >/dev/null 2>&1
zip ../${PNAME}-${OSARCH}.zip ./*
popd >/dev/null 2>&1
done
fi
# Done!
echo
echo "==> Results:"
ls -hl bin/${PNAME}/

View file

@ -0,0 +1,15 @@
/*
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.
*/

102
buildscripts/push Executable file
View file

@ -0,0 +1,102 @@
#!/bin/bash
set -e
if [ -z ${DIMAGE} ];
then
echo "Error: DIMAGE is not specified";
exit 1
fi
IMAGEID=$( sudo docker images -q ${DIMAGE}:ci )
echo "${DIMAGE}:ci -> $IMAGEID"
if [ -z ${IMAGEID} ];
then
echo "Error: unable to get IMAGEID for ${DIMAGE}:ci";
exit 1
fi
# Generate a unique tag based on the commit and tag
BUILD_ID=$(git describe --tags --always)
# Determine the current branch
CURRENT_BRANCH=""
if [ -z ${TRAVIS_BRANCH} ];
then
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
else
CURRENT_BRANCH=${TRAVIS_BRANCH}
fi
#Depending on the branch where builds are generated,
# set the tag CI (fixed) and build tags.
BUILD_TAG="${CURRENT_BRANCH}-${BUILD_ID}"
CI_TAG="${CURRENT_BRANCH}-ci"
if [ ${CURRENT_BRANCH} = "master" ]; then
CI_TAG="ci"
fi
echo "Set the fixed ci image tag as: ${CI_TAG}"
echo "Set the build/unique image tag as: ${BUILD_TAG}"
function TagAndPushImage() {
REPO="$1"
TAG="$2"
IMAGE_URI="${REPO}:${TAG}";
sudo docker tag ${IMAGEID} ${IMAGE_URI};
echo " push ${IMAGE_URI}";
sudo docker push ${IMAGE_URI};
}
if [ ! -z "${DNAME}" ] && [ ! -z "${DPASS}" ];
then
sudo docker login -u "${DNAME}" -p "${DPASS}";
# Push CI tagged image - :ci or :branch-ci
TagAndPushImage "${DIMAGE}" "${CI_TAG}"
# Push unique tagged image - :master-<uuid> or :branch-<uuid>
# This unique/build image will be pushed to corresponding ci repo.
TagAndPushImage "${DIMAGE}-ci" "${BUILD_TAG}"
if [ ! -z "${TRAVIS_TAG}" ] ;
then
# Push with different tags if tagged as a release
# When github is tagged with a release, then Travis will
# set the release tag in env TRAVIS_TAG
TagAndPushImage "${DIMAGE}" "${TRAVIS_TAG}"
TagAndPushImage "${DIMAGE}" "latest"
fi;
else
echo "No docker credentials provided. Skip uploading ${DIMAGE} to docker hub";
fi;
# Push ci image to quay.io for security scanning
if [ ! -z "${QNAME}" ] && [ ! -z "${QPASS}" ];
then
sudo docker login -u "${QNAME}" -p "${QPASS}" quay.io;
# Push CI tagged image - :ci or :branch-ci
TagAndPushImage "quay.io/${DIMAGE}" "${CI_TAG}"
if [ ! -z "${TRAVIS_TAG}" ] ;
then
# Push with different tags if tagged as a release
# When github is tagged with a release, then Travis will
# set the release tag in env TRAVIS_TAG
TagAndPushImage "quay.io/${DIMAGE}" "${TRAVIS_TAG}"
TagAndPushImage "quay.io/${DIMAGE}" "latest"
fi;
else
echo "No docker credentials provided. Skip uploading ${DIMAGE} to quay";
fi;
#Push image to run openebs-e2e based on git commit
if [ ! -z "${COMMIT}" ];
then
sudo docker login -u "${GITLAB_DNAME}" -p "${GITLAB_DPASS}";
# Push COMMIT tagged image - :COMMIT
TagAndPushImage "${DIMAGE}" "${COMMIT}"
fi;

13
buildscripts/test-cov.sh Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
echo "" > coverage.txt
for d in $(go list ./... | grep -v 'vendor\|pkg/apis\|pkg/generated\|tests'); do
#TODO - Include -race while creating the coverage profile.
go test -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done

63
buildscripts/travis-build.sh Executable file
View file

@ -0,0 +1,63 @@
#!/bin/bash
set -e
# 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.
SRC_REPO="$TRAVIS_BUILD_DIR"
DST_REPO="$GOPATH/src/github.com/openebs/zfs-localpv"
function checkGitDiff() {
if [[ `git diff --shortstat | wc -l` != 0 ]]; then echo "Some files got changed after $1";printf "\n";git diff --stat;printf "\n"; exit 1; fi
}
if [ "$SRC_REPO" != "$DST_REPO" ];
then
echo "Copying from $SRC_REPO to $DST_REPO"
# Get the git commit
echo "But first, get the git revision from $SRC_REPO"
GIT_COMMIT="$(git rev-parse HEAD)"
echo $GIT_COMMIT >> $SRC_REPO/GITCOMMIT
mkdir -p $DST_REPO
cp -R $SRC_REPO/* $DST_REPO/
cd $DST_REPO
fi
#make golint-travis
#rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "Running : make format"
make format
rc=$?; if [[ $rc != 0 ]]; then echo "make format failed"; exit $rc; fi
checkGitDiff "make format"
printf "\n"
echo "Running : make kubegen"
make kubegen
rc=$?; if [[ $rc != 0 ]]; then echo "make kubegen failed"; exit $rc; fi
checkGitDiff "make kubegen"
printf "\n"
./buildscripts/test-cov.sh
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make all
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
if [ $SRC_REPO != $DST_REPO ];
then
echo "Copying coverage.txt to $SRC_REPO"
cp coverage.txt $SRC_REPO/
cd $SRC_REPO
fi

View file

@ -0,0 +1,25 @@
#
# This Dockerfile builds a recent volume-mgmt using the latest binary from
# volume-mgmt releases.
#
FROM ubuntu:16.04
RUN apt-get update; exit 0
RUN apt-get -y install rsyslog
#RUN apt-get clean && rm -rf /var/lib/apt/lists/*
COPY zfs-driver /usr/local/bin/
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ARG BUILD_DATE
LABEL org.label-schema.name="zfs-driver"
LABEL org.label-schema.description="OpenEBS"
LABEL org.label-schema.url="http://www.openebs.io/"
LABEL org.label-schema.vcs-url="https://github.com/openebs/zfs-localpv"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date=$BUILD_DATE
ENTRYPOINT ["/usr/local/bin/zfs-driver"]
EXPOSE 7676 7777

View file

@ -0,0 +1,5 @@
#!/bin/sh
set -ex
/usr/local/bin/zfs-driver