@@ -103,6 +103,30 @@ var (
103
103
},
104
104
},
105
105
}}
106
+ mockPodListUnhealthy = & v1.PodList {
107
+ TypeMeta : metav1.TypeMeta {
108
+ Kind : "PodList" ,
109
+ APIVersion : "v1" ,
110
+ },
111
+ Items : []v1.Pod {
112
+ {
113
+ ObjectMeta : metav1.ObjectMeta {
114
+ Name : thirdCollectorName + "-1" ,
115
+ Namespace : otherCollectorName ,
116
+ Labels : map [string ]string {
117
+ "app.kubernetes.io/managed-by" : "opentelemetry-operator" ,
118
+ "app.kubernetes.io/instance" : fmt .Sprintf ("%s.%s" , otherCollectorName , thirdCollectorName ),
119
+ "app.kubernetes.io/part-of" : "opentelemetry" ,
120
+ "app.kubernetes.io/component" : "opentelemetry-collector" ,
121
+ },
122
+ },
123
+ Spec : v1.PodSpec {},
124
+ Status : v1.PodStatus {
125
+ StartTime : nil ,
126
+ Phase : v1 .PodRunning ,
127
+ },
128
+ },
129
+ }}
106
130
)
107
131
108
132
func getConfigHash (key , file string ) string {
@@ -187,6 +211,7 @@ func TestAgent_getHealth(t *testing.T) {
187
211
ctx context.Context
188
212
// List of mappings from namespace/name to a config file, tests are run in order of list
189
213
configs []map [string ]string
214
+ podList * v1.PodList
190
215
}
191
216
tests := []struct {
192
217
name string
@@ -203,6 +228,7 @@ func TestAgent_getHealth(t *testing.T) {
203
228
args : args {
204
229
ctx : context .Background (),
205
230
configs : nil ,
231
+ podList : mockPodList ,
206
232
},
207
233
want : []* protobufs.ComponentHealth {
208
234
{
@@ -227,6 +253,7 @@ func TestAgent_getHealth(t *testing.T) {
227
253
testCollectorKey : collectorBasicFile ,
228
254
},
229
255
},
256
+ podList : mockPodList ,
230
257
},
231
258
want : []* protobufs.ComponentHealth {
232
259
{
@@ -259,6 +286,7 @@ func TestAgent_getHealth(t *testing.T) {
259
286
otherCollectorKey : collectorUpdatedFile ,
260
287
},
261
288
},
289
+ podList : mockPodList ,
262
290
},
263
291
want : []* protobufs.ComponentHealth {
264
292
{
@@ -298,6 +326,7 @@ func TestAgent_getHealth(t *testing.T) {
298
326
thirdCollectorKey : collectorBasicFile ,
299
327
},
300
328
},
329
+ podList : mockPodList ,
301
330
},
302
331
want : []* protobufs.ComponentHealth {
303
332
{
@@ -324,14 +353,53 @@ func TestAgent_getHealth(t *testing.T) {
324
353
},
325
354
},
326
355
},
356
+ {
357
+ name : "with pod health, nil start time" ,
358
+ fields : fields {
359
+ configFile : agentTestFileName ,
360
+ },
361
+ args : args {
362
+ ctx : context .Background (),
363
+ configs : []map [string ]string {
364
+ {
365
+ thirdCollectorKey : collectorBasicFile ,
366
+ },
367
+ },
368
+ podList : mockPodListUnhealthy ,
369
+ },
370
+ want : []* protobufs.ComponentHealth {
371
+ {
372
+ Healthy : true ,
373
+ StartTimeUnixNano : uint64 (fakeClock .Now ().UnixNano ()),
374
+ StatusTimeUnixNano : uint64 (fakeClock .Now ().UnixNano ()),
375
+ ComponentHealthMap : map [string ]* protobufs.ComponentHealth {
376
+ "other/third" : {
377
+ Healthy : false , // we're working with mocks so the status will never be reconciled.
378
+ StartTimeUnixNano : collectorStartTime ,
379
+ LastError : "" ,
380
+ Status : "" ,
381
+ StatusTimeUnixNano : uint64 (fakeClock .Now ().UnixNano ()),
382
+ ComponentHealthMap : map [string ]* protobufs.ComponentHealth {
383
+ otherCollectorName + "/" + thirdCollectorName + "-1" : {
384
+ Healthy : false ,
385
+ Status : "Running" ,
386
+ StatusTimeUnixNano : uint64 (fakeClock .Now ().UnixNano ()),
387
+ StartTimeUnixNano : uint64 (0 ),
388
+ },
389
+ },
390
+ },
391
+ },
392
+ },
393
+ },
394
+ },
327
395
}
328
396
for _ , tt := range tests {
329
397
t .Run (tt .name , func (t * testing.T ) {
330
398
mockClient := & mockOpampClient {}
331
399
conf := config .NewConfig (logr .Discard ())
332
400
loadErr := config .LoadFromFile (conf , tt .fields .configFile )
333
401
require .NoError (t , loadErr , "should be able to load config" )
334
- applier := getFakeApplier (t , conf , mockPodList )
402
+ applier := getFakeApplier (t , conf , tt . args . podList )
335
403
agent := NewAgent (l , applier , conf , mockClient )
336
404
agent .clock = fakeClock
337
405
err := agent .Start ()
0 commit comments