From 5da73b9e49523a8488c641475b5603ae0030d0d1 Mon Sep 17 00:00:00 2001 From: Bryan Venteicher Date: Thu, 19 Dec 2024 10:19:23 -0600 Subject: [PATCH] Refactor chanErr consumption in VM controller This patch changes the way the error channel from the async create workflow is consumed in the VirtualMachine controller. Previously only a single error was assumed to be returned, but since this is a channel, the consumer should range over it, accounting for the possible vim and k8s error. --- .../virtualmachine/virtualmachine_controller.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go b/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go index f96e8be1c..75367ebea 100644 --- a/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go +++ b/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go @@ -499,8 +499,17 @@ func (r *Reconciler) ReconcileNormal(ctx *pkgctx.VirtualMachineContext) (reterr } else { // Emit event once goroutine is complete. go func(obj client.Object) { - err := <-chanErr - r.Recorder.EmitEvent(obj, "Create", err, false) + failed := false + for err := range chanErr { + if err != nil { + failed = true + r.Recorder.EmitEvent(obj, "Create", err, false) + } + } + if !failed { + // If no error the channel is just closed. + r.Recorder.EmitEvent(obj, "Create", nil, false) + } }(ctx.VM.DeepCopy()) } }