Skip to content

Commit

Permalink
Merge pull request #44 from arangodb/deployment-manifests
Browse files Browse the repository at this point in the history
Cleaning up deployment, avoiding docker overrides
  • Loading branch information
ewoutp authored Mar 13, 2018
2 parents 0682a76 + 414eb5f commit 45461c3
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 226 deletions.
11 changes: 7 additions & 4 deletions Jenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def buildTestSteps(String kubeConfigRoot, String kubeconfig) {
lock("${kubeconfig}-${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
withCredentials([string(credentialsId: 'ENTERPRISEIMAGE', variable: 'DEFAULTENTERPRISEIMAGE')]) {
withEnv([
"DEPLOYMENTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${params.DOCKERNAMESPACE}",
"ENTERPRISEIMAGE=${params.ENTERPRISEIMAGE}",
"IMAGETAG=${env.GIT_COMMIT}",
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
"LONG=${params.LONG ? 1 : 0}",
"PUSHIMAGES=1",
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
]) {
sh "make run-tests"
}
Expand All @@ -46,8 +46,9 @@ def buildCleanupSteps(String kubeConfigRoot, String kubeconfig) {
return {
timestamps {
withEnv([
"DEPLOYMENTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${params.DOCKERNAMESPACE}",
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
]) {
sh "make cleanup-tests"
}
Expand All @@ -62,6 +63,7 @@ pipeline {
agent any
parameters {
booleanParam(name: 'LONG', defaultValue: false, description: 'Execute long running tests')
string(name: 'DOCKERNAMESPACE', defaultValue: 'arangodb', description: 'DOCKERNAMESPACE sets the docker registry namespace in which the operator docker image will be pushed', )
string(name: 'KUBECONFIGS', defaultValue: 'scw-183a3b,c11', description: 'KUBECONFIGS is a comma separated list of Kubernetes configuration files (relative to /home/jenkins/.kube) on which the tests are run', )
string(name: 'TESTNAMESPACE', defaultValue: 'jenkins', description: 'TESTNAMESPACE sets the kubernetes namespace to ru tests in (this must be short!!)', )
string(name: 'ENTERPRISEIMAGE', defaultValue: '', description: 'ENTERPRISEIMAGE sets the docker image used for enterprise tests)', )
Expand All @@ -71,9 +73,10 @@ pipeline {
steps {
timestamps {
withEnv([
"DEPLOYMENTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${params.DOCKERNAMESPACE}",
"IMAGETAG=${env.GIT_COMMIT}",
"LONG=${params.LONG ? 1 : 0}",
"PUSHIMAGES=1",
]) {
sh "make"
sh "make run-unit-tests"
Expand Down
99 changes: 75 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ GOVERSION := 1.10.0-alpine

PULSAR := $(GOBUILDDIR)/bin/pulsar$(shell go env GOEXE)

ifndef DOCKERNAMESPACE
DOCKERNAMESPACE := arangodb
endif
DOCKERFILE := Dockerfile
DOCKERTESTFILE := Dockerfile.test

ifndef LOCALONLY
PUSHIMAGES := 1
IMAGESHA256 := true
else
IMAGESHA256 := false
endif

ifdef IMAGETAG
IMAGESUFFIX := ":$(IMAGETAG)"
IMAGESUFFIX := :$(IMAGETAG)
else
IMAGESUFFIX := :dev
endif

ifndef MANIFESTPATH
MANIFESTPATH := manifests/arango-operator-dev.yaml
endif
ifndef DEPLOYMENTNAMESPACE
DEPLOYMENTNAMESPACE := default
endif

ifndef OPERATORIMAGE
Expand All @@ -51,9 +64,6 @@ TESTBIN := $(BINDIR)/$(TESTBINNAME)
RELEASE := $(GOBUILDDIR)/bin/release
GHRELEASE := $(GOBUILDDIR)/bin/github-release

ifndef TESTNAMESPACE
TESTNAMESPACE := arangodb-operator-tests
endif
TESTLENGTHOPTIONS := -test.short
TESTTIMEOUT := 20m
ifeq ($(LONG), 1)
Expand All @@ -66,19 +76,29 @@ endif

SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')

.PHONY: all clean deps docker update-vendor update-generated verify-generated

all: verify-generated docker
.PHONY: all
all: verify-generated build

#
# Tip: Run `eval $(minikube docker-env)` before calling make if you're developing on minikube.
#

build: docker
.PHONY: build
build: check-vars docker manifests

.PHONY: clean
clean:
rm -Rf $(BIN) $(BINDIR) $(GOBUILDDIR)

.PHONY: check-vars
check-vars:
ifndef DOCKERNAMESPACE
@echo "DOCKERNAMESPACE must be set"
@exit 1
endif
@echo "Using docker namespace: $(DOCKERNAMESPACE)"

.PHONY: deps
deps:
@${MAKE} -B -s $(GOBUILDDIR)

Expand All @@ -93,6 +113,7 @@ $(GOBUILDDIR):
@rm -f $(REPODIR) && ln -sf ../../../.. $(REPODIR)
GOPATH=$(GOBUILDDIR) $(PULSAR) go flatten -V $(VENDORDIR)

.PHONY: update-vendor
update-vendor:
@mkdir -p $(GOBUILDDIR)
@GOPATH=$(GOBUILDDIR) go get github.com/pulcy/pulsar
Expand All @@ -119,6 +140,7 @@ update-vendor:
@$(PULSAR) go flatten -V $(VENDORDIR) $(VENDORDIR)
@${MAKE} -B -s clean

.PHONY: update-generated
update-generated: $(GOBUILDDIR)
@docker build $(SRCDIR)/tools/codegen --build-arg GOVERSION=$(GOVERSION) -t k8s-codegen
docker run \
Expand All @@ -136,6 +158,7 @@ update-generated: $(GOBUILDDIR)
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)

.PHONY: verify-generated
verify-generated:
@${MAKE} -B -s VERIFYARGS=--verify-only update-generated

Expand All @@ -152,14 +175,26 @@ $(BIN): $(GOBUILDDIR) $(SOURCES)
golang:$(GOVERSION) \
go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH)

docker: $(BIN)
.PHONY: docker
docker: check-vars $(BIN)
docker build -f $(DOCKERFILE) -t $(OPERATORIMAGE) .
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
endif

# Manifests

.PHONY: manifests
manifests: $(GOBUILDDIR)
GOPATH=$(GOBUILDDIR) go run $(ROOTDIR)/tools/manifests/manifest_builder.go \
--output=$(MANIFESTPATH) \
--image=$(OPERATORIMAGE) \
--image-sha256=$(IMAGESHA256) \
--namespace=$(DEPLOYMENTNAMESPACE)

# Testing

.PHONY: run-unit-tests
run-unit-tests: $(GOBUILDDIR) $(SOURCES)
docker run \
--rm \
Expand Down Expand Up @@ -189,39 +224,49 @@ $(TESTBIN): $(GOBUILDDIR) $(SOURCES)
golang:$(GOVERSION) \
go test -c -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(TESTBINNAME) $(REPOPATH)/tests

.PHONY: docker-test
docker-test: $(TESTBIN)
docker build --quiet -f $(DOCKERTESTFILE) -t $(TESTIMAGE) .

.PHONY: run-tests
run-tests: docker-test
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
docker push $(TESTIMAGE)
endif
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE)
kubectl create namespace $(TESTNAMESPACE)
$(ROOTDIR)/examples/setup-rbac.sh --namespace=$(TESTNAMESPACE)
$(ROOTDIR)/scripts/kube_create_operator.sh $(TESTNAMESPACE) $(OPERATORIMAGE)
$(ROOTDIR)/scripts/kube_create_storage.sh $(TESTNAMESPACE)
kubectl --namespace $(TESTNAMESPACE) \
ifneq ($(DEPLOYMENTNAMESPACE), default)
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(DEPLOYMENTNAMESPACE)
kubectl create namespace $(DEPLOYMENTNAMESPACE)
endif
kubectl apply -f $(MANIFESTPATH)
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
kubectl --namespace $(DEPLOYMENTNAMESPACE) \
run arangodb-operator-test -i --rm --quiet --restart=Never \
--image=$(TESTIMAGE) \
--env="ENTERPRISEIMAGE=$(ENTERPRISEIMAGE)" \
--env="TEST_NAMESPACE=$(TESTNAMESPACE)" \
--env="TEST_NAMESPACE=$(DEPLOYMENTNAMESPACE)" \
-- \
-test.v -test.timeout $(TESTTIMEOUT) $(TESTLENGTHOPTIONS)
kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now
ifneq ($(DEPLOYMENTNAMESPACE), default)
kubectl delete namespace $(DEPLOYMENTNAMESPACE) --ignore-not-found --now
endif

.PHONY: cleanup-tests
cleanup-tests:
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE)
ifneq ($(DEPLOYMENTNAMESPACE), default)
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(DEPLOYMENTNAMESPACE)
endif

# Release building

.PHONY: docker-push
docker-push: docker
ifneq ($(DOCKERNAMESPACE), arangodb)
docker tag $(OPERATORIMAGE) $(DOCKERNAMESPACE)/arangodb-operator
endif
docker push $(DOCKERNAMESPACE)/arangodb-operator

.PHONY: docker-push-version
docker-push-version: docker
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION_MAJOR_MINOR)
Expand All @@ -238,23 +283,29 @@ $(RELEASE): $(GOBUILDDIR) $(SOURCES) $(GHRELEASE)
$(GHRELEASE): $(GOBUILDDIR)
GOPATH=$(GOBUILDDIR) go build -o $(GHRELEASE) github.com/aktau/github-release

.PHONY: release-patch
release-patch: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=patch

.PHONY: release-minor
release-minor: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=minor

.PHONY: release-major
release-major: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=major

## Kubernetes utilities

.PHONY: minikube-start
minikube-start:
minikube start --cpus=4 --memory=6144

.PHONY: delete-operator
delete-operator:
kubectl delete deployment arangodb-operator --ignore-not-found
kubectl delete -f $(MANIFESTPATH) --ignore-not-found

redeploy-operator: delete-operator
USESHA256=1 $(ROOTDIR)/scripts/kube_create_operator.sh default $(OPERATORIMAGE)
.PHONY: redeploy-operator
redeploy-operator: delete-operator manifests
kubectl apply -f $(MANIFESTPATH)
kubectl get pods
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

"Starter for Kubernetes"

State: Design only
State: In development

- [User manual](./docs/user/README.md)
- [Design documents](./docs/design/README.md)

## Building

```bash
DOCKERNAMESPACE=<your dockerhub account> make
kubectl apply -f manifests/arango-operator-dev.yaml
```
4 changes: 2 additions & 2 deletions docs/user/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The ArangoDB operator needs to be installed in your Kubernetes
cluster first. To do so, clone this repository and run:

```bash
kubectl create -f examples/deployment.yaml
kubectl create -f manifests/arango-operator.yaml
```

## Cluster creation
Expand Down Expand Up @@ -37,5 +37,5 @@ To remove the entire ArangoDB operator, remove all
clusters first and then remove the operator by running:

```bash
kubectl delete -f examples/deployment.yaml
kubectl delete -f manifests/arango-operator.yaml
```
Loading

0 comments on commit 45461c3

Please sign in to comment.