Skip to content

Commit 7cead88

Browse files
committed
cri: restart created container with correct io type
Signed-off-by: Abel Feng <[email protected]>
1 parent 42f778f commit 7cead88

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

internal/cri/server/restart.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func (c *criService) loadContainer(ctx context.Context, cntr containerd.Containe
257257
defer cancel()
258258
id := cntr.ID()
259259
containerDir := c.getContainerRootDir(id)
260-
volatileContainerDir := c.getVolatileContainerRootDir(id)
261260
var container containerstore.Container
262261
// Load container metadata.
263262
exts, err := cntr.Extensions(ctx)
@@ -336,9 +335,7 @@ func (c *criService) loadContainer(ctx context.Context, cntr containerd.Containe
336335
// NOTE: Another possibility is that we've tried to start the container, but
337336
// containerd got restarted during that. In that case, we still
338337
// treat the container as `CREATED`.
339-
containerIO, err = cio.NewContainerIO(id,
340-
cio.WithNewFIFOs(volatileContainerDir, meta.Config.GetTty(), meta.Config.GetStdin()),
341-
)
338+
containerIO, err = c.createContainerIO(id, meta.SandboxID, meta.Config)
342339
if err != nil {
343340
return fmt.Errorf("failed to create container io: %w", err)
344341
}
@@ -465,3 +462,31 @@ func cleanupOrphanedIDDirs(ctx context.Context, cntrs []containerd.Container, ba
465462
}
466463
return nil
467464
}
465+
466+
func (c *criService) createContainerIO(containerID, sandboxID string, config *runtime.ContainerConfig) (*cio.ContainerIO, error) {
467+
if config == nil {
468+
return nil, fmt.Errorf("ContainerConfig should not be nil when create container io")
469+
}
470+
sb, err := c.sandboxStore.Get(sandboxID)
471+
if err != nil {
472+
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w", sandboxID, err)
473+
}
474+
ociRuntime, err := c.config.GetSandboxRuntime(sb.Config, sb.Metadata.RuntimeHandler)
475+
if err != nil {
476+
return nil, fmt.Errorf("failed to get sandbox runtime: %w", err)
477+
}
478+
var containerIO *cio.ContainerIO
479+
switch ociRuntime.IOType {
480+
case criconfig.IOTypeStreaming:
481+
containerIO, err = cio.NewContainerIO(containerID,
482+
cio.WithStreams(sb.Endpoint.Address, config.GetTty(), config.GetStdin()))
483+
default:
484+
volatileContainerRootDir := c.getVolatileContainerRootDir(containerID)
485+
containerIO, err = cio.NewContainerIO(containerID,
486+
cio.WithNewFIFOs(volatileContainerRootDir, config.GetTty(), config.GetStdin()))
487+
}
488+
if err != nil {
489+
return nil, fmt.Errorf("failed to create container io: %w", err)
490+
}
491+
return containerIO, nil
492+
}

0 commit comments

Comments
 (0)