Skip to content

Commit a77cbef

Browse files
fix: fix the e2e test script for fluentd (#1791)
* fix the scripts Signed-off-by: Chengwei Guo <[email protected]> * change version back to latest for master Signed-off-by: Chengwei Guo <[email protected]> * fix the outdated syntax Signed-off-by: Chengwei Guo <[email protected]> * directly run ginkgo Signed-off-by: Chengwei Guo <[email protected]> * fix e2e tests Signed-off-by: chengweiguo <[email protected]> * fix main workflow Signed-off-by: chengweiguo <[email protected]> * refactor fix lint issue Signed-off-by: chengweiguo <[email protected]> * Apply suggestions from code review Signed-off-by: Marco Franssen <[email protected]> * use defer to always run cleanup Signed-off-by: chengweiguo <[email protected]> * Makefile: Improve e2e-tests by utilizing make tasks * fix: Helm e2e Signed-off-by: Marco Franssen <[email protected]> --------- Signed-off-by: Chengwei Guo <[email protected]> Signed-off-by: chengweiguo <[email protected]> Signed-off-by: Marco Franssen <[email protected]> Co-authored-by: Marco Franssen <[email protected]>
1 parent d9775e4 commit a77cbef

File tree

12 files changed

+260
-227
lines changed

12 files changed

+260
-227
lines changed

.github/workflows/helm-ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
version: ${{ env.HELM_VERSION }}
5151

5252
- name: Install dependences
53-
run: make ginkgo kind
53+
run: make kind ginkgo setup-test-e2e
5454

5555
- name: Run helm e2e tests
56-
run: make helm-e2e
56+
run: make fluentd_helm-e2e

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
run: make ginkgo kind
115115

116116
- name: Run e2e tests
117-
run: make e2e
117+
run: make test-e2e
118118

119119
build:
120120
runs-on: ubuntu-22.04

.github/workflows/test-e2e.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ jobs:
1616
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
1717
with:
1818
go-version-file: go.mod
19+
cache-dependency-path: go.sum
1920

20-
- name: Install the latest version of kind
21-
run: |
22-
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
23-
chmod +x ./kind
24-
sudo mv ./kind /usr/local/bin/kind
21+
- name: Install dependences
22+
run: make kind ginkgo setup-test-e2e
2523

2624
- name: Verify kind installation
2725
run: kind version

Makefile

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +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:
82-
go test ./tests/e2e/ -v -ginkgo.v
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); export PATH="$$PWD/bin:$$PATH"; tests/scripts/$*_e2e.sh
83100

84101
.PHONY: lint
85102
lint: golangci-lint ## Run golangci-lint linter
@@ -231,7 +248,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
231248

232249
.PHONY: setup-envtest
233250
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
234-
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
251+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)"
235252
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
236253
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
237254
exit 1; \
@@ -257,28 +274,8 @@ code-generator: $(CODE_GENERATOR) ## Download code-generator locally if necessar
257274
$(CODE_GENERATOR): $(LOCALBIN)
258275
$(call go-install-tool,$(CODE_GENERATOR),k8s.io/code-generator,$(CODE_GENERATOR_VERSION))
259276

260-
KIND_CLUSTER ?= fluent-operator-test-e2e
261-
262-
.PHONY: setup-test-e2e
263-
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
264-
@command -v $(KIND) >/dev/null 2>&1 || { \
265-
echo "Kind is not installed. Please install Kind manually."; \
266-
exit 1; \
267-
}
268-
@case "$$($(KIND) get clusters)" in \
269-
*"$(KIND_CLUSTER)"*) \
270-
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
271-
*) \
272-
echo "Creating Kind cluster '$(KIND_CLUSTER)'..."; \
273-
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
274-
esac
275-
276-
.PHONY: cleanup-test-e2e
277-
cleanup-test-e2e:
278-
$(KIND) delete cluster --name $(KIND_CLUSTER)
279-
280277
.PHONY: kind
281-
kind: $(KIND) ## Download code-generator locally if necessary.
278+
kind: $(KIND) ## Install kind locally if necessary.
282279
$(KIND): $(LOCALBIN)
283280
$(call go-install-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))
284281

@@ -376,12 +373,6 @@ go-deps: # download go dependencies
376373
docs-update: # update api docs
377374
go run ./cmd/doc-gen/main.go
378375

379-
e2e: ginkgo # make e2e tests
380-
tests/scripts/fluentd_e2e.sh
381-
382-
helm-e2e: ginkgo # make helm e2e tests
383-
tests/scripts/fluentd_helm_e2e.sh
384-
385376
update-helm-package: # update helm repo
386377
./hack/update-helm-package.sh
387378

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.5.0
1+
latest
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<source>
2+
@type forward
3+
bind 0.0.0.0
4+
port 24224
5+
</source>
6+
<match **>
7+
@id main
8+
@type label_router
9+
<route>
10+
@label @5789d57841808bf91cfb0ed603d9ee86
11+
<match>
12+
namespaces fluent
13+
</match>
14+
</route>
15+
</match>
16+
<label @5789d57841808bf91cfb0ed603d9ee86>
17+
<filter **>
18+
@id FluentdConfig-fluent-fluentd-config-label-selector-test::fluent::filter::test-filter-recordtransformer-0
19+
@type record_transformer
20+
<record>
21+
environment testing
22+
hostname test-host
23+
</record>
24+
</filter>
25+
<match **>
26+
@id FluentdConfig-fluent-fluentd-config-label-selector-test::fluent::output::test-output-stdout-0
27+
@type stdout
28+
</match>
29+
</label>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<source>
2+
@type forward
3+
bind 0.0.0.0
4+
port 24224
5+
</source>
6+
<match **>
7+
@id main
8+
@type label_router
9+
<route>
10+
@label @7d670e99fb44ef7d003c936b2c226ac3
11+
<match>
12+
namespaces fluent
13+
</match>
14+
</route>
15+
</match>
16+
<label @7d670e99fb44ef7d003c936b2c226ac3>
17+
<filter **>
18+
@id FluentdConfig-fluent-fluentd-config-filter-only::fluent::filter::test-filter-grep-0
19+
@type grep
20+
<regexp>
21+
key level
22+
pattern /error/
23+
</regexp>
24+
</filter>
25+
<match **>
26+
@id FluentdConfig-fluent-fluentd-config-filter-only::cluster::clusteroutput::cluster-output-stdout-filter-test-0
27+
@type stdout
28+
</match>
29+
</label>

tests/e2e/fluentd/cfgrender_suite_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fluentd
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"testing"
@@ -22,7 +23,7 @@ var k8sClient client.Client
2223
func TestCompareFluentdMainAppConfig(t *testing.T) {
2324
RegisterFailHandler(Fail)
2425

25-
BeforeSuite(func() {
26+
BeforeSuite(func(ctx context.Context) {
2627
path := os.Getenv("TESTCONFIG")
2728
if path == "" {
2829
path = fmt.Sprintf("%s/.kube/config", os.Getenv("HOME"))
@@ -46,7 +47,7 @@ func TestCompareFluentdMainAppConfig(t *testing.T) {
4647
Expect(k8sClient).NotTo(BeNil())
4748

4849
_, _ = fmt.Fprintf(GinkgoWriter, "%s: Info: Setup Suite Execution\n", time.Now().Format(time.StampMilli))
49-
}, 60)
50+
}, NodeTimeout(60*time.Second))
5051

5152
AfterSuite(func() {
5253
By("After Suite Execution")

0 commit comments

Comments
 (0)