@@ -253,27 +253,26 @@ func (g *GenericPLEG) Relist() {
253
253
updateRunningPodAndContainerMetrics (pods )
254
254
g .podRecords .setCurrent (pods )
255
255
256
- // Compare the old and the current pods, and generate events.
257
- eventsByPodID := map [types. UID ][] * PodLifecycleEvent {}
256
+ needsReinspection := make ( map [types. UID ] * kubecontainer. Pod )
257
+
258
258
for pid := range g .podRecords {
259
+ // Compare the old and the current pods, and generate events.
259
260
oldPod := g .podRecords .getOld (pid )
260
261
pod := g .podRecords .getCurrent (pid )
261
262
// Get all containers in the old and the new pod.
262
263
allContainers := getContainersFromPods (oldPod , pod )
264
+ var events []* PodLifecycleEvent
263
265
for _ , container := range allContainers {
264
- events := computeEvents (g .logger , oldPod , pod , & container .ID )
265
- for _ , e := range events {
266
- updateEvents (eventsByPodID , e )
267
- }
266
+ containerEvents := computeEvents (g .logger , oldPod , pod , & container .ID )
267
+ events = append (events , containerEvents ... )
268
268
}
269
- }
270
269
271
- needsReinspection := make ( map [types. UID ] * kubecontainer. Pod )
270
+ _ , reinspect := g . podsToReinspect [ pid ]
272
271
273
- // If there are events associated with a pod, we should update the
274
- // podCache .
275
- for pid , events := range eventsByPodID {
276
- pod := g . podRecords . getCurrent ( pid )
272
+ if len ( events ) == 0 && ! reinspect {
273
+ // Nothing else needed for this pod .
274
+ continue
275
+ }
277
276
278
277
// updateCache() will inspect the pod and update the cache. If an
279
278
// error occurs during the inspection, we want PLEG to retry again
@@ -293,10 +292,6 @@ func (g *GenericPLEG) Relist() {
293
292
294
293
continue
295
294
} else {
296
- // this pod was in the list to reinspect and we did so because it had events, so remove it
297
- // from the list (we don't want the reinspection code below to inspect it a second time in
298
- // this relist execution)
299
- delete (g .podsToReinspect , pid )
300
295
if utilfeature .DefaultFeatureGate .Enabled (features .EventedPLEG ) {
301
296
if ! updated {
302
297
continue
@@ -342,18 +337,6 @@ func (g *GenericPLEG) Relist() {
342
337
}
343
338
}
344
339
345
- // reinspect any pods that failed inspection during the previous relist
346
- if len (g .podsToReinspect ) > 0 {
347
- g .logger .V (5 ).Info ("GenericPLEG: Reinspecting pods that previously failed inspection" )
348
- for pid , pod := range g .podsToReinspect {
349
- if err , _ := g .updateCache (ctx , pod , pid ); err != nil {
350
- // Rely on updateCache calling GetPodStatus to log the actual error.
351
- g .logger .V (5 ).Error (err , "PLEG: pod failed reinspection" , "pod" , klog .KRef (pod .Namespace , pod .Name ))
352
- needsReinspection [pid ] = pod
353
- }
354
- }
355
- }
356
-
357
340
// Update the cache timestamp. This needs to happen *after*
358
341
// all pods have been properly updated in the cache.
359
342
g .cache .UpdateTime (timestamp )
0 commit comments