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:
commit
d19950cc84
5 changed files with 185 additions and 9 deletions
|
@ -25,22 +25,28 @@ pipeline {
|
|||
}
|
||||
agent any
|
||||
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 {
|
||||
stage('Build') {
|
||||
steps {
|
||||
timestamps {
|
||||
withEnv([
|
||||
"IMAGETAG=${env.GIT_COMMIT}",
|
||||
]) {
|
||||
sh "make"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
timestamps {
|
||||
lock("kubernetes-operator-tests") {
|
||||
lock("${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
|
||||
withEnv([
|
||||
'TESTNAMESPACE=${params.TESTNAMESPACE}',
|
||||
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
|
||||
"IMAGETAG=${env.GIT_COMMIT}",
|
||||
"PUSHIMAGES=1",
|
||||
]) {
|
||||
sh "make run-tests"
|
||||
}
|
||||
|
|
26
Makefile
26
Makefile
|
@ -30,6 +30,17 @@ endif
|
|||
DOCKERFILE := Dockerfile
|
||||
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)
|
||||
BIN := $(BINDIR)/$(BINNAME)
|
||||
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)
|
||||
|
||||
docker: $(BIN)
|
||||
docker build -f $(DOCKERFILE) -t arangodb/arangodb-operator .
|
||||
docker build -f $(DOCKERFILE) -t $(OPERATORIMAGE) .
|
||||
|
||||
# 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
|
||||
|
||||
docker-test: $(TESTBIN)
|
||||
docker build --quiet -f $(DOCKERTESTFILE) -t arangodb/arangodb-operator-test .
|
||||
docker build --quiet -f $(DOCKERTESTFILE) -t $(TESTIMAGE) .
|
||||
|
||||
run-tests: docker-test
|
||||
ifdef PUSHIMAGES
|
||||
docker push $(OPERATORIMAGE)
|
||||
docker push $(TESTIMAGE)
|
||||
endif
|
||||
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE)
|
||||
kubectl create namespace $(TESTNAMESPACE)
|
||||
kubectl --namespace=$(TESTNAMESPACE) create -f examples/deployment.yaml
|
||||
kubectl --namespace $(TESTNAMESPACE) run arangodb-operator-test -i --rm --quiet --restart=Never --image=arangodb/arangodb-operator-test --env="TEST_NAMESPACE=$(TESTNAMESPACE)" -- -test.v
|
||||
$(ROOTDIR)/examples/setup-rbac.sh --namespace=$(TESTNAMESPACE)
|
||||
$(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
|
||||
|
||||
# Release building
|
||||
|
||||
docker-push: docker
|
||||
ifneq ($(DOCKERNAMESPACE), arangodb)
|
||||
docker tag arangodb/arangodb-operator $(DOCKERNAMESPACE)/arangodb-operator
|
||||
docker tag $(OPERATORIMAGE) $(DOCKERNAMESPACE)/arangodb-operator
|
||||
endif
|
||||
docker push $(DOCKERNAMESPACE)/arangodb-operator
|
||||
|
||||
|
|
104
examples/setup-rbac.sh
Executable file
104
examples/setup-rbac.sh
Executable 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
45
scripts/kube_create_operator.sh
Executable 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 -
|
|
@ -4,6 +4,11 @@
|
|||
|
||||
NS=$1
|
||||
|
||||
if [ -z $NS ]; then
|
||||
echo "Specify a namespace argument"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kubectl delete namespace $NS --now --ignore-not-found
|
||||
response=$(kubectl get namespace $NS --template="non-empty" --ignore-not-found)
|
||||
while [ ! -z $response ]; do
|
||||
|
|
Loading…
Reference in a new issue