@@ -50,20 +50,20 @@ var (
50
50
logEntryMessageRegex = regexp .MustCompile ("(?:I\\ d+ \\ d+:\\ d+:\\ d+.\\ d+ \\ d+ logs_generator.go:67] )?(\\ d+) .*" )
51
51
)
52
52
53
- // Type to track the progress of logs generating pod
54
- type loggingPod struct {
55
- // Name of the pod
56
- Name string
57
- // Cache of ingested and read entries
58
- Occurrences map [int ]logEntry
59
- // Number of lines expected to be ingested from this pod
60
- ExpectedLinesNumber int
61
- }
62
-
63
53
type logEntry struct {
64
54
Payload string
65
55
}
66
56
57
+ func (entry logEntry ) getLogEntryNumber () (int , bool ) {
58
+ submatch := logEntryMessageRegex .FindStringSubmatch (entry .Payload )
59
+ if submatch == nil || len (submatch ) < 2 {
60
+ return 0 , false
61
+ }
62
+
63
+ lineNumber , err := strconv .Atoi (submatch [1 ])
64
+ return lineNumber , err == nil
65
+ }
66
+
67
67
type logsProvider interface {
68
68
Init () error
69
69
Cleanup ()
@@ -79,31 +79,37 @@ type loggingTestConfig struct {
79
79
MaxAllowedFluentdRestarts int
80
80
}
81
81
82
- func (entry logEntry ) getLogEntryNumber () (int , bool ) {
83
- submatch := logEntryMessageRegex .FindStringSubmatch (entry .Payload )
84
- if submatch == nil || len (submatch ) < 2 {
85
- return 0 , false
86
- }
87
-
88
- lineNumber , err := strconv .Atoi (submatch [1 ])
89
- return lineNumber , err == nil
82
+ // Type to track the progress of logs generating pod
83
+ type loggingPod struct {
84
+ // Name equals to the pod name and the container name.
85
+ Name string
86
+ // NodeName is the name of the node this pod will be
87
+ // assigned to. Can be empty.
88
+ NodeName string
89
+ // Occurrences is a cache of ingested and read entries.
90
+ Occurrences map [int ]logEntry
91
+ // ExpectedLinesNumber is the number of lines that are
92
+ // expected to be ingested from this pod.
93
+ ExpectedLinesNumber int
94
+ // RunDuration is how long the pod will live.
95
+ RunDuration time.Duration
90
96
}
91
97
92
- func createLoggingPod (f * framework.Framework , podName string , nodeName string , totalLines int , loggingDuration time.Duration ) * loggingPod {
93
- framework .Logf ("Starting pod %s" , podName )
94
- createLogsGeneratorPod (f , podName , nodeName , totalLines , loggingDuration )
95
-
98
+ func newLoggingPod (podName string , nodeName string , totalLines int , loggingDuration time.Duration ) * loggingPod {
96
99
return & loggingPod {
97
100
Name : podName ,
101
+ NodeName : nodeName ,
98
102
Occurrences : make (map [int ]logEntry ),
99
103
ExpectedLinesNumber : totalLines ,
104
+ RunDuration : loggingDuration ,
100
105
}
101
106
}
102
107
103
- func createLogsGeneratorPod (f * framework.Framework , podName string , nodeName string , linesCount int , duration time.Duration ) {
108
+ func (p * loggingPod ) Start (f * framework.Framework ) {
109
+ framework .Logf ("Starting pod %s" , p .Name )
104
110
f .PodClient ().Create (& api_v1.Pod {
105
111
ObjectMeta : meta_v1.ObjectMeta {
106
- Name : podName ,
112
+ Name : p . Name ,
107
113
},
108
114
Spec : api_v1.PodSpec {
109
115
RestartPolicy : api_v1 .RestartPolicyNever ,
@@ -114,11 +120,11 @@ func createLogsGeneratorPod(f *framework.Framework, podName string, nodeName str
114
120
Env : []api_v1.EnvVar {
115
121
{
116
122
Name : "LOGS_GENERATOR_LINES_TOTAL" ,
117
- Value : strconv .Itoa (linesCount ),
123
+ Value : strconv .Itoa (p . ExpectedLinesNumber ),
118
124
},
119
125
{
120
126
Name : "LOGS_GENERATOR_DURATION" ,
121
- Value : duration .String (),
127
+ Value : p . RunDuration .String (),
122
128
},
123
129
},
124
130
Resources : api_v1.ResourceRequirements {
@@ -133,11 +139,17 @@ func createLogsGeneratorPod(f *framework.Framework, podName string, nodeName str
133
139
},
134
140
},
135
141
},
136
- NodeName : nodeName ,
142
+ NodeName : p . NodeName ,
137
143
},
138
144
})
139
145
}
140
146
147
+ func startNewLoggingPod (f * framework.Framework , podName string , nodeName string , totalLines int , loggingDuration time.Duration ) * loggingPod {
148
+ pod := newLoggingPod (podName , nodeName , totalLines , loggingDuration )
149
+ pod .Start (f )
150
+ return pod
151
+ }
152
+
141
153
func waitForSomeLogs (f * framework.Framework , config * loggingTestConfig ) error {
142
154
podHasIngestedLogs := make ([]bool , len (config .Pods ))
143
155
podWithIngestedLogsCount := 0
0 commit comments