Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement runner for e2e tests #548

Merged
merged 96 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
3a246eb
first commit
Apr 24, 2019
bbaf4cf
fix path
Apr 24, 2019
5fc371d
make go get verbose
Apr 24, 2019
699b276
adjust makefile && test client connection to kind
Apr 24, 2019
61bf835
add mock e2e script
Apr 24, 2019
264833c
push the script
Apr 24, 2019
e320fbc
fix cluster name
Apr 24, 2019
7049c26
delete existing kind cluster
Apr 25, 2019
86a17e3
add tests skeleton
Apr 25, 2019
2bfcb0e
run tests from the script
Apr 25, 2019
f62d740
set up simple unit test
Apr 25, 2019
215d6ba
add requirements
Apr 25, 2019
dda9466
install requirements during build
Apr 25, 2019
7443289
install python3
Apr 25, 2019
d9e905b
minor fixes
Apr 26, 2019
a967672
move tests to a separate dir
Apr 26, 2019
d358e16
rename test runner
Apr 26, 2019
8471590
add Python to .gitignore
Apr 26, 2019
78d2b9c
run e2e tests in Travis
Apr 26, 2019
1ae51f9
change priv in Travis
Apr 26, 2019
eafd302
add sudo to travis
Apr 26, 2019
d801ac3
try to bump up pip3 version
Apr 26, 2019
e9b2f0b
one more try
Apr 26, 2019
179e459
restore original travis yaml
Apr 26, 2019
0d0480d
Add flake
Apr 26, 2019
646de3d
minor fixes
Apr 26, 2019
0474be9
deploy operator before running test
Apr 26, 2019
02c2d48
create/delete the operator deployment
Apr 29, 2019
b63a11e
deploy/delete DB for each test
Apr 29, 2019
63bd846
prepare smoke test template
Apr 29, 2019
021ed9b
explicitly name smoke tests
Apr 30, 2019
2652d18
add timeouts
Apr 30, 2019
af202bf
start the e2e docs
Apr 30, 2019
806ca7b
assemble k8s client; patch scaling test
Apr 30, 2019
30e7445
submit custom operator images
May 2, 2019
25fea48
fix flake8 warnings
May 2, 2019
7858280
refactor into helper methods
May 2, 2019
0c4d80c
fix requirements.txt
May 2, 2019
cb9c77e
mention docker build during e2e
May 2, 2019
f9d145c
make setUp timeout
May 2, 2019
1ced414
minor changes
May 2, 2019
8352abe
fetch image name from docker
May 2, 2019
777ee68
upload newest operator image to kind
May 2, 2019
2aba529
remove python 3.6 formatting strings
May 2, 2019
f2b73e0
add a make target to isntall required tools for e2e
May 2, 2019
bfb6b53
Add progress reporting and make tests verbose
May 3, 2019
af13605
add 'halo' to requirements
May 3, 2019
52e53f1
add Dockerfile for e2e tests
May 8, 2019
084167f
run e2e in a separate Docker image, 1st commit
May 9, 2019
407b2ca
move tests to a Docker container
May 10, 2019
e1befad
ping kind version for CDP build
May 13, 2019
eeaa1a1
install kind before run
May 13, 2019
e985107
remove kubectl mentions
May 13, 2019
66a6d81
install pinned kind version to well-known location
May 13, 2019
82bf0d9
debug builds
May 13, 2019
b8e5567
install Kind to GOENV/bin
May 13, 2019
0ec5a2c
use full binary name
May 13, 2019
c7106dc
substitute realname with readlink
May 13, 2019
c3f5200
minor improvements in Dockerfile
May 14, 2019
9b05215
split run.sh into functions for readability
May 14, 2019
becb05e
Merge branch 'master' into sketch-e2e-tests
May 16, 2019
a00f047
add test for taint-based eviction
FxKu May 20, 2019
461beec
additional check plus comments
FxKu May 20, 2019
f677714
consider setups with more replicas and kind workers
FxKu May 20, 2019
1a3acd0
minor fix
FxKu May 20, 2019
7ca8662
minor fix
FxKu May 21, 2019
6a16daf
wait also for replica to be up and running
FxKu May 21, 2019
948b03f
be nice to flake8
FxKu May 22, 2019
da2e251
1st commit for logical backup e2e test
May 22, 2019
0ec3739
avoid dropping DELETE event for cron job
May 23, 2019
3e42713
Merge branch 'sketch-e2e-tests' of https://github.com/zalando-incubat…
May 23, 2019
45896d5
add assertions to logical backup test
May 23, 2019
7b71e0b
resolve first TODOs
May 23, 2019
a8cdd8b
introduce explicit timeout for operator pod
May 23, 2019
7b9e852
rename k8s_api to k8s everywhere
May 23, 2019
63aa6e6
move retry timeout to utils
May 23, 2019
7cee370
switch to K8s class instead of Util
May 23, 2019
0580916
drop Utils
May 23, 2019
2984872
create with kubectl
May 23, 2019
2ce7b51
refactor
May 24, 2019
3f32870
fix flake8 violations
May 24, 2019
46a4342
pin versions
May 24, 2019
424ad76
lint run.sh
May 24, 2019
4bb20da
unset Kubeconfig env var
May 24, 2019
7075d11
add a test for multiple namespaces
May 24, 2019
a64c355
bump up waiting period for the operator pod
May 24, 2019
9d1939d
bump up kind versions
May 24, 2019
ba52542
Merge branch 'master' into sketch-e2e-tests
FxKu May 24, 2019
bc05589
remove pinned package versions
May 29, 2019
7115989
move clean_up to trap
May 31, 2019
11f2a66
use specific asserts and yaml.safe_load
May 31, 2019
8e16e32
re-write condition in get_spilo_nodes
May 31, 2019
f287f55
introduce timeouts for individual tests
May 31, 2019
3433b7c
fix flake8 violations
Jun 4, 2019
27276bd
Merge branch 'sketch-e2e-tests' of github.com:zalando/postgres-operat…
FxKu Jun 5, 2019
89163e7
update signature for getting nodes of pg cluster
FxKu Jun 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
exclude=.git,__pycache__
max-line-length=120
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,59 @@ scm-source.json
# diagrams
*.aux
*.log

# Python
# Adapted from https://github.com/github/gitignore/blob/master/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ before_install:
- go get github.com/mattn/goveralls

install:
- make deps
- make deps e2e-tools e2e-build

script:
- hack/verify-codegen.sh
- travis_wait 20 goveralls -service=travis-ci -package ./pkg/... -v
- make e2e-run
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean local test linux macos docker push scm-source.json
.PHONY: clean local test linux macos docker push scm-source.json e2e-run e2e-tools e2e-build

BINARY ?= postgres-operator
BUILD_FLAGS ?= -v
Expand Down Expand Up @@ -34,7 +34,7 @@ ifdef CDP_PULL_REQUEST_NUMBER
CDP_TAG := -${CDP_BUILD_VERSION}
endif


KIND_PATH := $(GOPATH)/bin
PATH := $(GOPATH)/bin:$(PATH)
SHELL := env PATH=$(PATH) $(SHELL)

Expand Down Expand Up @@ -91,3 +91,16 @@ deps:
test:
hack/verify-codegen.sh
@go test ./...

e2e-build:
docker build --tag="postgres-operator-e2e-tests" -f e2e/Dockerfile .

e2e-tools:
# install pinned version of 'kind'
# leave the name as is to avoid overwriting official binary named `kind`
wget https://github.com/kubernetes-sigs/kind/releases/download/v0.3.0/kind-linux-amd64
chmod +x kind-linux-amd64
mv kind-linux-amd64 $(KIND_PATH)

e2e-run: docker
e2e/run.sh
6 changes: 5 additions & 1 deletion delivery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pipeline:
apt-get update
- desc: 'Install required build software'
cmd: |
apt-get install -y make git apt-transport-https ca-certificates curl build-essential
apt-get install -y make git apt-transport-https ca-certificates curl build-essential python3 python3-pip
- desc: 'Install go'
cmd: |
cd /tmp
Expand Down Expand Up @@ -41,6 +41,10 @@ pipeline:
export PATH=$PATH:$HOME/go/bin
cd $OPERATOR_TOP_DIR/postgres-operator
go test ./...
- desc: 'Run e2e tests'
cmd: |
cd $OPERATOR_TOP_DIR/postgres-operator
make e2e-tools e2e-build e2e-run
- desc: 'Push docker image'
cmd: |
export PATH=$PATH:$HOME/go/bin
Expand Down
10 changes: 10 additions & 0 deletions docs/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ Then you can for example check the Patroni logs:
kubectl logs acid-minimal-cluster-0
```

## End-to-end tests

The operator provides reference e2e (end-to-end) tests to ensure various infra parts work smoothly together.
Each e2e execution tests a Postgres operator image built from the current git branch. The test runner starts a [kind](https://kind.sigs.k8s.io/) (local k8s) cluster and Docker container with tests. The k8s API client from within the container connects to the `kind` cluster using the standard Docker `bridge` network.
The tests utilize examples from `/manifests` (ConfigMap is used for the operator configuration) to avoid maintaining yet another set of configuration files. The kind cluster is deleted if tests complete successfully.

End-to-end tests are executed automatically during builds; to invoke them locally use `make e2e-run` from the project's top directory. Run `make e2e-tools e2e-build` to install `kind` and build the tests' image locally before the first run.

End-to-end tests are written in Python and use `flake8` for code quality. Please run flake8 [before submitting a PR](http://flake8.pycqa.org/en/latest/user/using-hooks.html).

## Introduce additional configuration parameters

In the case you want to add functionality to the operator that shall be
Expand Down
22 changes: 22 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:18.04
LABEL maintainer="Team ACID @ Zalando <team-acid@zalando.de>"

WORKDIR /e2e

COPY manifests ./manifests
COPY e2e/requirements.txt e2e/tests ./

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
python3 \
python3-setuptools \
python3-pip \
curl \
&& pip3 install --no-cache-dir -r requirements.txt \
&& curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl \
&& mv ./kubectl /usr/local/bin/kubectl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

CMD ["python3", "-m", "unittest", "discover", "--start-directory", ".", "-v"]
6 changes: 6 additions & 0 deletions e2e/kind-cluster-postgres-operator-e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
- role: worker
- role: worker
3 changes: 3 additions & 0 deletions e2e/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kubernetes==9.0.0
timeout_decorator==0.4.1
pyyaml==5.1
58 changes: 58 additions & 0 deletions e2e/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

# enable unofficial bash strict mode
set -o errexit
set -o nounset
set -o pipefail
IFS=$'\n\t'

readonly cluster_name="postgres-operator-e2e-tests"
readonly operator_image=$(docker images --filter=reference="registry.opensource.zalan.do/acid/postgres-operator" --format "{{.Repository}}:{{.Tag}}" | head -1)
readonly e2e_test_image=${cluster_name}
readonly kubeconfig_path="/tmp/kind-config-${cluster_name}"


function start_kind(){

# avoid interference with previous test runs
if [[ $(kind-linux-amd64 get clusters | grep "^${cluster_name}*") != "" ]]
then
kind-linux-amd64 delete cluster --name ${cluster_name}
fi

kind-linux-amd64 create cluster --name ${cluster_name} --config ./e2e/kind-cluster-postgres-operator-e2e-tests.yaml
kind-linux-amd64 load docker-image "${operator_image}" --name ${cluster_name}
KUBECONFIG="$(kind-linux-amd64 get kubeconfig-path --name=${cluster_name})"
export KUBECONFIG
}

function set_kind_api_server_ip(){
# use the actual kubeconfig to connect to the 'kind' API server
# but update the IP address of the API server to the one from the Docker 'bridge' network
cp "${KUBECONFIG}" /tmp
readonly local kind_api_server_port=6443 # well-known in the 'kind' codebase
readonly local kind_api_server=$(docker inspect --format "{{ .NetworkSettings.IPAddress }}:${kind_api_server_port}" "${cluster_name}"-control-plane)
sed -i "s/server.*$/server: https:\/\/$kind_api_server/g" "${kubeconfig_path}"
}

function run_tests(){
docker run --rm --mount type=bind,source="$(readlink -f ${kubeconfig_path})",target=/root/.kube/config -e OPERATOR_IMAGE="${operator_image}" "${e2e_test_image}"
}

function clean_up(){
sdudoladov marked this conversation as resolved.
Show resolved Hide resolved
unset KUBECONFIG
kind-linux-amd64 delete cluster --name ${cluster_name}
rm -rf ${kubeconfig_path}
}

function main(){

trap "clean_up" QUIT TERM EXIT

start_kind
set_kind_api_server_ip
run_tests
exit 0
}

main "$@"
Loading