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

Add support for Local provider for e2e tests #668

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ install: manifests
kubectl apply -f config/crd/bases

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
.PHONY: deploy-via-kustomize
deploy-via-kustomize: manifests $(KUSTOMIZE)
kubectl apply -f config/crd/bases
kustomize build config/default | kubectl apply -f -
Expand Down
2 changes: 1 addition & 1 deletion api/validation/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

const (
name = "etcd-main"
name = "etcd-test"
namespace = "shoot--foo--bar"
uuid = "f1a38edd-e506-412a-82e6-e0fa839d0707"
provider = "aws"
Expand Down
4 changes: 4 additions & 0 deletions docs/deployment/feature-gates.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: Feature Gates in Etcd-Druid
---

# Feature Gates in Etcd-Druid

This page contains an overview of the various feature gates an administrator can specify on etcd-druid.
Expand Down
50 changes: 30 additions & 20 deletions docs/development/local-e2e-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ The following providers are supported for e2e tests:
- AWS
- Azure
- GCP
- Local

> Valid credentials need to be provided when tests happen with mentioned cloud providers.
> Valid credentials need to be provided when tests are executed with mentioned cloud providers.

## Flow

An e2e test execution involves the following steps:

| Step | Description |
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `setup` | Create a storage bucket which is used for etcd backups (only with cloud providers). |
| `deploy` | Build Docker image, upload it to registry (if remote cluster - see [Docker build](https://skaffold.dev/docs/pipeline-stages/builders/docker/)), deploy Helm chart (`charts/druid`) to Kubernetes cluster. |
| `test` | Execute e2e tests as defined in `test/e2e`. |
| `undeploy` | Remove the deployed artifacts from Kubernetes cluster. |
| `cleanup` | Delete storage bucket and Druid deployment from test cluster. |
| Step | Description |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `setup` | Create a storage bucket which is used for etcd backups (only with cloud providers). |
| `deploy` | Build Docker image, upload it to registry (if remote cluster - see [Docker build](https://skaffold.dev/docs/pipeline-stages/builders/docker/)), deploy Helm chart (`charts/druid`) to Kubernetes cluster. |
| `test` | Execute e2e tests as defined in `test/e2e`. |
| `undeploy` | Remove the deployed artifacts from Kubernetes cluster. |
| `cleanup` | Delete storage bucket and Druid deployment from test cluster. |

### Make target

Expand All @@ -62,7 +63,7 @@ make test-e2e

The following environment variables influence how the flow described above is executed:

- `PROVIDERS`: Providers used for testing (`all`, `aws`, `azure`, `gcp`). Multiple entries must be comma separated.
- `PROVIDERS`: Providers used for testing (`all`, `aws`, `azure`, `gcp`, `local`). Multiple entries must be comma separated.
> **Note**: Some tests will use very first entry from env `PROVIDERS` for e2e testing (ex: multi-node tests). So for multi-node tests to use specific provider, specify that provider as first entry in env `PROVIDERS`.
- `KUBECONFIG`: Kubeconfig pointing to cluster where Etcd-Druid will be deployed (preferably [KinD](https://kind.sigs.k8s.io)).
- `TEST_ID`: Some ID which is used to create assets for and during testing.
Expand Down Expand Up @@ -124,9 +125,24 @@ make \
test-e2e
```

### Local Env Variables

No special environment variables are required for running e2e tests with `Local` provider.

Example:

```
make \
KUBECONFIG="$HOME/.kube/config" \
PROVIDERS="local" \
TEST_ID="some-test-id" \
STEPS="setup,deploy,test,undeploy,cleanup" \
test-e2e
```

## e2e test with localstack

Above mentioned e2e tests need actual storage from cloud provider to be setup. But there is a tool named [localstack](https://docs.localstack.cloud/user-guide/aws/s3/) that enables to run e2e test with mock AWS storage. We can also provision KIND cluster for e2e tests. So, together with localstack and KIND cluster, we don't need to depend on any actual cloud provider infrastructure to be setup to run e2e tests.
The above-mentioned e2e tests need storage from real cloud providers to be setup. But there is a tool named [localstack](https://docs.localstack.cloud/user-guide/aws/s3/) that enables to run e2e test with mock AWS storage. We can also provision KIND cluster for e2e tests. So, together with localstack and KIND cluster, we don't need to depend on any actual cloud provider infrastructure to be setup to run e2e tests.

### How are the KIND cluster and localstack set up

Expand All @@ -138,13 +154,7 @@ The developer needs to run `make ci-e2e-kind` command. This command in turn runs

### How to execute e2e tests with localstack and KIND cluster

The developer just needs to install KIND following https://kind.sigs.k8s.io/docs/user/quick-start/ and start docker daemon. Additionaly, KIND cluster can be enabled via docker desktop.

Check if KIND is working on your machine by running the following command:
`kind create cluster --name kind-2`

If successful, delete the cluster by:
`kind delete cluster --name kind-2`

Run the following `make` command to perform e2e tests that will automatically take care of spinning up KIND clsuter and deploying localstack pod:
`make ci-e2e-kind`
Run the following `make` command to spin up a KinD cluster, deploy localstack and run the e2e tests with provider `aws`:
```
make ci-e2e-kind
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:

set -e

source /var/lib/infra/data/common/common.sh
source "/var/lib/infra/data/common/common.sh"

setup_aws
configure_aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:

set -e

source /var/lib/infra/data/common/common.sh
source "/var/lib/infra/data/common/common.sh"

setup_azcli
delete_azure_bucket
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:

set -e

source /var/lib/infra/data/common/common.sh
source "/var/lib/infra/data/common/common.sh"

setup_gcloud
configure_gcloud
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: run-script
data:
run.sh: |-
#!/usr/bin/env bash

set -e

source "/var/lib/infra/data/common/common.sh"

delete_local_bucket
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../common

patchesStrategicMerge:
- configmap-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
#
# Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

MOUNT_PATH="/host-dir-etc"
HOST_PATH="/etc"
BACKUP_BUCKETS_DIR="gardener/local-backupbuckets"

function create_local_bucket() {
echo "Creating Local bucket ${TEST_ID} at host directory ${HOST_PATH}/${BACKUP_BUCKETS_DIR} ."
mkdir -p "${MOUNT_PATH}/${BACKUP_BUCKETS_DIR}/${TEST_ID}"
echo "Successfully created Local bucket ${TEST_ID} at host directory ${HOST_PATH}/${BACKUP_BUCKETS_DIR} ."
}

function delete_local_bucket() {
echo "About to delete Local bucket ${TEST_ID} from host directory ${HOST_PATH}/${BACKUP_BUCKETS_DIR} ."
rm -rf "${MOUNT_PATH:?}/${BACKUP_BUCKETS_DIR}/${TEST_ID}"
echo "Successfully deleted Local bucket ${TEST_ID} from host directory ${HOST_PATH}/${BACKUP_BUCKETS_DIR} ."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: batch/v1
kind: Job
metadata:
name: infra-job
spec:
template:
spec:
containers:
- name: infra
envFrom:
- secretRef:
name: infra-secret
volumeMounts:
- name: common
mountPath: /var/lib/infra/data/common
- name: host-dir
mountPath: /host-dir-etc
volumes:
- name: common
configMap:
name: infra-common
defaultMode: 0755
- name: host-dir
hostPath:
path: /etc
type: Directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namePrefix: local-

resources:
- ../../../base

generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- name: infra-common
files:
- ./files/common.sh

secretGenerator:
- name: infra-secret
envs:
- local.env

patchesStrategicMerge:
- job-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST_ID
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: run-script
data:
run.sh: |-
#!/usr/bin/env bash

set -e

source "/var/lib/infra/data/common/common.sh"

create_local_bucket
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../common

patchesStrategicMerge:
- configmap-patch.yaml
25 changes: 24 additions & 1 deletion hack/e2e-test/run-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ function setup_gcp_e2e {
setup_e2e
}

function usage_local {
cat <<EOM
Usage:
run-e2e-test.sh local

Please make sure the following environment variables are set:

TEST_ID ID of the test, used for test objects and assets.
EOM
exit 0
}

function setup_local_e2e {
[[ -z ${TEST_ID:=""} ]] && usage_local

profile_setup="local-setup"
profile_cleanup="local-cleanup"
setup_e2e
}

: ${INFRA_PROVIDERS:=""}
: ${STEPS:="setup,deploy,test,undeploy,cleanup"}
: ${cleanup_done:="false"}
Expand All @@ -199,7 +219,7 @@ export INFRA_PROVIDERS=${1}
for p in ${1//,/ }; do
case $p in
all)
export INFRA_PROVIDERS="aws,azure,gcp"
export INFRA_PROVIDERS="aws,azure,gcp,local"
setup_aws_e2e
setup_azure_e2e
setup_gcp_e2e
Expand All @@ -213,6 +233,9 @@ for p in ${1//,/ }; do
gcp)
setup_gcp_e2e
;;
local)
setup_local_e2e
;;
*)
echo "Provider ${1} is not supported."
;;
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/etcd/statefulset/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var (
autoCompactionRetention = "2m"
quota = resource.MustParse("8Gi")
prefix = "/tmp"
volumeClaimTemplateName = "etcd-main"
volumeClaimTemplateName = "etcd-test"
garbageCollectionPolicy = druidv1alpha1.GarbageCollectionPolicy(druidv1alpha1.GarbageCollectionPolicyExponential)
metricsBasic = druidv1alpha1.Basic
etcdSnapshotTimeout = metav1.Duration{
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
var _ = Describe("Image retrieval tests", func() {

const (
etcdName = "etcd-main-0"
etcdName = "etcd-test-0"
namespace = "default"
)
var (
Expand Down
20 changes: 16 additions & 4 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ profiles:
- op: add
path: /deploy/kustomize/paths
value: [hack/e2e-test/infrastructure/overlays/aws/setup]
- name: aws-cleanup
# Profile to delete the S3 backup bucket from an e2e test.
- name: aws-cleanup
patches:
- op: add
path: /deploy/kustomize/paths
Expand All @@ -85,8 +85,8 @@ profiles:
- op: add
path: /deploy/kustomize/paths
value: [hack/e2e-test/infrastructure/overlays/azure/setup]
- name: azure-cleanup
# Profile to delete the Azure storage container from an e2e test.
- name: azure-cleanup
patches:
- op: add
path: /deploy/kustomize/paths
Expand All @@ -108,8 +108,8 @@ profiles:
"os": [darwin, linux]
}
}
# Profile to delete the GCP backup bucket from an e2e test.
- name: gcp-cleanup
# Profile to delete the GCP backup bucket from an e2e test.
patches:
- op: add
path: /deploy/kustomize/paths
Expand All @@ -124,4 +124,16 @@ profiles:
cp "$GCP_SERVICEACCOUNT_JSON_PATH" "hack/e2e-test/infrastructure/overlays/gcp/common/assets/serviceaccount.json"'],
"os": [darwin, linux]
}
}
}
# Profile to create the required Local storage container for an e2e test.
- name: local-setup
patches:
- op: add
path: /deploy/kustomize/paths
value: [hack/e2e-test/infrastructure/overlays/local/setup]
# Profile to delete the Local storage container from an e2e test.
- name: local-cleanup
patches:
- op: add
path: /deploy/kustomize/paths
value: [hack/e2e-test/infrastructure/overlays/local/cleanup]
Loading