From 3b5970bd564f128e0767fa6f07fdfba60bff491e Mon Sep 17 00:00:00 2001 From: Enrique Llorente Date: Thu, 4 Jul 2024 16:50:23 +0200 Subject: [PATCH] webhook: Check first vm annotation Signed-off-by: Enrique Llorente --- pkg/ipamclaimswebhook/podmutator.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/ipamclaimswebhook/podmutator.go b/pkg/ipamclaimswebhook/podmutator.go index a9b2d3eb..7f2a3112 100644 --- a/pkg/ipamclaimswebhook/podmutator.go +++ b/pkg/ipamclaimswebhook/podmutator.go @@ -65,6 +65,14 @@ func (a *IPAMClaimsValet) Handle(ctx context.Context, request admission.Request) return admission.Errored(http.StatusBadRequest, err) } + vmName, hasVMAnnotation := pod.Annotations["kubevirt.io/domain"] + if !hasVMAnnotation { + log.Info( + "does not have the kubevirt VM annotation", + ) + return admission.Allowed("not a VM") + } + log.Info("webhook handling event") networkSelectionElements, err := netutils.ParsePodNetworkAnnotation(pod) if err != nil { @@ -112,15 +120,6 @@ func (a *IPAMClaimsValet) Handle(ctx context.Context, request admission.Request) "NAD", nadName, "network", pluginConfig.Name, ) - vmName, hasVMAnnotation := pod.Annotations["kubevirt.io/domain"] - if !hasVMAnnotation { - log.Info( - "does not have the kubevirt VM annotation", - "NAD", nadName, - "network", pluginConfig.Name, - ) - return admission.Allowed("not a VM") - } vmKey := types.NamespacedName{Namespace: pod.Namespace, Name: vmName} vmi := &virtv1.VirtualMachineInstance{}