From db1481f2f2d89af057866afa5e227350a17ecefa Mon Sep 17 00:00:00 2001 From: Relk Li Date: Tue, 19 Apr 2022 00:35:48 +0800 Subject: [PATCH] Fix cni panic due to pod.Annotations is a nil map (#1974) Co-authored-by: Relk Li --- pkg/ipamd/ipamd.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/ipamd/ipamd.go b/pkg/ipamd/ipamd.go index 2717cb93aa..6a3b031035 100644 --- a/pkg/ipamd/ipamd.go +++ b/pkg/ipamd/ipamd.go @@ -1920,6 +1920,9 @@ func (c *IPAMContext) AnnotatePod(podName, podNamespace, key, val string) error } newPod := pod.DeepCopy() + if newPod.Annotations == nil { + newPod.Annotations = make(map[string]string) + } newPod.Annotations[key] = val if err = c.rawK8SClient.Patch(ctx, newPod, client.MergeFrom(pod)); err != nil { log.Errorf("Failed to annotate %s the pod with %s, error %v", key, val, err)