Skip to content

Commit 875e909

Browse files
authored
[chore] update k8sevent test for k8s v1.35 (#2247)
* [chore] update k8sevent for k8s v1.35 * compute re once
1 parent a23715a commit 875e909

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

functional_tests/k8sevents/k8sevents_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import (
2727

2828
var eventsLogsConsumer *consumertest.LogsSink
2929

30+
// Regexes for normalizing k8s event log bodies.
31+
var (
32+
rePulledImage = regexp.MustCompile(`Successfully pulled image "(busybox|alpine):latest" in .* \(.* including waiting\).*`)
33+
reCreatedContainer = regexp.MustCompile(`Created container: .*`)
34+
reStartedContainer = regexp.MustCompile(`Started container( .*)?`)
35+
)
36+
3037
// Env vars to control the test behavior
3138
// TEARDOWN_BEFORE_SETUP: if set to true, the test will run teardown before setup
3239
// SKIP_SETUP: if set to true, the test will skip setup
@@ -64,8 +71,11 @@ func Test_K8SEvents(t *testing.T) {
6471
t.Run("CheckK8SEventsLogs", func(t *testing.T) {
6572
actualLogs := selectResLogs("com.splunk.sourcetype", "kube:events", eventsLogsConsumer)
6673
k8sEventsLogs := selectLogs("k8s.namespace.name", "k8sevents-test", &actualLogs, func(body string) string {
67-
re := regexp.MustCompile(`Successfully pulled image "(busybox|alpine):latest" in .* \(.* including waiting\).*`)
68-
return re.ReplaceAllString(body, `Successfully pulled image "$1:latest" in <time> (<time> including waiting)`)
74+
s := rePulledImage.ReplaceAllString(body, `Successfully pulled image "$1:latest" in <time> (<time> including waiting)`)
75+
// Pre-1.35: "Created container: <name>", "Started container <name>". 1.35+: "Container created", "Container started".
76+
s = reCreatedContainer.ReplaceAllString(s, "Container created")
77+
s = reStartedContainer.ReplaceAllString(s, "Container started")
78+
return s
6979
})
7080

7181
expectedEventsLogsFile := "testdata/expected_k8sevents.yaml"

functional_tests/k8sevents/testdata/expected_k8sevents.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ resourceLogs:
327327
value:
328328
stringValue: Normal
329329
body:
330-
stringValue: 'Created container: container-1'
330+
stringValue: Container created
331331
timeUnixNano: "1759215210000000000"
332332
- attributes:
333333
- key: deployment.environment
@@ -391,7 +391,7 @@ resourceLogs:
391391
value:
392392
stringValue: Normal
393393
body:
394-
stringValue: Started container container-1
394+
stringValue: Container started
395395
timeUnixNano: "1759215210000000000"
396396
- attributes:
397397
- key: deployment.environment
@@ -583,7 +583,7 @@ resourceLogs:
583583
value:
584584
stringValue: Normal
585585
body:
586-
stringValue: 'Created container: container-2'
586+
stringValue: Container created
587587
timeUnixNano: "1759215213000000000"
588588
- attributes:
589589
- key: deployment.environment
@@ -647,6 +647,6 @@ resourceLogs:
647647
value:
648648
stringValue: Normal
649649
body:
650-
stringValue: Started container container-2
650+
stringValue: Container started
651651
timeUnixNano: "1759215213000000000"
652652
scope: {}

0 commit comments

Comments
 (0)