From 73c2cb5632e5e9c93c2de10c544eff6b401739c7 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Thu, 2 Nov 2017 22:41:59 +0000 Subject: [PATCH] Fix spammy CNI log. Signed-off-by: Lantao Liu --- pkg/server/sandbox_status.go | 5 +++++ pkg/store/sandbox/netns.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/server/sandbox_status.go b/pkg/server/sandbox_status.go index 6c7863206..fa075c0ea 100644 --- a/pkg/server/sandbox_status.go +++ b/pkg/server/sandbox_status.go @@ -85,6 +85,11 @@ func (c *criContainerdService) getIP(sandbox sandboxstore.Sandbox) (string, erro return "", nil } + // The network namespace has been closed. + if sandbox.NetNS == nil || sandbox.NetNS.Closed() { + return "", nil + } + podNetwork := ocicni.PodNetwork{ Name: config.GetMetadata().GetName(), Namespace: config.GetMetadata().GetNamespace(), diff --git a/pkg/store/sandbox/netns.go b/pkg/store/sandbox/netns.go index cc638cb8a..ec1aae08b 100644 --- a/pkg/store/sandbox/netns.go +++ b/pkg/store/sandbox/netns.go @@ -111,6 +111,13 @@ func (n *NetNS) Remove() error { return nil } +// Closed checks whether the network namespace has been closed. +func (n *NetNS) Closed() bool { + n.Lock() + defer n.Unlock() + return n.closed +} + // GetPath returns network namespace path for sandbox container func (n *NetNS) GetPath() string { n.Lock()