Skip to content

End 2 End tests speedup #1180

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

Merged
merged 49 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
21afc07
Improving end 2 end tests by implementing proper eventual asserts and…
Jan-M Oct 18, 2020
cc4bfb0
Build docker image and changed back to os image.
Jan-M Oct 18, 2020
38e6261
Loadbalancer test now uses eventualEqual properly.
Jan-M Oct 19, 2020
ccde8c6
More fixes for e2e tests.
Jan-M Oct 19, 2020
c1ad716
WIP
Jan-M Oct 19, 2020
966575d
* Patroni state function added in k8s
Jan-M Oct 19, 2020
4fc8ca3
Fix distribution call.
Jan-M Oct 19, 2020
c6c4c4c
* Make lazy upgrade test work reliable
Jan-M Oct 20, 2020
668ef51
Printing config as multi log line entity, makes it readable and grepa…
Jan-M Oct 21, 2020
2066256
Progressing on faster e2e tests.
Jan-M Oct 21, 2020
9b596f1
Extending timeout, allow one sync.
Jan-M Oct 21, 2020
f03409d
Fix min resurces end to end test.
Jan-M Oct 21, 2020
39641e8
Fixing annotations key.
Jan-M Oct 21, 2020
6b91bd3
More e2e changes for scale up and down.
Jan-M Oct 21, 2020
b422cf9
Comments updated.
Jan-M Oct 21, 2020
e40abdb
Move scale function.
Jan-M Oct 21, 2020
1f3730b
More tests and more nice diff.
Jan-M Oct 21, 2020
2aeaad0
Minor changes around running pods and catching error in infrastructur…
Jan-M Oct 22, 2020
0143a47
Mostly cosmetic changes to logs. Removed quotes from diff. Move all o…
Jan-M Oct 22, 2020
aa3100c
Mount script with tools for easy logaccess and watching objects.
Jan-M Oct 22, 2020
d88e62f
Fixing yaml dump. Removing restart pending between tests.
Jan-M Oct 22, 2020
0c0474c
Fix missing message.
Jan-M Oct 22, 2020
3d734b1
Set proper update strategy for Postgres operator deployment.
Jan-M Oct 23, 2020
8b057d4
Updating readme.
Jan-M Oct 23, 2020
5294995
Move long running test to end. Move pooler test to new functions.
Jan-M Oct 26, 2020
150205e
Connection pooler diff using new log method.
Jan-M Oct 26, 2020
a8c777a
Show deployments too.
Jan-M Oct 26, 2020
acc1d5e
Pooler cleanup in spec in extra step.
Jan-M Oct 26, 2020
a53280e
Changing e2e for pooler a bit. Check annotations object before lookup.
Jan-M Oct 26, 2020
89741c4
Fix annotation error case.
Jan-M Oct 26, 2020
88e8995
Verify explicit sync of deployment.
Jan-M Oct 26, 2020
eb8df06
Tiny changes.
Jan-M Oct 26, 2020
e6b71cb
Taints and tolerations test.
Jan-M Oct 27, 2020
8dc6c08
Changes to tolerations test. Make it complete quicker.
Jan-M Oct 27, 2020
d2599d9
Fix funciton in wrong class.
Jan-M Oct 27, 2020
826d7c0
Typos.
Jan-M Oct 27, 2020
326c67b
Proper f() wrapper for taint test.
Jan-M Oct 27, 2020
b606b6f
Wait for pods to run.
Jan-M Oct 27, 2020
60cbd4e
Skip failing test for now.
Jan-M Oct 27, 2020
24a2a62
Adress typos.
Jan-M Oct 27, 2020
9a7fc85
Merge master.
Jan-M Oct 27, 2020
30ddfc9
Fix missing pieces from K8s API.
Jan-M Oct 27, 2020
474d4d9
Rename cleanup. Add to readme.
Jan-M Oct 27, 2020
cabb7bc
Catch possible pods count error.
Jan-M Oct 27, 2020
30cd4ed
Giving operator 1 second to startup.
Jan-M Oct 27, 2020
e3f32d2
tiny change to log message.
Jan-M Oct 27, 2020
d24c128
No need to quote valid K8s identifiers.
Jan-M Oct 27, 2020
067c7b5
Adding message to verif manifest was in fact deleted.
Jan-M Oct 27, 2020
85ae41b
Wait more before we delete.
Jan-M Oct 27, 2020
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
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ PKG := `go list ./... | grep -v /vendor/`

ifeq ($(DEBUG),1)
DOCKERFILE = DebugDockerfile
DEBUG_POSTFIX := -debug
DEBUG_POSTFIX := -debug-$(shell date hhmmss)
BUILD_FLAGS += -gcflags "-N -l"
else
DOCKERFILE = Dockerfile
endif

ifeq ($(FRESH),1)
DEBUG_FRESH=$(shell date +"%H-%M-%S")
endif

ifdef CDP_PULL_REQUEST_NUMBER
CDP_TAG := -${CDP_BUILD_VERSION}
endif
Expand Down Expand Up @@ -66,7 +70,7 @@ docker: ${DOCKERDIR}/${DOCKERFILE} docker-context
echo "Version ${VERSION}"
echo "CDP tag ${CDP_TAG}"
echo "git describe $(shell git describe --tags --always --dirty)"
cd "${DOCKERDIR}" && docker build --rm -t "$(IMAGE):$(TAG)$(CDP_TAG)$(DEBUG_POSTFIX)" -f "${DOCKERFILE}" .
cd "${DOCKERDIR}" && docker build --rm -t "$(IMAGE):$(TAG)$(CDP_TAG)$(DEBUG_FRESH)$(DEBUG_POSTFIX)" -f "${DOCKERFILE}" .

indocker-race:
docker run --rm -v "${GOPATH}":"${GOPATH}" -e GOPATH="${GOPATH}" -e RACE=1 -w ${PWD} golang:1.8.1 bash -c "make linux"
Expand Down Expand Up @@ -97,4 +101,4 @@ test:
GO111MODULE=on go test ./...

e2e: docker # build operator image to be tested
cd e2e; make e2etest
cd e2e; make e2etest
6 changes: 5 additions & 1 deletion e2e/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ RUN apt-get update \
python3-setuptools \
python3-pip \
curl \
vim \
&& pip3 install --no-cache-dir -r requirements.txt \
&& curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl \
&& mv ./kubectl /usr/local/bin/kubectl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["python3", "-m", "unittest", "discover", "--start-directory", ".", "-v"]
# working line
# python3 -m unittest discover -v --failfast -k test_e2e.EndToEndTestCase.test_lazy_spilo_upgrade --start-directory tests
ENTRYPOINT ["python3", "-m", "unittest"]
CMD ["discover","-v","--failfast","--start-directory","/tests"]
44 changes: 44 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Docker.
Docker
Go

# Notice

The `manifest` folder in e2e tests folder is not commited to git, it comes from `/manifests`

## Build test runner

In the directory of the cloned Postgres Operator repository change to the e2e
Expand All @@ -35,6 +39,46 @@ In the e2e folder you can invoke tests either with `make test` or with:
To run both the build and test step you can invoke `make e2e` from the parent
directory.

To run the end 2 end test and keep the kind state execute:
```bash
NOCLEANUP=True ./run.sh
```

## Run indidual test

After having executed a normal E2E run with `NOCLEANUP=True` Kind still continues to run, allowing you subsequent test runs.

To run an individual test, run the following command in the `e2e` directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may or may not work depending on the state in which the last test to run leaves the cluster.
It is assumed that individual unit tests will properly clean up after themselves, but that is not given.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. This does not work when stuff is broken. But we cant fix it all now. Future work to have e2e tests not be so mixed up and depending on each other.

Most are easy, bit more annoying to fix are those nodes label and toleration changes.


```bash
NOCLEANUP=True ./run.sh main tests.test_e2e.EndToEndTestCase.test_lazy_spilo_upgrade
```

## Inspecting Kind

If you want to inspect Kind/Kubernetes cluster, use the following script to exec into the K8s setup and then use `kubectl`

```bash
./exec_into_env.sh

# use kube ctl
kubectl get pods

# watch relevant objects
./scripts/watch_objects.sh

# get operator logs
./scripts/get_logs.sh
```

## Cleaning up Kind

To cleanup kind and start fresh

```bash
e2e/run.sh cleanup
```

## Covered use cases

The current tests are all bundled in [`test_e2e.py`](tests/test_e2e.py):
Expand Down
14 changes: 14 additions & 0 deletions e2e/exec_into_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

export cluster_name="postgres-operator-e2e-tests"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does a docker run wrapper export anything to the env ?

export kubeconfig_path="/tmp/kind-config-${cluster_name}"
export operator_image="registry.opensource.zalan.do/acid/postgres-operator:latest"
export e2e_test_runner_image="registry.opensource.zalan.do/acid/postgres-operator-e2e-tests-runner:0.3"

docker run -it --entrypoint /bin/bash --network=host -e "TERM=xterm-256color" \
--mount type=bind,source="$(readlink -f ${kubeconfig_path})",target=/root/.kube/config \
--mount type=bind,source="$(readlink -f manifests)",target=/manifests \
--mount type=bind,source="$(readlink -f tests)",target=/tests \
--mount type=bind,source="$(readlink -f exec.sh)",target=/exec.sh \
--mount type=bind,source="$(readlink -f scripts)",target=/scripts \
-e OPERATOR_IMAGE="${operator_image}" "${e2e_test_runner_image}"
45 changes: 25 additions & 20 deletions e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ IFS=$'\n\t'
readonly cluster_name="postgres-operator-e2e-tests"
readonly kubeconfig_path="/tmp/kind-config-${cluster_name}"
readonly spilo_image="registry.opensource.zalan.do/acid/spilo-12:1.6-p5"
readonly e2e_test_runner_image="registry.opensource.zalan.do/acid/postgres-operator-e2e-tests-runner:0.3"

export GOPATH=${GOPATH-~/go}
export PATH=${GOPATH}/bin:$PATH

echo "Clustername: ${cluster_name}"
echo "Kubeconfig path: ${kubeconfig_path}"
Expand All @@ -19,12 +23,7 @@ function pull_images(){
then
docker pull registry.opensource.zalan.do/acid/postgres-operator:latest
fi

operator_image=$(docker images --filter=reference="registry.opensource.zalan.do/acid/postgres-operator" --format "{{.Repository}}:{{.Tag}}" | head -1)

# this image does not contain the tests; a container mounts them from a local "./tests" dir at start time
e2e_test_runner_image="registry.opensource.zalan.do/acid/postgres-operator-e2e-tests-runner:latest"
docker pull ${e2e_test_runner_image}
}

function start_kind(){
Expand All @@ -36,12 +35,17 @@ function start_kind(){
fi

export KUBECONFIG="${kubeconfig_path}"
kind create cluster --name ${cluster_name} --config kind-cluster-postgres-operator-e2e-tests.yaml
kind load docker-image "${operator_image}" --name ${cluster_name}
kind create cluster --name ${cluster_name} --config kind-cluster-postgres-operator-e2e-tests.yaml
docker pull "${spilo_image}"
kind load docker-image "${spilo_image}" --name ${cluster_name}
}

function load_operator_image() {
echo "Loading operator image"
export KUBECONFIG="${kubeconfig_path}"
kind load docker-image "${operator_image}" --name ${cluster_name}
}

function set_kind_api_server_ip(){
echo "Setting up kind API server ip"
# use the actual kubeconfig to connect to the 'kind' API server
Expand All @@ -52,35 +56,36 @@ function set_kind_api_server_ip(){
}

function run_tests(){
echo "Running tests..."

echo "Running tests... image: ${e2e_test_runner_image}"
# tests modify files in ./manifests, so we mount a copy of this directory done by the e2e Makefile

docker run --rm --network=host -e "TERM=xterm-256color" \
--mount type=bind,source="$(readlink -f ${kubeconfig_path})",target=/root/.kube/config \
--mount type=bind,source="$(readlink -f manifests)",target=/manifests \
--mount type=bind,source="$(readlink -f tests)",target=/tests \
--mount type=bind,source="$(readlink -f exec.sh)",target=/exec.sh \
-e OPERATOR_IMAGE="${operator_image}" "${e2e_test_runner_image}"

--mount type=bind,source="$(readlink -f scripts)",target=/scripts \
-e OPERATOR_IMAGE="${operator_image}" "${e2e_test_runner_image}" ${E2E_TEST_CASE-} $@
}

function clean_up(){
function cleanup(){
echo "Executing cleanup"
unset KUBECONFIG
kind delete cluster --name ${cluster_name}
rm -rf ${kubeconfig_path}
}

function main(){

trap "clean_up" QUIT TERM EXIT

time pull_images
time start_kind
time set_kind_api_server_ip
run_tests
echo "Entering main function..."
[[ -z ${NOCLEANUP-} ]] && trap "cleanup" QUIT TERM EXIT
pull_images
[[ ! -f ${kubeconfig_path} ]] && start_kind
load_operator_image
set_kind_api_server_ip

shift
run_tests $@
exit 0
}

"$@"
"$1" $@
7 changes: 7 additions & 0 deletions e2e/scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
kubectl delete postgresql acid-minimal-cluster
kubectl delete deployments -l application=db-connection-pooler,cluster-name=acid-minimal-cluster
kubectl delete statefulsets -l application=spilo,cluster-name=acid-minimal-cluster
kubectl delete services -l application=spilo,cluster-name=acid-minimal-cluster
kubectl delete configmap postgres-operator
kubectl delete deployment postgres-operator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be subject to a race condition where an operator is deleted earlier that it completes the clean up. That happened earlier both in this e2e pipeline and the run_operator_locally script.

2 changes: 2 additions & 0 deletions e2e/scripts/get_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
kubectl logs $(kubectl get pods -l name=postgres-operator --field-selector status.phase=Running -o jsonpath='{.items..metadata.name}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can that command be wrapped into a function so that

source e2e/scripts/get_logs.sh

would work ?

19 changes: 19 additions & 0 deletions e2e/scripts/watch_objects.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

watch -c "
kubectl get postgresql
echo
echo -n 'Rolling upgrade pending: '
kubectl get statefulset -o jsonpath='{.items..metadata.annotations.zalando-postgres-operator-rolling-update-required}'
echo
echo
kubectl get pods -o wide
echo
kubectl get statefulsets
echo
kubectl get deployments
echo
kubectl get pods -l name=postgres-operator -o jsonpath='{.items..metadata.annotations.step}'
echo
kubectl get pods -l application=spilo -o jsonpath='{.items..spec.containers..image}'
"
Loading