Skip to content

Commit 5fdfa50

Browse files
committed
PR: error messages, docs, and formatting
Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent b846a9a commit 5fdfa50

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

cmd/containerd-shim-runhcs-v1/pod.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type shimPod interface {
5252
// not in this state this pod MUST return `errdefs.ErrFailedPrecondition`.
5353
KillTask(ctx context.Context, tid, eid string, signal uint32, all bool) error
5454
// DeleteTask removes a task from being tracked by this pod, and cleans up
55-
// and resources the shim allocated to the task.
55+
// the resources the shim allocated for the task.
5656
//
5757
// The task's init exec (eid == "") must be either `shimExecStateCreated` or
5858
// `shimExecStateExited`. If the exec is not in this state this pod MUST
@@ -400,12 +400,17 @@ func (p *pod) KillTask(ctx context.Context, tid, eid string, signal uint32, all
400400
}
401401

402402
func (p *pod) DeleteTask(ctx context.Context, tid string) error {
403+
// Deleting the sandbox task is a no-op, since the service should delete its
404+
// reference to the sandbox task or pod, and `p.sandboxTask != nil` is an
405+
// invariant that is relied on elsewhere.
406+
// However, still get the init exec for all tasks to ensure that they have
407+
// been properly stopped.
408+
403409
t, err := p.GetTask(tid)
404410
if err != nil {
405-
return errors.Wrap(err, "could not delete task")
411+
return errors.Wrap(err, "could not find task to delete")
406412
}
407413

408-
// although deleting the sandbox task is a no-op, still check that it is not running
409414
e, err := t.GetExec("")
410415
if err != nil {
411416
return errors.Wrap(err, "could not get initial exec")

cmd/containerd-shim-runhcs-v1/service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ type service struct {
3737

3838
// taskOrPod is either the `pod` this shim is tracking if `isSandbox ==
3939
// true` or it is the `task` this shim is tracking. If no call to `Create`
40-
// has taken place yet `taskOrPod.Load()` MUST return `nil`.
40+
// has taken place yet, or `Delete` was called on the init task id (`tid`),
41+
// then `taskOrPod.Load()` MUST return `nil`.
4142
taskOrPod atomic.Value
4243

4344
// cl is the create lock. Since each shim MUST only track a single task or

cmd/containerd-shim-runhcs-v1/service_internal.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package main
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"os"
78
"path/filepath"
89
"strings"
10+
"sync/atomic"
911

1012
runhcsopts "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
1113
"github.com/Microsoft/hcsshim/internal/oci"
@@ -215,16 +217,23 @@ func (s *service) deleteInternal(ctx context.Context, req *task.DeleteRequest) (
215217
return nil, err
216218
}
217219

218-
// remove the pod sandbox's reference to the task, if the delete is for a
219-
// task and not an exec
220-
if s.isSandbox && req.ExecID == "" {
221-
p, err := s.getPod()
222-
if err != nil {
223-
return nil, errors.Wrapf(err, "could not get pod %q to delete task %q", s.tid, req.ID)
220+
// delete is for a task, and not an exec
221+
if req.ExecID == "" {
222+
// remove the pod sandbox's reference to the task
223+
if s.isSandbox {
224+
p, err := s.getPod()
225+
if err != nil {
226+
return nil, errors.Wrapf(err, "could not get pod %q to delete task %q", s.tid, req.ID)
227+
}
228+
err = p.DeleteTask(ctx, req.ID)
229+
if err != nil {
230+
return nil, fmt.Errorf("could not delete task %q in pod %q: %w", req.ID, s.tid, err)
231+
}
224232
}
225-
err = p.DeleteTask(ctx, req.ID)
226-
if err != nil {
227-
return nil, errors.Wrapf(err, "could not delete task %q in pod %q", req.ID, s.tid)
233+
if req.ID == s.tid {
234+
// deleting the init task, so delete the internal reference to it, cleaning up
235+
// any final resources the service had for it
236+
s.taskOrPod = atomic.Value{}
228237
}
229238
}
230239

0 commit comments

Comments
 (0)