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()