From 3c97b829e264c768b5d31e7fc12ac874bee1e623 Mon Sep 17 00:00:00 2001 From: zachdorame <43703863+zachdorame@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:03:48 -0800 Subject: [PATCH] check if ipv4Addr or ipv6Addr is empty before calling AnnotatePod() (#2702) Co-authored-by: Zach Dorame-Barajas --- pkg/ipamd/rpc_handler.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/ipamd/rpc_handler.go b/pkg/ipamd/rpc_handler.go index 0eca3e07bc..16c73ec9fd 100644 --- a/pkg/ipamd/rpc_handler.go +++ b/pkg/ipamd/rpc_handler.go @@ -203,9 +203,16 @@ func (s *server) AddNetwork(ctx context.Context, in *rpc.AddNetworkRequest) (*rp if s.ipamContext.enablePodIPAnnotation { // On ADD, we pass empty string as there is no IP being released - err = s.ipamContext.AnnotatePod(in.K8S_POD_NAME, in.K8S_POD_NAMESPACE, vpccniPodIPKey, ipv4Addr, "") - if err != nil { - log.Errorf("Failed to add the pod annotation: %v", err) + if ipv4Addr != "" { + err = s.ipamContext.AnnotatePod(in.K8S_POD_NAME, in.K8S_POD_NAMESPACE, vpccniPodIPKey, ipv4Addr, "") + if err != nil { + log.Errorf("Failed to add the pod annotation: %v", err) + } + } else if ipv6Addr != "" { + err = s.ipamContext.AnnotatePod(in.K8S_POD_NAME, in.K8S_POD_NAMESPACE, vpccniPodIPKey, ipv6Addr, "") + if err != nil { + log.Errorf("Failed to add the pod annotation: %v", err) + } } } resp := rpc.AddNetworkReply{