@@ -274,7 +274,7 @@ func (w *workerHelperImpl) ProcessModuleSpec(
274
274
275
275
func (w * workerHelperImpl ) ProcessOrphanModuleStatus (
276
276
ctx context.Context ,
277
- nmc * kmmv1beta1.NodeModulesConfig ,
277
+ nmcObj * kmmv1beta1.NodeModulesConfig ,
278
278
status * kmmv1beta1.NodeModuleStatus ,
279
279
) error {
280
280
logger := ctrl .LoggerFrom (ctx )
@@ -284,9 +284,16 @@ func (w *workerHelperImpl) ProcessOrphanModuleStatus(
284
284
return nil
285
285
}
286
286
287
+ if status .Config == nil {
288
+ logger .Info ("Missing status config and pod is not running: previously failed pod, no need to unload" )
289
+ patchFrom := client .MergeFrom (nmcObj .DeepCopy ())
290
+ nmc .RemoveModuleStatus (& nmcObj .Status .Modules , status .Namespace , status .Name )
291
+ return w .client .Status ().Patch (ctx , nmcObj , patchFrom )
292
+ }
293
+
287
294
logger .Info ("Creating unloader Pod" )
288
295
289
- return w .pm .CreateUnloaderPod (ctx , nmc , status )
296
+ return w .pm .CreateUnloaderPod (ctx , nmcObj , status )
290
297
}
291
298
292
299
func (w * workerHelperImpl ) RemoveOrphanFinalizers (ctx context.Context , nodeName string ) error {
@@ -347,27 +354,32 @@ func (w *workerHelperImpl) SyncStatus(ctx context.Context, nmcObj *kmmv1beta1.No
347
354
348
355
logger .Info ("Processing worker Pod" )
349
356
350
- status := kmmv1beta1.NodeModuleStatus {
351
- Namespace : modNamespace ,
352
- Name : modName ,
357
+ status := nmc .FindModuleStatus (nmcObj .Status .Modules , modNamespace , modName )
358
+ if status == nil {
359
+ status = & kmmv1beta1.NodeModuleStatus {
360
+ Namespace : modNamespace ,
361
+ Name : modName ,
362
+ }
353
363
}
354
364
355
365
deletePod := false
356
- statusDeleted := false
366
+ updateModuleStatus := false
357
367
358
368
switch phase {
359
369
case v1 .PodFailed :
370
+ status .InProgress = false
360
371
deletePod = true
372
+ updateModuleStatus = true
361
373
case v1 .PodSucceeded :
362
374
deletePod = true
363
375
364
376
if p .Labels [actionLabelKey ] == WorkerActionUnload {
365
377
nmc .RemoveModuleStatus (& nmcObj .Status .Modules , modNamespace , modName )
366
- deletePod = true
367
- statusDeleted = true
368
378
break
369
379
}
370
380
381
+ updateModuleStatus = true
382
+
371
383
config := kmmv1beta1.ModuleConfig {}
372
384
373
385
if err = yaml .UnmarshalStrict ([]byte (p .Annotations [configAnnotationKey ]), & config ); err != nil {
@@ -388,9 +400,9 @@ func (w *workerHelperImpl) SyncStatus(ctx context.Context, nmcObj *kmmv1beta1.No
388
400
389
401
status .LastTransitionTime = & podLTT
390
402
391
- deletePod = true
392
403
case v1 .PodPending , v1 .PodRunning :
393
404
status .InProgress = true
405
+ updateModuleStatus = true
394
406
// TODO: if the NMC's spec changed compared to the Pod's config, recreate the Pod
395
407
default :
396
408
errs = append (
@@ -410,8 +422,8 @@ func (w *workerHelperImpl) SyncStatus(ctx context.Context, nmcObj *kmmv1beta1.No
410
422
}
411
423
}
412
424
413
- if ! statusDeleted {
414
- nmc .SetModuleStatus (& nmcObj .Status .Modules , status )
425
+ if updateModuleStatus {
426
+ nmc .SetModuleStatus (& nmcObj .Status .Modules , * status )
415
427
}
416
428
}
417
429
0 commit comments