MCPcopy Index your code
hub / github.com/containerd/containerd / loadShim

Method loadShim

core/runtime/v2/shim_load.go:127–201  ·  view source on GitHub ↗
(ctx context.Context, bundle *Bundle)

Source from the content-addressed store, hash-verified

125}
126
127func (m *ShimManager) loadShim(ctx context.Context, bundle *Bundle) error {
128 var (
129 runtime string
130 id = bundle.ID
131 )
132
133 // If we're on 1.6+ and specified custom path to the runtime binary, path will be saved in 'shim-binary-path' file.
134 if data, err := os.ReadFile(filepath.Join(bundle.Path, "shim-binary-path")); err == nil {
135 runtime = string(data)
136 } else if err != nil && !os.IsNotExist(err) {
137 log.G(ctx).WithError(err).Error("failed to read `runtime` path from bundle")
138 }
139
140 // Query runtime name from metadata store
141 if runtime == "" {
142 container, err := m.containers.Get(ctx, id)
143 if err != nil {
144 log.G(ctx).WithError(err).Errorf("loading container %s", id)
145 if err := mount.UnmountRecursive(filepath.Join(bundle.Path, "rootfs"), 0); err != nil {
146 log.G(ctx).WithError(err).Errorf("failed to unmount of rootfs %s", id)
147 }
148 return err
149 }
150 runtime = container.Runtime.Name
151 }
152
153 runtime, err := m.resolveRuntimePath(runtime)
154 if err != nil {
155 bundle.Delete()
156
157 return fmt.Errorf("failed to resolve runtime path: %w", err)
158 }
159
160 binaryCall := shimBinary(bundle,
161 shimBinaryConfig{
162 runtime: runtime,
163 address: m.containerdAddress,
164 ttrpcAddress: m.containerdTTRPCAddress,
165 socketDir: m.socketDir,
166 env: m.env,
167 })
168 // TODO: It seems we can only call loadShim here if it is a sandbox shim?
169 shim, err := loadShimTask(ctx, bundle, func() {
170 log.G(ctx).WithField("id", id).Info("shim disconnected")
171
172 cleanupAfterDeadShim(context.WithoutCancel(ctx), id, m.shims, m.events, binaryCall)
173 // Remove self from the runtime task list.
174 m.shims.Delete(ctx, id)
175 })
176 if err != nil {
177 cleanupAfterDeadShim(ctx, id, m.shims, m.events, binaryCall)
178 return fmt.Errorf("unable to load shim %q: %w", id, err)
179 }
180
181 // There are 3 possibilities for the loaded shim here:
182 // 1. It could be a shim that is running a task.
183 // 2. It could be a sandbox shim.
184 // 3. Or it could be a shim that was created for running a task but

Callers 1

loadShimsMethod · 0.95

Calls 12

resolveRuntimePathMethod · 0.95
UnmountRecursiveFunction · 0.92
shimBinaryFunction · 0.85
loadShimTaskFunction · 0.85
cleanupAfterDeadShimFunction · 0.85
GetMethod · 0.65
DeleteMethod · 0.65
InfoMethod · 0.65
PidsMethod · 0.65
AddMethod · 0.65
ErrorMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected