Skip to content

Commit

Permalink
vm, webhook: Fix panic on templateless VM
Browse files Browse the repository at this point in the history
former fix [0] was not sufficient. Moving the check earlier in the
webhoook handling.

Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Sep 8, 2024
1 parent 246c3f2 commit 3e2b11f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/webhook/virtualmachine/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func (a *virtualMachineAnnotator) Handle(ctx context.Context, req admission.Requ

logger.V(1).Info("got a virtual machine event")

if virtualMachine.Spec.Template == nil {
const errMsg = "virtual machine template is nil, ignoring virtual machine"
logger.Info(errMsg)
return admission.Allowed(errMsg)
}

isNotDryRun := (req.DryRun == nil || *req.DryRun == false)
if req.AdmissionRequest.Operation == admissionv1.Create {
err = a.mutateCreateVirtualMachinesFn(virtualMachine, isNotDryRun, logger)
Expand Down

0 comments on commit 3e2b11f

Please sign in to comment.