Skip to content

Commit e03751e

Browse files
committed
Makefile: Improve e2e-tests by utilizing make tasks
1 parent 8a37684 commit e03751e

File tree

3 files changed

+44
-54
lines changed

3 files changed

+44
-54
lines changed

Makefile

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,27 @@ vet: ## Run go vet against code.
7676
test: manifests generate fmt vet setup-envtest ## Run tests.
7777
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
7878

79-
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
80-
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
81-
test-e2e: fluentd-e2e
79+
KIND_CLUSTER ?= fluent-operator-test-e2e
80+
81+
.PHONY: setup-test-e2e
82+
setup-test-e2e: $(KIND) ## Set up a Kind cluster for e2e tests if it does not exist
83+
@case "$$($(KIND) get clusters)" in \
84+
*"$(KIND_CLUSTER)"*) \
85+
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
86+
*) \
87+
echo "Creating Kind cluster '$(KIND_CLUSTER)'…"; \
88+
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
89+
esac
90+
91+
.PHONY: cleanup-test-e2e
92+
cleanup-test-e2e:
93+
$(KIND) delete cluster --name $(KIND_CLUSTER)
94+
95+
.PHONY: test-e2e
96+
test-e2e: setup-test-e2e fluentd-e2e ## Run the e2e tests against a Kind k8s instance that is spun up.
97+
98+
%-e2e: ginkgo
99+
@export KIND_CLUSTER=$(KIND_CLUSTER); tests/scripts/$*_e2e.sh
82100

83101
.PHONY: lint
84102
lint: golangci-lint ## Run golangci-lint linter
@@ -230,7 +248,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
230248

231249
.PHONY: setup-envtest
232250
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
233-
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
251+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)"
234252
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
235253
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
236254
exit 1; \
@@ -256,26 +274,6 @@ code-generator: $(CODE_GENERATOR) ## Download code-generator locally if necessar
256274
$(CODE_GENERATOR): $(LOCALBIN)
257275
$(call go-install-tool,$(CODE_GENERATOR),k8s.io/code-generator,$(CODE_GENERATOR_VERSION))
258276

259-
KIND_CLUSTER ?= fluent-operator-test-e2e
260-
261-
.PHONY: setup-test-e2e
262-
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
263-
@command -v $(KIND) >/dev/null 2>&1 || { \
264-
echo "Kind is not installed. Please install Kind manually."; \
265-
exit 1; \
266-
}
267-
@case "$$($(KIND) get clusters)" in \
268-
*"$(KIND_CLUSTER)"*) \
269-
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
270-
*) \
271-
echo "Creating Kind cluster '$(KIND_CLUSTER)'..."; \
272-
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
273-
esac
274-
275-
.PHONY: cleanup-test-e2e
276-
cleanup-test-e2e:
277-
$(KIND) delete cluster --name $(KIND_CLUSTER)
278-
279277
.PHONY: kind
280278
kind: $(KIND) ## Download code-generator locally if necessary.
281279
$(KIND): $(LOCALBIN)
@@ -375,12 +373,6 @@ go-deps: # download go dependencies
375373
docs-update: # update api docs
376374
go run ./cmd/doc-gen/main.go
377375

378-
fluentd-e2e: ginkgo # make e2e tests
379-
tests/scripts/fluentd_e2e.sh
380-
381-
fluentd-helm-e2e: ginkgo # make helm e2e tests
382-
tests/scripts/fluentd_helm_e2e.sh
383-
384376
update-helm-package: # update helm repo
385377
./hack/update-helm-package.sh
386378

tests/scripts/fluentd_e2e.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LOGGING_NAMESPACE="fluent"
1414
IMAGE_TAG="$(date "+%Y-%m-%d-%H-%M-%S")"
1515
VERSION="$(tr -d " \t\n\r" < VERSION)"
1616
IMAGE_NAME="ghcr.io/fluent/fluent-operator/fluent-operator"
17+
KIND_CLUSTER="${KIND_CLUSTER:-fluent-operator-test-e2e}"
1718

1819
GINKGO_BIN="ginkgo"
1920
if [ -f "$PROJECT_ROOT/bin/ginkgo" ]; then
@@ -29,32 +30,29 @@ function build_ginkgo_test() {
2930
# shellcheck disable=SC2329
3031
function cleanup() {
3132
local exit_code=$?
32-
33+
3334
if [ "${SKIP_CLEANUP:-false}" == "true" ]; then
3435
echo "Skipping cleanup as requested."
3536
exit "$exit_code"
3637
fi
3738

38-
echo "Cleaning up..."
39+
echo "Cleaning up"
3940
pushd "$PROJECT_ROOT" >/dev/null || true
40-
# kubectl delete -f manifests/setup/setup.yaml
41-
# kubectl delete ns $LOGGING_NAMESPACE
42-
kind delete cluster --name test || true
41+
make cleanup-test-e2e KIND_CLUSTER="$KIND_CLUSTER"
4342
popd >/dev/null || true
4443
}
4544

4645
function prepare_cluster() {
47-
kind create cluster --name test
4846
kubectl create ns "$LOGGING_NAMESPACE"
4947

50-
echo "wait the control-plane ready..."
51-
kubectl wait --for=condition=Ready node/test-control-plane --timeout=60s
48+
echo "wait the control-plane ready"
49+
kubectl wait --for=condition=Ready "node/${KIND_CLUSTER}-control-plane" --timeout=60s
5250
}
5351

5452
function build_image() {
5553
pushd "$PROJECT_ROOT" >/dev/null
5654
make build-op-amd64 -e "FO_IMG=$IMAGE_NAME:$IMAGE_TAG"
57-
kind load docker-image "$IMAGE_NAME:$IMAGE_TAG" --name test
55+
kind load docker-image "$IMAGE_NAME:$IMAGE_TAG" --name "$KIND_CLUSTER"
5856
popd >/dev/null
5957
}
6058

@@ -79,19 +77,19 @@ function run_test() {
7977
function main() {
8078
trap cleanup EXIT
8179

82-
echo -e "\nBuilding testcases..."
80+
echo -e "\nBuilding testcases"
8381
build_ginkgo_test
8482

85-
echo -e "\nPreparing cluster..."
83+
echo -e "\nPreparing cluster"
8684
prepare_cluster
8785

88-
echo -e "\nBuilding image..."
86+
echo -e "\nBuilding image"
8987
build_image
9088

91-
echo -e "\nStart fluent operator..."
89+
echo -e "\nStart fluent operator"
9290
start_fluent_operator
9391

94-
echo -e "\nRunning test..."
92+
echo -e "\nRunning test"
9593
run_test
9694
}
9795

tests/scripts/fluentd_helm_e2e.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PROJECT_ROOT=$PWD
66
E2E_DIR=$(realpath "$(dirname "$0")/..")
77
LOGGING_NAMESPACE=fluent
88
IMAGE_TAG=$(date "+%Y-%m-%d-%H-%M-%S")
9+
KIND_CLUSTER="${KIND_CLUSTER:-fluent-operator-test-e2e}"
910

1011
function build_ginkgo_test() {
1112
ginkgo build -r e2e/fluentd/
@@ -18,25 +19,24 @@ function cleanup() {
1819
# helm uninstall fluent-operator -n $LOGGING_NAMESPACE
1920
# kubectl delete ns $LOGGING_NAMESPACE
2021
# shellcheck disable=SC2317
21-
kind delete cluster --name test-helm
22+
kind delete cluster --name "$KIND_CLUSTER"
2223
# shellcheck disable=SC2317
2324
popd >/dev/null
2425
# shellcheck disable=SC2317
2526
exit 0
2627
}
2728

2829
function prepare_cluster() {
29-
kind create cluster --name test-helm
3030
kubectl create ns $LOGGING_NAMESPACE
3131

32-
echo "wait the control-plane ready..."
33-
kubectl wait --for=condition=Ready node/test-helm-control-plane --timeout=60s
32+
echo "wait the control-plane ready"
33+
kubectl wait --for=condition=Ready "node/${KIND_CLUSTER}-control-plane" --timeout=60s
3434
}
3535

3636
function build_image() {
3737
pushd "$PROJECT_ROOT" >/dev/null
3838
make build-op-amd64 -e "FO_IMG=kubesphere/fluent-operator:$IMAGE_TAG"
39-
kind load docker-image "kubesphere/fluent-operator:$IMAGE_TAG" --name test-helm
39+
kind load docker-image "kubesphere/fluent-operator:$IMAGE_TAG" --name "$KIND_CLUSTER"
4040
popd >/dev/null
4141
}
4242

@@ -74,19 +74,19 @@ function run_test() {
7474
set -Ee
7575
trap cleanup EXIT ERR
7676

77-
echo -e "\nBuilding testcases..."
77+
echo -e "\nBuilding testcases"
7878
pushd "$E2E_DIR" >/dev/null
7979
build_ginkgo_test
8080
popd >/dev/null
8181

82-
echo -e "\nPreparing cluster..."
82+
echo -e "\nPreparing cluster"
8383
prepare_cluster
8484

85-
echo -e "\nBuilding image..."
85+
echo -e "\nBuilding image"
8686
build_image
8787

88-
echo -e "\nStart fluent operator..."
88+
echo -e "\nStart fluent operator"
8989
start_fluent_operator
9090

91-
echo -e "\nRunning test..."
91+
echo -e "\nRunning test"
9292
run_test

0 commit comments

Comments
 (0)