cri: restart created container with correct io type
Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
parent
42f778fc14
commit
7cead88004
@ -257,7 +257,6 @@ func (c *criService) loadContainer(ctx context.Context, cntr containerd.Containe
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
id := cntr.ID()
|
id := cntr.ID()
|
||||||
containerDir := c.getContainerRootDir(id)
|
containerDir := c.getContainerRootDir(id)
|
||||||
volatileContainerDir := c.getVolatileContainerRootDir(id)
|
|
||||||
var container containerstore.Container
|
var container containerstore.Container
|
||||||
// Load container metadata.
|
// Load container metadata.
|
||||||
exts, err := cntr.Extensions(ctx)
|
exts, err := cntr.Extensions(ctx)
|
||||||
@ -336,9 +335,7 @@ func (c *criService) loadContainer(ctx context.Context, cntr containerd.Containe
|
|||||||
// NOTE: Another possibility is that we've tried to start the container, but
|
// NOTE: Another possibility is that we've tried to start the container, but
|
||||||
// containerd got restarted during that. In that case, we still
|
// containerd got restarted during that. In that case, we still
|
||||||
// treat the container as `CREATED`.
|
// treat the container as `CREATED`.
|
||||||
containerIO, err = cio.NewContainerIO(id,
|
containerIO, err = c.createContainerIO(id, meta.SandboxID, meta.Config)
|
||||||
cio.WithNewFIFOs(volatileContainerDir, meta.Config.GetTty(), meta.Config.GetStdin()),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create container io: %w", err)
|
return fmt.Errorf("failed to create container io: %w", err)
|
||||||
}
|
}
|
||||||
@ -465,3 +462,31 @@ func cleanupOrphanedIDDirs(ctx context.Context, cntrs []containerd.Container, ba
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *criService) createContainerIO(containerID, sandboxID string, config *runtime.ContainerConfig) (*cio.ContainerIO, error) {
|
||||||
|
if config == nil {
|
||||||
|
return nil, fmt.Errorf("ContainerConfig should not be nil when create container io")
|
||||||
|
}
|
||||||
|
sb, err := c.sandboxStore.Get(sandboxID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w", sandboxID, err)
|
||||||
|
}
|
||||||
|
ociRuntime, err := c.config.GetSandboxRuntime(sb.Config, sb.Metadata.RuntimeHandler)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get sandbox runtime: %w", err)
|
||||||
|
}
|
||||||
|
var containerIO *cio.ContainerIO
|
||||||
|
switch ociRuntime.IOType {
|
||||||
|
case criconfig.IOTypeStreaming:
|
||||||
|
containerIO, err = cio.NewContainerIO(containerID,
|
||||||
|
cio.WithStreams(sb.Endpoint.Address, config.GetTty(), config.GetStdin()))
|
||||||
|
default:
|
||||||
|
volatileContainerRootDir := c.getVolatileContainerRootDir(containerID)
|
||||||
|
containerIO, err = cio.NewContainerIO(containerID,
|
||||||
|
cio.WithNewFIFOs(volatileContainerRootDir, config.GetTty(), config.GetStdin()))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create container io: %w", err)
|
||||||
|
}
|
||||||
|
return containerIO, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user