sandbox_stop: Store stopped status
This allows us to respond to kubelet quickly if the pod was already stopped successfully earlier. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
ce17c5214d
commit
8d58f227cd
2 changed files with 19 additions and 0 deletions
|
@ -153,6 +153,7 @@ type Sandbox struct {
|
||||||
resolvPath string
|
resolvPath string
|
||||||
hostname string
|
hostname string
|
||||||
portMappings []*hostport.PortMapping
|
portMappings []*hostport.PortMapping
|
||||||
|
stopped bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -381,6 +382,19 @@ func (s *Sandbox) NetNsCreate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetStopped sets the sandbox state to stopped.
|
||||||
|
// This should be set after a stop operation succeeds
|
||||||
|
// so that subsequent stops can return fast.
|
||||||
|
func (s *Sandbox) SetStopped() {
|
||||||
|
s.stopped = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stopped returns whether the sandbox state has been
|
||||||
|
// set to stopped.
|
||||||
|
func (s *Sandbox) Stopped() bool {
|
||||||
|
return s.stopped
|
||||||
|
}
|
||||||
|
|
||||||
// NetNsJoin attempts to join the sandbox to an existing network namespace
|
// NetNsJoin attempts to join the sandbox to an existing network namespace
|
||||||
// This will fail if the sandbox is already part of a network namespace
|
// This will fail if the sandbox is already part of a network namespace
|
||||||
func (s *Sandbox) NetNsJoin(nspath, name string) error {
|
func (s *Sandbox) NetNsJoin(nspath, name string) error {
|
||||||
|
|
|
@ -37,6 +37,10 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sb.Stopped() {
|
||||||
|
return &pb.StopPodSandboxResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
podInfraContainer := sb.InfraContainer()
|
podInfraContainer := sb.InfraContainer()
|
||||||
netnsPath, err := podInfraContainer.NetNsPath()
|
netnsPath, err := podInfraContainer.NetNsPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -110,6 +114,7 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
|
||||||
logrus.Warnf("failed to stop sandbox container in pod sandbox %s: %v", sb.ID(), err)
|
logrus.Warnf("failed to stop sandbox container in pod sandbox %s: %v", sb.ID(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.SetStopped()
|
||||||
resp := &pb.StopPodSandboxResponse{}
|
resp := &pb.StopPodSandboxResponse{}
|
||||||
logrus.Debugf("StopPodSandboxResponse: %+v", resp)
|
logrus.Debugf("StopPodSandboxResponse: %+v", resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
|
Loading…
Reference in a new issue