From 054eb6e2769df62905d9f82c651e685188c2d3d9 Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Wed, 21 Feb 2024 13:47:45 +0000 Subject: [PATCH] Fix NPE in virtualmachine.Status.RestartCount (#819) --- neonvm/controllers/virtualmachine_controller.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/neonvm/controllers/virtualmachine_controller.go b/neonvm/controllers/virtualmachine_controller.go index 2bb37eb55..74909ffde 100644 --- a/neonvm/controllers/virtualmachine_controller.go +++ b/neonvm/controllers/virtualmachine_controller.go @@ -787,7 +787,11 @@ func (r *VirtualMachineReconciler) doReconcile(ctx context.Context, virtualmachi if shouldRestart { log.Info("Restarting VM runner pod", "VM.Phase", virtualmachine.Status.Phase, "RestartPolicy", virtualmachine.Spec.RestartPolicy) virtualmachine.Status.Phase = vmv1.VmPending // reset to trigger restart - *virtualmachine.Status.RestartCount += 1 // increment restart count + if virtualmachine.Status.RestartCount == nil { + var zero int32 = 0 + virtualmachine.Status.RestartCount = &zero + } + *virtualmachine.Status.RestartCount += 1 // increment restart count r.Metrics.vmRestartCounts.Inc() }