From 1c82cdc2f144d27bde82e95897c027323dca8b6d Mon Sep 17 00:00:00 2001 From: Evan Baker Date: Wed, 12 Jan 2022 03:37:59 +0000 Subject: [PATCH 1/2] fix initialize from kube pods flow Signed-off-by: Evan Baker Date: Wed, 19 Jan 2022 23:31:38 +0000 Subject: [PATCH 2/2] move list pods inside closure Signed-off-by: Evan Baker --- cns/service/main.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/cns/service/main.go b/cns/service/main.go index 12fa5e43ca..f997f13904 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -46,7 +46,6 @@ import ( "github.com/Azure/azure-container-networking/store" "github.com/avast/retry-go/v3" "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" @@ -925,16 +924,14 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn } } else { logger.Printf("Initializing from Kubernetes") - var pods *corev1.PodList - pods, err = clientset.CoreV1().Pods("").List(ctx, metav1.ListOptions{ - FieldSelector: "spec.nodeName=" + nodeName, - }) - if err != nil { - return errors.Wrap(err, "failed to list Pods for PodInfoProvider") - } podInfoByIPProvider = cns.PodInfoByIPProviderFunc(func() (map[string]cns.PodInfo, error) { - var podInfo map[string]cns.PodInfo - podInfo, err = cns.KubePodsToPodInfoByIP(pods.Items) + pods, err := clientset.CoreV1().Pods("").List(ctx, metav1.ListOptions{ //nolint:govet // ignore err shadow + FieldSelector: "spec.nodeName=" + nodeName, + }) + if err != nil { + return nil, errors.Wrap(err, "failed to list Pods for PodInfoProvider") + } + podInfo, err := cns.KubePodsToPodInfoByIP(pods.Items) if err != nil { return nil, errors.Wrap(err, "failed to convert Pods to PodInfoByIP") }