@@ -39,6 +39,15 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
3939 return nil , errors .Wrapf (err , "an error occurred when try to find sandbox %q" ,
4040 r .GetPodSandboxId ())
4141 }
42+
43+ if err := c .stopPodSandbox (ctx , sandbox ); err != nil {
44+ return nil , err
45+ }
46+
47+ return & runtime.StopPodSandboxResponse {}, nil
48+ }
49+
50+ func (c * criService ) stopPodSandbox (ctx context.Context , sandbox sandboxstore.Sandbox ) error {
4251 // Use the full sandbox id.
4352 id := sandbox .ID
4453
@@ -52,20 +61,20 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
5261 }
5362 // Forcibly stop the container. Do not use `StopContainer`, because it introduces a race
5463 // if a container is removed after list.
55- if err = c .stopContainer (ctx , container , 0 ); err != nil {
56- return nil , errors .Wrapf (err , "failed to stop container %q" , container .ID )
64+ if err : = c .stopContainer (ctx , container , 0 ); err != nil {
65+ return errors .Wrapf (err , "failed to stop container %q" , container .ID )
5766 }
5867 }
5968
6069 if err := c .cleanupSandboxFiles (id , sandbox .Config ); err != nil {
61- return nil , errors .Wrap (err , "failed to cleanup sandbox files" )
70+ return errors .Wrap (err , "failed to cleanup sandbox files" )
6271 }
6372
6473 // Only stop sandbox container when it's running or unknown.
6574 state := sandbox .Status .Get ().State
6675 if state == sandboxstore .StateReady || state == sandboxstore .StateUnknown {
6776 if err := c .stopSandboxContainer (ctx , sandbox ); err != nil {
68- return nil , errors .Wrapf (err , "failed to stop sandbox container %q in %q state" , id , state )
77+ return errors .Wrapf (err , "failed to stop sandbox container %q in %q state" , id , state )
6978 }
7079 }
7180
@@ -74,21 +83,21 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
7483 // Use empty netns path if netns is not available. This is defined in:
7584 // https://github.com/containernetworking/cni/blob/v0.7.0-alpha1/SPEC.md
7685 if closed , err := sandbox .NetNS .Closed (); err != nil {
77- return nil , errors .Wrap (err , "failed to check network namespace closed" )
86+ return errors .Wrap (err , "failed to check network namespace closed" )
7887 } else if closed {
7988 sandbox .NetNSPath = ""
8089 }
8190 if err := c .teardownPodNetwork (ctx , sandbox ); err != nil {
82- return nil , errors .Wrapf (err , "failed to destroy network for sandbox %q" , id )
91+ return errors .Wrapf (err , "failed to destroy network for sandbox %q" , id )
8392 }
84- if err = sandbox .NetNS .Remove (); err != nil {
85- return nil , errors .Wrapf (err , "failed to remove network namespace for sandbox %q" , id )
93+ if err : = sandbox .NetNS .Remove (); err != nil {
94+ return errors .Wrapf (err , "failed to remove network namespace for sandbox %q" , id )
8695 }
8796 }
8897
8998 log .G (ctx ).Infof ("TearDown network for sandbox %q successfully" , id )
9099
91- return & runtime. StopPodSandboxResponse {}, nil
100+ return nil
92101}
93102
94103// stopSandboxContainer kills the sandbox container.
0 commit comments