Skip to content

Commit c6bf75d

Browse files
committed
fix e2e tests
Signed-off-by: chengweiguo <[email protected]>
1 parent d647fa0 commit c6bf75d

File tree

6 files changed

+82
-44
lines changed

6 files changed

+82
-44
lines changed

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
7878

7979
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
8080
.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
81+
test-e2e: fluentd-e2e
8382

8483
.PHONY: lint
8584
lint: golangci-lint ## Run golangci-lint linter
@@ -215,7 +214,7 @@ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller
215214
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
216215
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
217216
GOLANGCI_LINT_VERSION ?= v2.1.0
218-
GINKGO_VERSION ?= v2.23.4
217+
GINKGO_VERSION ?= v2.27.2
219218
CODE_GENERATOR_VERSION ?= v0.32.3
220219
KIND_VERSION ?= v0.17.0
221220

@@ -376,10 +375,10 @@ go-deps: # download go dependencies
376375
docs-update: # update api docs
377376
go run ./cmd/doc-gen/main.go
378377

379-
e2e: ginkgo # make e2e tests
378+
fluentd-e2e: ginkgo # make e2e tests
380379
tests/scripts/fluentd_e2e.sh
381380

382-
helm-e2e: ginkgo # make helm e2e tests
381+
fluentd-helm-e2e: ginkgo # make helm e2e tests
383382
tests/scripts/fluentd_helm_e2e.sh
384383

385384
update-helm-package: # update helm repo
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/label_selector_test.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package fluentd
33
import (
44
"context"
55
"fmt"
6-
"strings"
76
"time"
87

98
. "github.com/onsi/ginkgo/v2"
@@ -13,6 +12,7 @@ import (
1312
"sigs.k8s.io/yaml"
1413

1514
fluentdv1alpha1 "github.com/fluent/fluent-operator/v3/apis/fluentd/v1alpha1"
15+
"github.com/fluent/fluent-operator/v3/tests/utils"
1616
)
1717

1818
var (
@@ -34,7 +34,7 @@ spec:
3434
image: ghcr.io/fluent/fluent-operator/fluentd:v1.19.1
3535
fluentdCfgSelector:
3636
matchLabels:
37-
config.fluentd.fluent.io/enabled: "true"
37+
label.config.fluentd.fluent.io/enabled: "true"
3838
`
3939

4040
// FluentdConfig with filterSelector and outputSelector
@@ -45,7 +45,7 @@ metadata:
4545
name: fluentd-config-label-selector-test
4646
namespace: fluent
4747
labels:
48-
config.fluentd.fluent.io/enabled: "true"
48+
label.config.fluentd.fluent.io/enabled: "true"
4949
spec:
5050
filterSelector:
5151
matchLabels:
@@ -100,7 +100,7 @@ metadata:
100100
name: fluentd-config-filter-only
101101
namespace: fluent
102102
labels:
103-
config.fluentd.fluent.io/enabled: "true"
103+
label.config.fluentd.fluent.io/enabled: "true"
104104
spec:
105105
filterSelector:
106106
matchLabels:
@@ -199,22 +199,7 @@ var _ = Describe("Test FluentdConfig with namespace-level filter and output sele
199199

200200
// Verify that the filter configuration is present
201201
// Before the fix, the filter would not be loaded because it was written to the inputs list
202-
Expect(config).To(ContainSubstring("<filter"))
203-
Expect(config).To(ContainSubstring("@type record_transformer"))
204-
Expect(config).To(ContainSubstring("hostname"))
205-
Expect(config).To(ContainSubstring("test-host"))
206-
Expect(config).To(ContainSubstring("environment"))
207-
Expect(config).To(ContainSubstring("testing"))
208-
209-
// Verify that the output configuration is present
210-
// Before the fix, the output would not be loaded because it was written to the inputs list
211-
Expect(config).To(ContainSubstring("<match"))
212-
Expect(config).To(ContainSubstring("@type stdout"))
213-
214-
// Verify that filter and output are in the correct order (filter before output)
215-
filterIndex := strings.Index(config, "<filter")
216-
outputIndex := strings.Index(config, "<match")
217-
Expect(filterIndex).To(BeNumerically("<", outputIndex), "Filter should appear before output in configuration")
202+
Expect(string(utils.ExpectedFluentdNamespacedCfgFilterOutputSelector)).To(Equal(config))
218203

219204
// Clean up
220205
err = DeleteObjs(ctx, objects)
@@ -257,12 +242,7 @@ var _ = Describe("Test FluentdConfig with namespace-level filter and output sele
257242
Name: fmt.Sprintf("%s-config", fluentd.Name),
258243
}
259244
config, err := GetCfgFromSecret(ctx, seckey)
260-
Expect(err).NotTo(HaveOccurred())
261-
262-
// Verify grep filter is present
263-
Expect(config).To(ContainSubstring("@type grep"))
264-
Expect(config).To(ContainSubstring("key level"))
265-
Expect(config).To(ContainSubstring("pattern /error/"))
245+
Expect(string(utils.ExpectedFluentdNamespacedCfgFilterSelector)).To(Equal(config))
266246

267247
// Clean up
268248
err = DeleteObjs(ctx, objects)

tests/scripts/fluentd_e2e.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ E2E_DIR="$(cd "$(dirname "$0")/.." && pwd)"
1313
LOGGING_NAMESPACE="fluent"
1414
IMAGE_TAG="$(date "+%Y-%m-%d-%H-%M-%S")"
1515
VERSION="$(tr -d " \t\n\r" < VERSION)"
16-
LOG_FILE="$(mktemp)"
1716
IMAGE_NAME="ghcr.io/fluent/fluent-operator/fluent-operator"
1817

1918
GINKGO_BIN="ginkgo"
@@ -42,7 +41,6 @@ function cleanup() {
4241
# kubectl delete ns $LOGGING_NAMESPACE
4342
kind delete cluster --name test || true
4443
popd >/dev/null || true
45-
rm -f "$LOG_FILE"
4644
}
4745

4846
function prepare_cluster() {
@@ -68,9 +66,6 @@ function start_fluent_operator() {
6866
}
6967

7068
function run_test() {
71-
# inspired by github.com/kubeedge/kubeedge/tests/e2e/scripts/helm_keadm_e2e.sh
72-
echo "Logs will be written to $LOG_FILE"
73-
7469
export ACK_GINKGO_RC=true
7570
"$GINKGO_BIN" -v "$E2E_DIR/e2e/fluentd/fluentd.test" -- "$debugflag"
7671

tests/utils/utils.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import (
99
var (
1010
once sync.Once
1111

12-
ExpectedFluentdClusterCfgOutputES []byte
13-
ExpectedFluentdClusterCfgOutputKafka []byte
14-
ExpectedFluentdClusterCfgOutputWithBuffer []byte
15-
ExpectedFluentdMixedCfgsMultiTenant []byte
16-
ExpectedFluentdMixedCfgsOutputES []byte
17-
ExpectedFluentdNamespacedCfgOutputES []byte
18-
ExpectedDuplicateRemovalCRSPECS []byte
19-
ExpectedFluentdClusterCfgOutputCustom []byte
12+
ExpectedFluentdClusterCfgOutputES []byte
13+
ExpectedFluentdClusterCfgOutputKafka []byte
14+
ExpectedFluentdClusterCfgOutputWithBuffer []byte
15+
ExpectedFluentdMixedCfgsMultiTenant []byte
16+
ExpectedFluentdMixedCfgsOutputES []byte
17+
ExpectedFluentdNamespacedCfgOutputES []byte
18+
ExpectedDuplicateRemovalCRSPECS []byte
19+
ExpectedFluentdClusterCfgOutputCustom []byte
20+
ExpectedFluentdNamespacedCfgFilterOutputSelector []byte
21+
ExpectedFluentdNamespacedCfgFilterSelector []byte
2022
)
2123

2224
func init() {
@@ -37,6 +39,10 @@ func init() {
3739
getExpectedCfg("./apis/fluentd/v1alpha1/tests/expected/duplicate-removal-cr-specs.cfg")
3840
ExpectedFluentdClusterCfgOutputCustom =
3941
getExpectedCfg("./apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-output-custom.cfg")
42+
ExpectedFluentdNamespacedCfgFilterOutputSelector =
43+
getExpectedCfg("./apis/fluentd/v1alpha1/tests/expected/fluentd-namespaced-cfg-filter-output-selector.cfg")
44+
ExpectedFluentdNamespacedCfgFilterSelector =
45+
getExpectedCfg("./apis/fluentd/v1alpha1/tests/expected/fluentd-namespaced-cfg-filter-selector.cfg")
4046
})
4147
}
4248

0 commit comments

Comments
 (0)