server: clean up sandbox network when running the sandbox fails
Runtimes need to clean up anything that needs it if RunPodSandbox() fails. Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
parent
c56dcf2cb5
commit
6a58bdf787
3 changed files with 83 additions and 66 deletions
|
@ -2,7 +2,6 @@ package server
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containers/storage"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
|
@ -15,7 +14,6 @@ import (
|
|||
"golang.org/x/net/context"
|
||||
"golang.org/x/sys/unix"
|
||||
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network/hostport"
|
||||
)
|
||||
|
||||
// StopPodSandbox stops the sandbox. If there are any running containers in the
|
||||
|
@ -44,36 +42,14 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
podInfraContainer := sb.InfraContainer()
|
||||
netnsPath, err := podInfraContainer.NetNsPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := os.Stat(netnsPath); err == nil {
|
||||
if err2 := s.hostportManager.Remove(sb.ID(), &hostport.PodPortMapping{
|
||||
Name: sb.Name(),
|
||||
PortMappings: sb.PortMappings(),
|
||||
HostNetwork: false,
|
||||
}); err2 != nil {
|
||||
logrus.Warnf("failed to remove hostport for pod sandbox %s(%s): %v",
|
||||
podInfraContainer.Name(), sb.ID(), err2)
|
||||
}
|
||||
|
||||
podNetwork := newPodNetwork(sb.Namespace(), sb.KubeName(), sb.ID(), netnsPath)
|
||||
if err2 := s.netPlugin.TearDownPod(podNetwork); err2 != nil {
|
||||
logrus.Warnf("failed to destroy network for pod sandbox %s(%s): %v",
|
||||
sb.Name(), sb.ID(), err2)
|
||||
}
|
||||
} else if !os.IsNotExist(err) { // it's ok for netnsPath to *not* exist
|
||||
return nil, fmt.Errorf("failed to stat netns path for pod sandbox %s(%s) before tearing down the network: %v",
|
||||
sb.Name(), sb.ID(), err)
|
||||
}
|
||||
|
||||
// Close the sandbox networking namespace.
|
||||
// Clean up sandbox networking and close its network namespace.
|
||||
hostNetwork := sb.NetNsPath() == ""
|
||||
s.networkStop(hostNetwork, sb)
|
||||
if err := sb.NetNsRemove(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
podInfraContainer := sb.InfraContainer()
|
||||
containers := sb.Containers().List()
|
||||
containers = append(containers, podInfraContainer)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue