Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Commit ad8317c

Browse files
authored
Run Riff in e2e CI tests (#311)
1 parent c21f1a9 commit ad8317c

26 files changed

+314
-1023
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ GO_LDFLAGS += -X $(VERSION_PACKAGE).commit=$(shell git rev-parse HEAD)
2626
GO_LDFLAGS +="
2727

2828
PKGS := pkg
29-
3029
GIT_VERSION = $(shell git describe --tags)
30+
PREFIX ?= $(shell pwd)
3131

32-
# Output prefix, defaults to local directory if not specified
33-
ifeq ($(PREFIX),)
34-
PREFIX := $(shell pwd)
35-
endif
3632

3733
.PHONY: all
3834
all: generate linux darwin

ci/Makefile

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Allows running CI jobs manually, each step at a time. It serves following purposes:
2+
# * validation of tasks - if task succeeded invoked using this file, it's more likely it will succeed in pipeline.
3+
# Executing entire pipeline costs time, so validating individual tasks brings value.
4+
# * debugging issues with PRs - when pipeline fails, it might be easier to debug by reducing the debugging iteration time.
5+
#
6+
#
7+
# ## Details: ##
8+
# "make images" will build images. This step and the "build-cli" step are the only steps that are executed locally.
9+
# Other steps are executed in concourse worker.
10+
#
11+
#
12+
# ## Example workflow: ##
13+
#
14+
# 1. Build images (set DOCKER_REGISTRY if you want to use other registry than vmware):
15+
# DOCKER_REGISTRY=gcr.io/project-id make -f ci/Makefile images
16+
# At this point, images are pushed to the repo.
17+
#
18+
# 2. Create a GKE cluster:
19+
# make create-cluster
20+
# This will create a GKE cluster and print its name. You can retrieve kubelet credentials using following command:
21+
# gcloud container clusters get-credentials CLUSTER_NAME
22+
# You don't need to do it, as deploy dispatch command will deploy dispatch for you.
23+
# NOTE: Once you created a cluster, you can skip this step in next debugging iteration.
24+
#
25+
# 4. Prepare Dispatch CLI:
26+
# make build-cli
27+
# if you changed something in CLI code, run this step again before running tests or deploying dispatch
28+
#
29+
# 3. Deploy dispatch:
30+
# DOCKER_REGISTRY=gcr.io/project-id make deploy-dispatch-openfaas
31+
# or
32+
# DOCKER_REGISTRY=gcr.io/project-id make deploy-dispatch-riff
33+
# depending on which faas backend you would like to use. Once you deploy dispatch, you can update it manually using kubectl,
34+
# or rerun this step (if you, for example, updated image tag).
35+
#
36+
# 4. Run e2e tests:
37+
# make e2e-tests-riff
38+
# or
39+
# make e2e-tests-openfaas
40+
# this step will execute e2e-tests.
41+
#
42+
# 5. Uninstall dispatch:
43+
# make uninstall-dispatch
44+
# Run this when you're done with testing. Note: make sure you run this step so there are no leftovers after cluster is deleted.
45+
#
46+
# 6. Delete the cluster:
47+
# make cleanup
48+
# Run this to delete the k8s cluster on GKE. MAKE SURE YOU RUN THIS STEP!
49+
#
50+
51+
MAKE_PATH := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
52+
DISPATCH_PATH := $(MAKE_PATH)/..
53+
54+
GKE_KEY ?= ((gke-key))
55+
GKE_PROJECT_ID ?= ((gke-project-id))
56+
DOCKER_REGISTRY ?= vmware
57+
PUSH_IMAGES ?= 1
58+
BUILD ?= $(shell date +%s)
59+
CLUSTER_NAME_SUFFIX ?= $(shell whoami)
60+
61+
DOCKER_REGISTRY_HOST = $(DOCKER_REGISTRY)
62+
export GKE_KEY
63+
export GKE_PROJECT_ID
64+
export DOCKER_REGISTRY
65+
export DOCKER_REGISTRY_HOST
66+
export PUSH_IMAGES
67+
export BUILD
68+
export CLUSTER_NAME_SUFFIX
69+
70+
.PHONY: all
71+
all: images create-cluster build-cli deploy-dispatch e2e-tests cleanup
72+
73+
.PHONY: login
74+
login:
75+
fly -t dispatch login
76+
77+
.PHONY: images
78+
images:
79+
if [[ "$(DOCKER_REGISTRY)" =~ ^gcr\.io.* ]]; then gcloud docker --authorize-only; fi
80+
$(MAKE) -f $(DISPATCH_PATH)/Makefile images
81+
mkdir -p ciinputs/properties
82+
echo "tag=dev-$(BUILD)" > ciinputs/properties/keyval.properties
83+
84+
85+
.PHONY: create-cluster
86+
create-cluster: ## Create a Kubernetes cluster on GKE
87+
rm -rf ciinputs/cluster
88+
mkdir -p ciinputs/cluster
89+
fly -t dispatch e -c $(MAKE_PATH)/e2e/gke-cluster-create.yml -i dispatch=$(DISPATCH_PATH) -o k8s-cluster=ciinputs/cluster
90+
@echo "Cluster $(shell cat ciinputs/cluster/name) created"
91+
92+
.PHONY: build-cli
93+
build-cli: ## Build CLI to be used in CI
94+
mkdir -p ciinputs/dispatch-cli
95+
GOOS=linux go build -o ciinputs/dispatch-cli/dispatch github.com/vmware/dispatch/cmd/dispatch
96+
97+
.PHONY: deploy-dispatch-openfaas
98+
deploy-dispatch-openfaas: ## Deploy dispatch with OpenFaaS on Kubernetes cluster
99+
FAAS=openfaas fly -t dispatch e -c $(MAKE_PATH)/e2e/deploy-dispatch.yml -i dispatch=$(DISPATCH_PATH) -i cluster=ciinputs/cluster -i dispatch-cli=ciinputs/dispatch-cli -i properties=ciinputs/properties
100+
101+
.PHONY: deploy-dispatch-riff
102+
deploy-dispatch-riff: ## Deploy dispatch with Riff on Kubernetes cluster
103+
FAAS=riff fly -t dispatch e -c $(MAKE_PATH)/e2e/deploy-dispatch.yml -i dispatch=$(DISPATCH_PATH) -i cluster=ciinputs/cluster -i dispatch-cli=ciinputs/dispatch-cli -i properties=ciinputs/properties
104+
105+
.PHONY: e2e-tests-openfaas
106+
e2e-tests-openfaas: ## Run e2e tests with OpenFaaS
107+
FAAS=riff fly -t dispatch e -c $(MAKE_PATH)/e2e/run-tests.yml -i dispatch=$(DISPATCH_PATH) -i cluster=ciinputs/cluster -i dispatch-cli=ciinputs/dispatch-cli -o tests-logs=ciinputs/tests-logs
108+
109+
.PHONY: e2e-tests-riff
110+
e2e-tests-riff: ## Run e2e tests with Riff
111+
FAAS=riff fly -t dispatch e -c $(MAKE_PATH)/e2e/run-tests.yml -i dispatch=$(DISPATCH_PATH) -i cluster=ciinputs/cluster -i dispatch-cli=ciinputs/dispatch-cli -o tests-logs=ciinputs/tests-logs
112+
113+
.PHONY: collect-logs
114+
collect-logs: ## Collect logs && uninstall
115+
fly -t dispatch e -c $(MAKE_PATH)/e2e/collect-logs.yml -i dispatch=$(DISPATCH_PATH) -i cluster=ciinputs/cluster -i tests-logs=ciinputs/tests-logs -o dispatch-logs=ciinputs/dispatch-logs
116+
117+
.PHONY: uninstall-dispatch
118+
uninstall-dispatch: ## Uninstall Dispatch from the cluster.
119+
fly -t dispatch e -c $(MAKE_PATH)/e2e/uninstall-dispatch.yml -i dispatch=$(DISPATCH_PATH) -i cluster=ciinputs/cluster -i dispatch-cli=ciinputs/dispatch-cli
120+
121+
.PHONY: cleanup
122+
cleanup: ## Cleanup the cluster
123+
fly -t dispatch e -c $(MAKE_PATH)/e2e/cleanup.yml -i dispatch=$(DISPATCH_PATH) -i cluster=ciinputs/cluster
124+
125+
help: ## Display make help
126+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

ci/e2e/cleanup.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ image_resource:
88
tag: v0.0.10
99

1010
# dispatch must be dispatch git repo.
11-
# dispatch-cli must contain "dispatch" binary
1211
inputs:
1312
- name: dispatch
1413
- name: cluster
15-
- name: dispatch-cli
1614

1715
params:
1816
GKE_KEY:

ci/e2e/collect-logs.yml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ image_resource:
88
tag: v0.0.10
99

1010
# dispatch must be dispatch git repo.
11-
# dispatch-cli must contain "dispatch" binary
1211
inputs:
1312
- name: dispatch
1413
- name: cluster
15-
- name: dispatch-cli
1614
- name: tests-logs
1715

1816
params:
@@ -23,6 +21,7 @@ params:
2321
APIGATEWAY_NAMESPACE: kong
2422
APIGATEWAY_NAME: api-gateway
2523
POSTGRES_NAME: postgres
24+
RIFF_NAMESPACE: riff
2625

2726
outputs:
2827
- name: dispatch-logs
@@ -44,8 +43,10 @@ run:
4443
kubectl logs --tail 100 -n kube-system $(kubectl get deployments -n kube-system -o=name | grep ingress-controller) > ingress_controller.log 2>&1
4544
4645
# OpenFaaS logs
47-
kubectl logs deploy/gateway -n ${FAAS_NAMESPACE} > openfaas_gateway.log 2>&1
48-
kubectl logs deploy/faas-netesd -n ${FAAS_NAMESPACE} > openfaas_faas-netesd.log 2>&1
46+
if kubectl get namespace ${FAAS_NAMESPACE}; then
47+
kubectl logs deploy/gateway -n ${FAAS_NAMESPACE} > openfaas_gateway.log 2>&1
48+
kubectl logs deploy/faas-netesd -n ${FAAS_NAMESPACE} > openfaas_faas-netesd.log 2>&1
49+
fi
4950
5051
# Dispatch logs
5152
kubectl logs deploy/dispatch-function-manager -n ${DISPATCH_NAMESPACE} -c function-manager | sed 's/\\n/\n/g' > dispatch-function-manager.log 2>&1
@@ -67,27 +68,23 @@ run:
6768
kubectl exec ${KONG_PODNAME} -n=${APIGATEWAY_NAMESPACE} cat /usr/local/kong/logs/admin_access.log > kong-admin-access.log 2>&1
6869
kubectl exec ${KONG_PODNAME} -n=${APIGATEWAY_NAMESPACE} cat /usr/local/kong/logs/error.log > kong-error.log 2>&1
6970
71+
# Riff logs
72+
if kubectl get namespace ${RIFF_NAMESPACE}; then
73+
kubectl logs deploy/riff-riff-function-controller -n ${RIFF_NAMESPACE} | sed 's/\\n/\n/g' > riff-function-controller.log 2>&1
74+
kubectl logs deploy/riff-riff-topic-controller -n ${RIFF_NAMESPACE} | sed 's/\\n/\n/g' > riff-topic-controller.log 2>&1
75+
kubectl logs deploy/riff-riff-http-gateway -n ${RIFF_NAMESPACE} | sed 's/\\n/\n/g' > riff-http-gateway.log 2>&1
76+
fi
77+
7078
# Bats log
7179
cp tests-logs/bats.log .
7280
7381
82+
83+
7484
tar -czf dispatch-logs/${BUNDLE_ID}.tar.gz *.log
7585
7686
echo
7787
echo
7888
echo "Job failed. Download logs from dispatch-logs/${BUNDLE_ID}.tar.gz on S3"
7989
echo
8090
echo
81-
82-
cp dispatch-cli/dispatch /usr/local/bin/dispatch
83-
mkdir -p ~/.dispatch
84-
85-
set +x
86-
if [[ -n ${GKE_PROJECT_ID} ]]; then
87-
cp dispatch/ci/e2e/configs/dispatch-install-gke.yml install.yaml
88-
else
89-
cp dispatch/ci/e2e/configs/dispatch-install-local.yml install.yaml
90-
fi
91-
set -x
92-
dispatch uninstall --file install.yaml
93-
exit $?

ci/e2e/config-gke-env.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ set -e +x -u
44

55
: ${GKE_ZONE:="us-west1-c"}
66

7+
echo "Setting up GKE key"
78
echo ${GKE_KEY} | base64 --decode --ignore-garbage > ${HOME}/gcloud-service-key.json
9+
echo "Activating GKE account"
810
gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json >/dev/null 2>&1
9-
gcloud config set project $GKE_PROJECT_ID >/dev/null 2>&1
11+
echo "Setting GKE project"
12+
gcloud config set project ${GKE_PROJECT_ID} >/dev/null 2>&1
13+
echo "Setting default GKE compute zone"
1014
gcloud config set compute/zone ${GKE_ZONE} >/dev/null 2>&1
1115

1216
set -x

ci/e2e/configs/dispatch-install-gke.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dispatch:
77
host: 10.0.0.1
88
port: 443
99
skipAuth: true
10+
faas: FAAS
1011
image:
1112
host: DOCKER_REGISTRY_HOST
1213
tag: IMAGE_TAG

ci/e2e/configs/dispatch-install-local.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dispatch:
44
host: dispatch.local
55
port: 443
66
skipAuth: true
7+
faas: FAAS
78
image:
89
host: DOCKER_REGISTRY_HOST
910
tag: IMAGE_TAG

ci/e2e/deploy-dispatch.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ params:
1111
GKE_KEY:
1212
GKE_PROJECT_ID:
1313
DOCKER_REGISTRY_HOST:
14+
FAAS: openfaas
1415

1516
# dispatch must be dispatch git repo.
1617
# dispatch-cli must contain "dispatch" binary
@@ -43,6 +44,7 @@ run:
4344
4445
sed -i "s/IMAGE_TAG/${IMAGE_TAG}/g" install.yaml
4546
sed -i "s#DOCKER_REGISTRY_HOST#${DOCKER_REGISTRY_HOST}#g" install.yaml
47+
sed -i "s/FAAS/${FAAS}/g" install.yaml
4648
4749
cp dispatch-cli/dispatch /usr/local/bin/dispatch
4850

ci/e2e/gke-cluster-create.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ params:
1212
GKE_PROJECT_ID:
1313
K8S_VERSION: 1.8.7-gke.1
1414
GKE_ZONE: us-west1-c
15+
CLUSTER_NAME_SUFFIX: job
1516

1617
inputs:
1718
- name: dispatch
@@ -28,7 +29,7 @@ run:
2829
2930
source dispatch/ci/e2e/config-gke-env.sh
3031
31-
export cluster_name=dispatch-ci-$(date +%s)
32+
export cluster_name=dispatch-ci-${CLUSTER_NAME_SUFFIX}-$(date +%s)
3233
echo ${cluster_name} > k8s-cluster/name
3334
3435
gcloud container clusters create -m n1-standard-2 --cluster-version ${K8S_VERSION} ${cluster_name}

ci/e2e/run-tests.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ image_resource:
1010
params:
1111
GKE_KEY:
1212
GKE_PROJECT_ID:
13+
FAAS: openfaas
1314

1415
# dispatch must be dispatch git repo.
1516
# dispatch-cli must contain "dispatch" binary
@@ -58,24 +59,5 @@ run:
5859
fi
5960
export BATS_LOG="$(pwd)/tests-logs/bats.log"
6061
pushd dispatch
61-
set +e
6262
./e2e/scripts/run-e2e.sh e2e/tests
63-
test_result=$?
64-
popd
65-
set -e
66-
if [ "$test_result" -eq 0 ]
67-
then
68-
set +x
69-
if [[ -n ${GKE_PROJECT_ID} ]]; then
70-
cp dispatch/ci/e2e/configs/dispatch-install-gke.yml install.yaml
71-
else
72-
cp dispatch/ci/e2e/configs/dispatch-install-local.yml install.yaml
73-
fi
74-
set -x
75-
dispatch uninstall --file install.yaml
76-
exit $?
77-
else
78-
# collect logs must uninstall
79-
exit 1
80-
fi
8163

0 commit comments

Comments
 (0)