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

Method execInContainer

internal/cri/server/container_execsync.go:271–288  ·  view source on GitHub ↗

execInContainer executes a command inside the container synchronously, and redirects stdio stream properly. This function only returns when the exec process exits, this means that: 1) As long as the exec process is running, the goroutine in the cri plugin will be running and wait for the exit code;

(ctx context.Context, id string, opts execOptions)

Source from the content-addressed store, hash-verified

269// this case, the CRI plugin will still have a goroutine waiting for the exec process
270// to exit and log the exit code, but dockershim won't.
271func (c *criService) execInContainer(ctx context.Context, id string, opts execOptions) (*uint32, error) {
272 span := tracing.SpanFromContext(ctx)
273 // Get container from our container store.
274 cntr, err := c.containerStore.Get(id)
275
276 if err != nil {
277 return nil, fmt.Errorf("failed to find container %q in store: %w", id, err)
278 }
279 id = cntr.ID
280 span.SetAttributes(tracing.Attribute("container.id", id))
281
282 state := cntr.Status.Get().State()
283 if state != runtime.ContainerState_CONTAINER_RUNNING {
284 return nil, fmt.Errorf("container is in %s state", criContainerStateToString(state))
285 }
286
287 return c.execInternal(ctx, cntr.Container, id, opts)
288}
289
290// drainExecSyncIO drains process IO with timeout after exec init process exits.
291//

Callers 2

ExecSyncMethod · 0.95
ExecMethod · 0.80

Implementers 1

criServiceinternal/cri/server/service.go

Calls 7

execInternalMethod · 0.95
SpanFromContextFunction · 0.92
AttributeFunction · 0.92
SetAttributesMethod · 0.80
GetMethod · 0.65
StateMethod · 0.65

Tested by

no test coverage detected