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)
| 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. |
| 271 | func (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 | // |
no test coverage detected