Skip to content

Commit

Permalink
Refactor chanErr consumption in VM controller
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bryan Venteicher authored and akutz committed Dec 19, 2024
1 parent eecd7f1 commit 5da73b9
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down

0 comments on commit 5da73b9

Please sign in to comment.