1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

Merge branch 'test-framework' into update-deployment

This commit is contained in:
Ewout Prangsma 2018-02-22 11:02:49 +01:00
commit d19950cc84
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698
5 changed files with 185 additions and 9 deletions

View file

@ -25,22 +25,28 @@ pipeline {
} }
agent any agent any
parameters { parameters {
string(name: 'TESTNAMESPACE', defaultValue: 'arangodb-operator-tests', description: 'TESTNAMESPACE sets the kubernetes namespace to ru tests in', ) string(name: 'TESTNAMESPACE', defaultValue: 'jenkins', description: 'TESTNAMESPACE sets the kubernetes namespace to ru tests in (this must be short!!)', )
} }
stages { stages {
stage('Build') { stage('Build') {
steps { steps {
timestamps { timestamps {
sh "make" withEnv([
"IMAGETAG=${env.GIT_COMMIT}",
]) {
sh "make"
}
} }
} }
} }
stage('Test') { stage('Test') {
steps { steps {
timestamps { timestamps {
lock("kubernetes-operator-tests") { lock("${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
withEnv([ withEnv([
'TESTNAMESPACE=${params.TESTNAMESPACE}', "TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
"IMAGETAG=${env.GIT_COMMIT}",
"PUSHIMAGES=1",
]) { ]) {
sh "make run-tests" sh "make run-tests"
} }

View file

@ -30,6 +30,17 @@ endif
DOCKERFILE := Dockerfile DOCKERFILE := Dockerfile
DOCKERTESTFILE := Dockerfile.test DOCKERTESTFILE := Dockerfile.test
ifdef IMAGETAG
IMAGESUFFIX := ":$(IMAGETAG)"
endif
ifndef OPERATORIMAGE
OPERATORIMAGE := $(DOCKERNAMESPACE)/arangodb-operator$(IMAGESUFFIX)
endif
ifndef TESTIMAGE
TESTIMAGE := $(DOCKERNAMESPACE)/arangodb-operator-test$(IMAGESUFFIX)
endif
BINNAME := $(PROJECT) BINNAME := $(PROJECT)
BIN := $(BINDIR)/$(BINNAME) BIN := $(BINDIR)/$(BINNAME)
TESTBINNAME := $(PROJECT)_test TESTBINNAME := $(PROJECT)_test
@ -126,7 +137,7 @@ $(BIN): $(GOBUILDDIR) $(SOURCES)
go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH) go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH)
docker: $(BIN) docker: $(BIN)
docker build -f $(DOCKERFILE) -t arangodb/arangodb-operator . docker build -f $(DOCKERFILE) -t $(OPERATORIMAGE) .
# Testing # Testing
@ -144,20 +155,25 @@ $(TESTBIN): $(GOBUILDDIR) $(SOURCES)
go test -c -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(TESTBINNAME) $(REPOPATH)/tests go test -c -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(TESTBINNAME) $(REPOPATH)/tests
docker-test: $(TESTBIN) docker-test: $(TESTBIN)
docker build --quiet -f $(DOCKERTESTFILE) -t arangodb/arangodb-operator-test . docker build --quiet -f $(DOCKERTESTFILE) -t $(TESTIMAGE) .
run-tests: docker-test run-tests: docker-test
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
docker push $(TESTIMAGE)
endif
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE) $(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE)
kubectl create namespace $(TESTNAMESPACE) kubectl create namespace $(TESTNAMESPACE)
kubectl --namespace=$(TESTNAMESPACE) create -f examples/deployment.yaml $(ROOTDIR)/examples/setup-rbac.sh --namespace=$(TESTNAMESPACE)
kubectl --namespace $(TESTNAMESPACE) run arangodb-operator-test -i --rm --quiet --restart=Never --image=arangodb/arangodb-operator-test --env="TEST_NAMESPACE=$(TESTNAMESPACE)" -- -test.v $(ROOTDIR)/scripts/kube_create_operator.sh $(TESTNAMESPACE) $(OPERATORIMAGE)
kubectl --namespace $(TESTNAMESPACE) run arangodb-operator-test -i --rm --quiet --restart=Never --image=$(TESTIMAGE) --env="TEST_NAMESPACE=$(TESTNAMESPACE)" -- -test.v
kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now
# Release building # Release building
docker-push: docker docker-push: docker
ifneq ($(DOCKERNAMESPACE), arangodb) ifneq ($(DOCKERNAMESPACE), arangodb)
docker tag arangodb/arangodb-operator $(DOCKERNAMESPACE)/arangodb-operator docker tag $(OPERATORIMAGE) $(DOCKERNAMESPACE)/arangodb-operator
endif endif
docker push $(DOCKERNAMESPACE)/arangodb-operator docker push $(DOCKERNAMESPACE)/arangodb-operator

104
examples/setup-rbac.sh Executable file
View file

@ -0,0 +1,104 @@
#!/bin/bash
function usage {
echo "$(basename "$0") - Create Kubernetes RBAC role and bindings for ArangoDB operator
Usage: $(basename "$0") [options...]
Options:
--role-name=STRING Name of ClusterRole to create
(default=\"arangodb-operator\", environment variable: ROLE_NAME)
--role-binding-name=STRING Name of ClusterRoleBinding to create
(default=\"arangodb-operator\", environment variable: ROLE_BINDING_NAME)
--namespace=STRING namespace to create role and role binding in. Must already exist.
(default=\"default\", environment vairable: NAMESPACE)
" >&2
}
ROLE_NAME="${ROLE_NAME:-arangodb-operator}"
ROLE_BINDING_NAME="${ROLE_BINDING_NAME:-arangodb-operator}"
NAMESPACE="${NAMESPACE:-default}"
function setupRole {
yaml=$(cat << EOYAML
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: ${ROLE_NAME}
rules:
- apiGroups:
- database.arangodb.com
resources:
- arangodeployments
verbs:
- "*"
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- "*"
- apiGroups:
- ""
resources:
- pods
- services
- endpoints
- persistentvolumeclaims
- events
- secrets
verbs:
- "*"
- apiGroups:
- apps
resources:
- deployments
verbs:
- "*"
EOYAML
)
echo "$yaml" | kubectl apply -f -
}
function setupRoleBinding {
yaml=$(cat << EOYAML
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: ${ROLE_BINDING_NAME}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: ${ROLE_NAME}
subjects:
- kind: ServiceAccount
name: default
namespace: ${NAMESPACE}
EOYAML
)
echo "$yaml" | kubectl apply -f -
}
for i in "$@"
do
case $i in
--role-name=*)
ROLE_NAME="${i#*=}"
;;
--role-binding-name=*)
ROLE_BINDING_NAME="${i#*=}"
;;
--namespace=*)
NAMESPACE="${i#*=}"
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
setupRole
setupRoleBinding

45
scripts/kube_create_operator.sh Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
# Create the operator deployment with custom image option
NS=$1
IMAGE=$2
if [ -z $NS ]; then
echo "Specify a namespace argument"
exit 1
fi
if [ -z $IMAGE ]; then
echo "Specify an image argument"
exit 1
fi
yaml=$(cat << EOYAML
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: arangodb-operator
spec:
replicas: 1
template:
metadata:
labels:
name: arangodb-operator
spec:
containers:
- name: arangodb-operator
imagePullPolicy: IfNotPresent
image: ${IMAGE}
env:
- name: MY_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
EOYAML
)
echo "$yaml" | kubectl --namespace=$NS create -f -

View file

@ -4,6 +4,11 @@
NS=$1 NS=$1
if [ -z $NS ]; then
echo "Specify a namespace argument"
exit 1
fi
kubectl delete namespace $NS --now --ignore-not-found kubectl delete namespace $NS --now --ignore-not-found
response=$(kubectl get namespace $NS --template="non-empty" --ignore-not-found) response=$(kubectl get namespace $NS --template="non-empty" --ignore-not-found)
while [ ! -z $response ]; do while [ ! -z $response ]; do