Skip to content

Commit 06ec42b

Browse files
Enable e2e tests with cloud provider emulators for aws,gcp,azure (#743)
* Make e2e tests functional * Provide support to run them with major cloud providers & their emulators * Upgrade helm pkg `k8.io/helm/v2` to `helm.sh/helm/v3`
1 parent 36392b4 commit 06ec42b

File tree

1,743 files changed

+382118
-13737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,743 files changed

+382118
-13737
lines changed

.ci/integration_test

+2-77
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ function run_test_as_processes() {
276276
setup_test_cluster
277277

278278
echo "Starting integration tests..."
279-
cd test/e2e/integration
279+
cd test/integration
280280

281281
set +e
282282
ginkgo -r -mod=vendor
@@ -295,81 +295,6 @@ function run_test_as_processes() {
295295
fi
296296
}
297297

298-
function run_test_on_cluster() {
299-
if ! [ -x "$(command -v ginkgo)" ]; then
300-
setup_ginkgo
301-
fi
302-
303-
export TEST_ID=${STORAGE_CONTAINER}
304-
if [ "$STORAGE_CONTAINER" == "" ]; then
305-
setup_awscli
306-
get_test_id
307-
setup-aws-infrastructure
308-
fi
309-
310-
# TODO: change the etcd wrapper version to a newer version which spawns etcd v3.4.34
311-
export ETCD_WRAPPER_VERSION=${ETCD_WRAPPER_VERSION:-"v0.2.0"}
312-
echo "etcd-wrapper version: ${ETCD_WRAPPER_VERSION}"
313-
314-
export ETCDBR_VERSION=${ETCDBR_VERSION:-${ETCDBR_VER:-"v0.12.1"}}
315-
echo "etcd-backup-restore version: ${ETCDBR_VERSION}"
316-
317-
echo "Starting integration tests on k8s cluster."
318-
319-
set +e
320-
321-
if [ -r "$INTEGRATION_TEST_KUBECONFIG" ]; then
322-
KUBECONFIG=$INTEGRATION_TEST_KUBECONFIG STORAGE_CONTAINER=$TEST_ID ginkgo -v -timeout=15m -mod=vendor test/e2e/integrationcluster
323-
TEST_RESULT=$?
324-
echo "Successfully completed all tests."
325-
else
326-
echo "Invalid kubeconfig for integration test $INTEGRATION_TEST_KUBECONFIG"
327-
TEST_RESULT=255
328-
fi
329-
330-
set -e
331-
332-
echo "Done with integration test on k8s cluster."
333-
334-
if [ "$STORAGE_CONTAINER" == "" ]; then
335-
echo "Deleting test bucket..."
336-
cleanup-aws-infrastructure
337-
fi
338-
}
339-
340-
function run_test_on_tm() {
341-
if [ "$ACCESS_KEY_ID" == "" ] || [ "$SECRET_ACCESS_KEY_B64" == "" ] || [ "$AWS_REGION" == "" ] ; then
342-
echo "AWS S3 credentials unavailable. Exiting."
343-
exit 1
344-
fi
345-
export SECRET_ACCESS_KEY=`echo $SECRET_ACCESS_KEY_B64 | base64 -d`
346-
export REGION=$AWS_REGION
347-
348-
get_tm_test_id
349-
export STORAGE_CONTAINER=$TEST_ID
350-
export ETCDBR_VER=$EFFECTIVE_VERSION
351-
352-
setup_awscli
353-
write_aws_secret "${ACCESS_KEY_ID}" "${SECRET_ACCESS_KEY}" "${REGION}"
354-
create_s3_bucket
355-
356-
export INTEGRATION_TEST_KUBECONFIG=$TM_KUBECONFIG_PATH/shoot.config
357-
echo "Starting integration tests on TM cluster $PROJECT_NAMESPACE/$SHOOT_NAME."
358-
run_test_on_cluster
359-
echo "Done with integration test on TM cluster."
360-
cleanup-aws-infrastructure
361-
}
362-
363-
case $1 in
364-
tm)
365-
run_test_on_tm
366-
;;
367-
cluster)
368-
run_test_on_cluster
369-
;;
370-
*)
371-
run_test_as_processes
372-
;;
373-
esac
298+
run_test_as_processes
374299

375300
exit $TEST_RESULT

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
# Build Binaries
2020
bin
21+
hack/tools/bin
2122
test/output
2223
test/e2e_test_data
2324
default.bkp*
@@ -28,6 +29,9 @@ compctedsnap.bkp*
2829
.vscode
2930
.idea/
3031

32+
# kubeconfig
33+
hack/e2e-test/infrastructure/kind/kubeconfig
34+
3135
# developers workspace
3236
tmp
3337
dev

Makefile

+45-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
VERSION ?= $(shell cat VERSION)
6+
REPO_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")
67
REGISTRY ?= europe-docker.pkg.dev/gardener-project/snapshots
78
IMAGE_REPOSITORY := $(REGISTRY)/gardener/etcdbrctl
89
IMAGE_TAG := $(VERSION)
@@ -11,10 +12,11 @@ PLATFORM ?= $(shell docker info --format '{{.OSType}}/{{.Architecture
1112
BIN_DIR := bin
1213
COVERPROFILE := test/output/coverprofile.out
1314
IMG ?= ${IMAGE_REPOSITORY}:${IMAGE_TAG}
15+
KUBECONFIG_PATH :=$(REPO_ROOT)/hack/e2e-test/infrastructure/kind/kubeconfig
1416

1517
.DEFAULT_GOAL := build-local
1618

17-
include hack/tools.mk
19+
include $(REPO_ROOT)/hack/tools.mk
1820

1921
.PHONY: revendor
2022
revendor:
@@ -26,6 +28,8 @@ update-dependencies:
2628
@env go get -u
2729
@make revendor
2830

31+
kind-up kind-down ci-e2e-kind ci-e2e-kind-aws ci-e2e-kind-azure ci-e2e-kind-gcp: export KUBECONFIG = $(KUBECONFIG_PATH)
32+
2933
.PHONY: build
3034
build:
3135
@.ci/build
@@ -74,11 +78,47 @@ perf-regression-test:
7478
integration-test:
7579
@.ci/integration_test
7680

77-
.PHONY: integration-test-cluster
78-
integration-test-cluster:
79-
@.ci/integration_test cluster
80-
8181
.PHONY: show-coverage
8282
show-coverage:
8383
@if [ ! -f $(COVERPROFILE) ]; then echo "$(COVERPROFILE) is not yet built. Please run 'COVER=true make test'"; false; fi
8484
@go tool cover -html $(COVERPROFILE)
85+
86+
.PHONY: test-e2e
87+
test-e2e: $(KIND) $(HELM) $(GINKGO) $(KUBECTL)
88+
@"$(REPO_ROOT)/hack/e2e-test/run-e2e-test.sh" $(PROVIDERS) $(KUBECONFIG)
89+
90+
.PHONY: kind-up
91+
kind-up: $(KIND)
92+
./hack/kind-up.sh
93+
94+
.PHONY: kind-down
95+
kind-down: $(KIND)
96+
kind delete cluster --name etcdbr-e2e
97+
98+
.PHONY: deploy-localstack
99+
deploy-localstack: $(KUBECTL)
100+
./hack/deploy-localstack.sh $(KUBECONFIG)
101+
102+
.PHONY: deploy-fakegcs
103+
deploy-fakegcs: $(KUBECTL)
104+
./hack/deploy-fakegcs.sh $(KUBECONFIG)
105+
106+
.PHONY: deploy-azurite
107+
deploy-azurite: $(KUBECTL)
108+
./hack/deploy-azurite.sh $(KUBECONFIG)
109+
110+
.PHONY: ci-e2e-kind
111+
ci-e2e-kind:
112+
./hack/ci-e2e-kind.sh $(PROVIDERS)
113+
114+
.PHONY: ci-e2e-kind-aws
115+
ci-e2e-kind-aws:
116+
./hack/ci-e2e-kind.sh aws
117+
118+
.PHONY: ci-e2e-kind-azure
119+
ci-e2e-kind-azure:
120+
./hack/ci-e2e-kind.sh azure
121+
122+
.PHONY: ci-e2e-kind-gcp
123+
ci-e2e-kind-gcp:
124+
./hack/ci-e2e-kind.sh gcp

chart/etcd-backup-restore/templates/etcd-backup-secret.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ data:
1414
region: {{ .Values.backup.s3.region | b64enc }}
1515
secretAccessKey: {{ .Values.backup.s3.secretAccessKey | b64enc }}
1616
accessKeyID: {{ .Values.backup.s3.accessKeyID | b64enc }}
17+
{{- if .Values.backup.s3.s3ForcePathStyle }}
1718
s3ForcePathStyle: {{ .Values.backup.s3.s3ForcePathStyle | b64enc}}
19+
{{- end }}
1820
{{- if .Values.backup.s3.endpoint }}
1921
endpoint: {{ .Values.backup.s3.endpoint | b64enc }}
2022
{{- end }}

chart/etcd-backup-restore/templates/etcd-statefulset.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ spec:
350350
- name: local-backup
351351
hostPath:
352352
path: {{ .Values.backup.local.path }}/{{ .Values.backup.storageContainer }}
353-
type: Directory
353+
type: DirectoryOrCreate
354354
{{- else }}
355355
- name: etcd-backup
356356
secret:
@@ -366,3 +366,4 @@ spec:
366366
resources:
367367
requests:
368368
storage: {{ .Values.storageCapacity }}
369+

docs/development/testing_and_dependencies.md

+4-13
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,15 @@ By default, we run tests without computing code coverage. To get the code covera
3333

3434
### Integration tests
3535

36-
You can also run integration tests for etcd-backup-restore on any given Kubernetes cluster. The test creates namespace `integration-test` on the cluster and deploys the [etcd-backup-restore helm chart](../../chart/etcd-backup-restore) which in turn deploys the required secrets, configmap, services and finally the statefulset which contains the pod that runs etcd and backup-restore as a sidecar.
36+
Integration tests are process based tests i.e spins up `etcd` and `etcdbr` as processes and runs the tests to check the functionality. The tests expect that the AWS credentials are present in the `$HOME/.aws` directory. Make sure to provide the correct credentials before running the tests.
3737

3838
```sh
39-
make integration-test-cluster
39+
make integration-test
4040
```
4141

42-
:warning: Prerequisite for this command is to set the following environment variables:
43-
44-
- INTEGRATION_TEST_KUBECONFIG: kubeconfig to the cluster on which you wish to run the test
45-
<!-- TODO: change the etcd wrapper version to a newer version which spawns etcd v3.4.34 -->
46-
- ETCD_WRAPPER_VERSION: optional, defaults to `v0.2.0`
47-
- ETCDBR_VERSION: optional, defaults to `v0.12.1`
48-
- ACCESS_KEY_ID: S3 credentials
49-
- SECRET_ACCESS_KEY: S3 credentials
50-
- REGION: S3 credentials
51-
- STORAGE_CONTAINER: S3 bucket name
42+
### E2E tests
5243

53-
If you have a working setup of [TestMachinery](https://github.com/gardener/test-infra), you can run the integration tests on a TM-generated cluster as well.
44+
The e2e tests for etcd-backup-restore are cluster-based tests located in the test/e2e package, run on Kubernetes clusters using both emulators and real cloud providers (AWS, GCP, Azure). These tests deploy the etcd-backup-restore helm chart to verify full functionality in various environments.
5445

5546
### Performance regression tests
5647

docs/development/tests.md

+84
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,94 @@ Integration tests include the basic working of:
1818
- **data validation**: corrupted etcd data should be marked for deletion and restoration should be triggered
1919
- **restoration**: etcd data should be restored correctly from latest set of snapshots (full + deltas)
2020

21+
**Note**: The tests expects that the aws credentials are present in the `$HOME/.aws` directory. Make sure to provide the correct credentials before running the tests.
22+
23+
These tests can be run locally with both `etcd` and `etcdbr` running as processes. To execute the tests, run the following command:
24+
25+
```sh
26+
make integration-test
27+
```
28+
2129
### Unit tests
2230

2331
Each package within this repo contains its own set of unit tests to test the functionality of the methods contained within the packages.
2432

2533
### Performance regression tests
2634

2735
These tests help check any regression in performance in terms of memory consumption and CPU utilization.
36+
37+
### End-to-end tests
38+
39+
The e2e tests for etcd-backup-restore are cluster based tests located in the `test/e2e` package. These tests are run on a Kubernetes cluster and test the full functionality of etcd-backup-restore. The tests create a provider namespace on the cluster and deploy the [etcd-backup-restore helm chart](../../chart/etcd-backup-restore) which in turn deploys the required secrets, configmap, services and finally the statefulset which deploys the pod that runs etcd and backup-restore as a sidecar.
40+
41+
These tests are setup to be run with both emulators and real cloud providers. The emulators can be used for local development and testing as well as running jobs to test code changes when a PR is raised. The real cloud providers can be used for testing in a real cloud environment to ensure that the changes work as expected in an actual environment.
42+
43+
Currently, the tests can be run using the following cloud providers:
44+
45+
- AWS
46+
- GCP
47+
- Azure
48+
49+
#### Running the e2e tests with the emulators
50+
51+
##### On a Kind Cluster
52+
53+
To run the e2e tests with the emulators, run the following command:
54+
55+
```sh
56+
make ci-e2e-kind PROVIDERS="{providers}"
57+
```
58+
59+
By default, when no provider is specified, the tests are run using AWS emulator i.e Localstack as storage provider. The provider can be specified as comma separated values of the cloud providers mentioned above in small case. For example, to run the tests on AWS and GCP, run the following command:
60+
61+
```sh
62+
make ci-e2e-kind PROVIDERS="aws,gcp"
63+
```
64+
65+
##### On any Kubernetes Cluster
66+
67+
The e2e tests can also be run on any other cluster by running the following command:
68+
69+
> **_NOTE:_** If using emulators for e2e tests, make sure to port-forward the snapstore service to the local machine before running the tests.
70+
71+
- For AWS: `kubectl port-forward service/localstack 4566:4566`
72+
- For GCP: `kubectl port-forward service/fake-gcs 4443:4443 8000:8000`
73+
- For Azure: `kubectl port-forward service/azurite 10000:10000`
74+
75+
```sh
76+
make test-e2e PROVIDERS="{providers}" KUBECONFIG="{path-to-kubeconfig}"
77+
```
78+
79+
#### Running the e2e tests with real cloud providers
80+
81+
To run the tests with real cloud providers, the required credentials need to be set as environment variables before running the tests. See the below sections for the required environment variables for each cloud provider. To test with multiple providers, set the required environment variables for each provider.
82+
83+
##### Set the required environment variables
84+
85+
- AWS:
86+
- `AWS_ACCESS_KEY_ID`
87+
- `AWS_SECRET_ACCESS_KEY`
88+
- `AWS_DEFAULT_REGION`
89+
90+
- GCP:
91+
- `GOOGLE_APPLICATION_CREDENTIALS`
92+
- `GCP_PROJECT_ID`
93+
94+
- Azure:
95+
- `STORAGE_ACCOUNT`
96+
- `STORAGE_KEY`
97+
98+
##### Run the tests
99+
100+
To run the tests with a kind cluster, run the following command:
101+
102+
```sh
103+
make ci-e2e-kind PROVIDERS="{providers}"
104+
```
105+
106+
To run the tests on any other cluster, run the following command:
107+
108+
```sh
109+
make test-e2e PROVIDERS="{providers}" KUBECONFIG="{path-to-kubeconfig}"
110+
```
111+

0 commit comments

Comments
 (0)