@@ -27,6 +27,13 @@ import (
2727
2828var 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"
0 commit comments