io

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package io has been copied from https://github.com/containerd/containerd/tree/c07fb699a9a0c9792d21a759c87d0d60de11bfb9/internal/cri/io with some small changes to avoid importing k8s.io/cri-api (except in tests) and github.com/docker/go-metrics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCRILogger

func NewCRILogger(path string, w io.Writer, stream StreamType, maxLen int) (io.WriteCloser, <-chan struct{})

NewCRILogger returns a write closer which redirect container log into log file, and decorate the log line into CRI defined format. It also returns a channel which indicates whether the logger is stopped. maxLen is the max length limit of a line. A line longer than the limit will be cut into multiple lines.

func NewDiscardLogger

func NewDiscardLogger() io.WriteCloser

NewDiscardLogger creates logger which discards all the input.

Types

type AttachOptions

type AttachOptions struct {
	Stdin     io.Reader
	Stdout    io.WriteCloser
	Stderr    io.WriteCloser
	Tty       bool
	StdinOnce bool
	// CloseStdin is the function to close container stdin.
	CloseStdin func() error
}

AttachOptions specifies how to attach to a container.

type ContainerIO

type ContainerIO struct {
	// contains filtered or unexported fields
}

ContainerIO holds the container io.

func NewContainerIO

func NewContainerIO(id string, opts ...ContainerIOOpts) (_ *ContainerIO, err error)

NewContainerIO creates container io.

func (*ContainerIO) AddOutput

func (c *ContainerIO) AddOutput(name string, stdout, stderr io.WriteCloser) (io.WriteCloser, io.WriteCloser)

AddOutput adds new write closers to the container stream, and returns existing write closers if there are any.

func (*ContainerIO) Cancel

func (c *ContainerIO) Cancel()

Cancel cancels container io.

func (*ContainerIO) Close

func (c *ContainerIO) Close() error

Close closes all FIFOs.

func (*ContainerIO) Config

func (c *ContainerIO) Config() cio.Config

Config returns io config.

func (*ContainerIO) Pipe

func (c *ContainerIO) Pipe()

Pipe creates container fifos and pipe container output to output stream.

func (*ContainerIO) Wait

func (c *ContainerIO) Wait()

Wait waits container io to finish.

type ContainerIOOpts

type ContainerIOOpts func(*ContainerIO) error

ContainerIOOpts sets specific information to newly created ContainerIO.

func WithFIFOs

func WithFIFOs(fifos *cio.FIFOSet) ContainerIOOpts

WithFIFOs specifies existing fifos for the container io.

func WithNewFIFOs

func WithNewFIFOs(root string, tty, stdin bool) ContainerIOOpts

WithNewFIFOs creates new fifos for the container io.

func WithStreams

func WithStreams(address string, tty, stdin bool) ContainerIOOpts

WithStreams creates new streams for the container io. The stream address is in format of `protocol://address?stream_id=xyz`. It allocates ContainerID-stdin, ContainerID-stdout and ContainerID-stderr as streaming IDs. For example, that advertiser address of shim is `ttrpc+unix:///run/demo.sock` and container ID is `app`. There are three streams if stdin is enabled and TTY is disabled.

  • Stdin: ttrpc+unix:///run/demo.sock?stream_id=app-stdin
  • Stdout: ttrpc+unix:///run/demo.sock?stream_id=app-stdout
  • stderr: ttrpc+unix:///run/demo.sock?stream_id=app-stderr

The streaming IDs will be used as unique key to establish stream tunnel. And it should support reconnection with the same streaming ID if containerd restarts.

type LogTag

type LogTag string

LogTag is the tag of a log line in CRI container log. Currently defined log tags: * First tag: Partial/Full - P/F. The field in the container log format can be extended to include multiple tags by using a delimiter, but changes should be rare. If it becomes clear that better extensibility is desired, a more extensible format (e.g., json) should be adopted as a replacement and/or addition.

const (
	// LogTagPartial means the line is part of multiple lines.
	LogTagPartial LogTag = "P"
	// LogTagFull means the line is a single full line or the end of multiple lines.
	LogTagFull LogTag = "F"
)

type StreamType

type StreamType string

StreamType is the type of the stream, stdout/stderr.

const (
	// Stdin stream type.
	Stdin StreamType = "stdin"
	// Stdout stream type.
	Stdout StreamType = "stdout"
	// Stderr stream type.
	Stderr StreamType = "stderr"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL