mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
Better testin on jenkins
This commit is contained in:
parent
f921584da7
commit
69554d57b9
3 changed files with 72 additions and 7 deletions
|
@ -31,18 +31,23 @@ pipeline {
|
|||
stage('Build') {
|
||||
steps {
|
||||
timestamps {
|
||||
withEnv([
|
||||
"IMAGETAG=${env.GIT_COMMIT}",
|
||||
]) {
|
||||
sh "make"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
timestamps {
|
||||
lock("kubernetes-operator-tests") {
|
||||
withEnv([
|
||||
"TESTNAMESPACE=${params.TESTNAMESPACE}",
|
||||
"IMAGETAG=${env.GIT_COMMIT}",
|
||||
"PUSHIMAGES=1",
|
||||
]) {
|
||||
sh "make"
|
||||
sh "make run-tests"
|
||||
}
|
||||
}
|
||||
|
|
25
Makefile
25
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,24 @@ $(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)/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
|
||||
|
||||
|
|
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 -
|
Loading…
Reference in a new issue