|
| 1 | +// Copyright (c) 2023-2026, Nubificus LTD |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package containerdshim |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + |
| 20 | + runcManager "github.com/containerd/containerd/runtime/v2/runc/manager" |
| 21 | + "github.com/containerd/containerd/runtime/v2/shim" |
| 22 | +) |
| 23 | + |
| 24 | +// NewShimManager returns urunc's shim manager wrapper around containerd's runc |
| 25 | +// shim manager. The wrapper is behavior-preserving today, but gives urunc a |
| 26 | +// manager-level hook for cleanup paths that do not go through TaskService. |
| 27 | +func NewShimManager(name string) shim.Manager { |
| 28 | + return &manager{ |
| 29 | + Manager: runcManager.NewShimManager(name), |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +type manager struct { |
| 34 | + shim.Manager |
| 35 | +} |
| 36 | + |
| 37 | +// Stop handles the shim binary "delete" action path. |
| 38 | +// |
| 39 | +// In containerd runtime-v2, normal task deletion reaches the long-running shim |
| 40 | +// over ttrpc and therefore goes through taskService.Delete. Dead-shim cleanup is |
| 41 | +// different: when containerd cannot reconnect to the shim, it executes the shim |
| 42 | +// binary with the "delete" action, and shim.RunManager calls Manager.Stop |
| 43 | +// directly before task plugins are initialized. Any urunc resource created by |
| 44 | +// the shim but needing dead-shim cleanup must therefore be cleaned from this |
| 45 | +// path as well as from taskService.Delete. |
| 46 | +func (m *manager) Stop(ctx context.Context, id string) (shim.StopStatus, error) { |
| 47 | + return m.Manager.Stop(ctx, id) |
| 48 | +} |
0 commit comments