Documentation ¶
Index ¶
- Constants
- Variables
- func NoPodError(ns, pod string) error
- func ShortContainerId(cid string) string
- func SortMountPointsByLongSourceFirst(mounts []*MountPoint)
- func TransferToHostPathForContainer(c *Container, ctrPath string, respectSymbol bool) (string, error)
- type AlpineStatus
- type Container
- type ContainerEngine
- type ContainerEngineFeature
- type ContainerRole
- type ContainerState
- type EngineDetailContainer
- type EngineSimpleContainer
- type ExecAsyncResult
- type ExecAsyncResultCode
- type ExecRequest
- type ExecResult
- type Interface
- type LocalAgentMeta
- type MetaListener
- type MetaStore
- type MountPoint
- type NsEnterType
- type Pod
- type TzInfo
Constants ¶
View Source
const ( Runc = "runc" Rund = "rund" ContainerEngineFeatureCopy ContainerEngineFeature = iota )
View Source
const ( HackInit = iota HackIng HackOk HackSkipped HackRetryError )
View Source
const (
DefaultSampleOutputLength = 1024
)
Variables ¶
View Source
var ( ErrMultiBiz = errors.New("multi biz containers") ErrNoBiz = errors.New("no biz container") ErrNoSuchContainer = errors.New("no such container") )
TODO 我们推出一个规范 让用户按我们规范做 就认为它是主容器
Functions ¶
func NoPodError ¶
func ShortContainerId ¶
func SortMountPointsByLongSourceFirst ¶
func SortMountPointsByLongSourceFirst(mounts []*MountPoint)
Types ¶
type AlpineStatus ¶
type AlpineStatus uint8
const ( AlpineStatusUnknown AlpineStatus = iota // AlpineStatusYes indicates that the container is an alpine-based container AlpineStatusYes // AlpineStatusNo indicates that the container is not an alpine-based container AlpineStatusNo )
func (AlpineStatus) MarshalText ¶
func (a AlpineStatus) MarshalText() ([]byte, error)
type Container ¶
type Container struct { // container 可能会依赖底层实现, 因此这里不让它依赖具体的实现类 Id string // 所属的pod Pod *Pod `json:"-"` // ContainerName example: // /k8s_POD_xxx // /k8s_xxx ContainerName string // K8sContainerName k8s container name K8sContainerName string // 常见状态 State ContainerState // 容器常见配置 Labels map[string]string Env map[string]string // 挂载点 已经转换到hostfs Mounts []*MountPoint // docker 的 MergedDir 特有字段, 已经转换到hostfs MergedDir string ContainerRole ContainerRole // 该 container 所属的 pod 的 sandbox cid SandboxID string Tz TzInfo // 该容器是否已经被我们hack过 Hacked int // pouch 场景, 只有登录到 container 里 才能获取 daemonset 的 hostname Hostname string // 运行时 Runtime string // NetworkMode NetworkMode string // If PidMode is "host", it means that the container uses the pid namespace of the physical machine. PidMode string // docker json log: https://docs.docker.com/config/containers/logging/json-file/ LogPath string // Attributes can be used to prevent arbitrary extension fields Attributes sync.Map // The number of zombie processes inside the container ZombieCount int // pid 1 process name Pid1Name string // Whether pid 1 has the ability to recycle zombie processes Pid1CanRecycleZombieProcesses bool }
type ContainerEngine ¶
type ContainerEngine interface { // Init initializes the engine Init() error // Type returns engine type, such as "docker" "containerd" Type() string ListAllContainers(ctx context.Context) ([]*EngineSimpleContainer, error) GetContainerDetail(ctx context.Context, cid string) (*EngineDetailContainer, error) Exec(ctx context.Context, c *Container, req ExecRequest) (ExecResult, error) // ExecAsync runs command in target container ExecAsync(ctx context.Context, c *Container, req ExecRequest) (ExecAsyncResult, error) // CopyToContainer copies file from src(in agent) to dst(in container) CopyToContainer(ctx context.Context, c *Container, src, dst string) error // CopyFromContainer copies file from src(in container) to dst(in agent) CopyFromContainer(ctx context.Context, c *Container, src, dst string) error // Supports checks if engine supports the specified feature Supports(feature ContainerEngineFeature) bool }
ContainerEngine is an abstraction for docker/pouch/containerd
type ContainerEngineFeature ¶
type ContainerEngineFeature uint8
type ContainerRole ¶
type ContainerRole string
ContainerRole biz sidecar sandbox
const ( // ContainerRoleBiz The target container is the pod's biz(main) container. ContainerRoleBiz ContainerRole = "biz" // ContainerRoleSidecar The target container is the pod's sidecar. ContainerRoleSidecar ContainerRole = "sidecar" // ContainerRoleSandbox The target container is the pod's sandbox. ContainerRoleSandbox ContainerRole = "sandbox" )
type ContainerState ¶
func (*ContainerState) IsRunning ¶
func (s *ContainerState) IsRunning() bool
type EngineDetailContainer ¶
type EngineDetailContainer struct { ID string Name string Labels map[string]string Env []string Source interface{} IsSandbox bool SandboxId string Hostname string Runtime string NetworkMode string PidMode string MergedDir string LogPath string Mounts []*MountPoint State ContainerState }
EngineDetailContainer Contains the most common container properties, provided by almost all advanced container runtimes.
type EngineSimpleContainer ¶
type ExecAsyncResult ¶
type ExecAsyncResultCode ¶
type ExecRequest ¶
type ExecRequest struct { Cmd []string `json:"cmd"` Env []string `json:"env"` WorkingDir string `json:"workingDir"` Input io.Reader // User is the user passed to docker exec, defaults to 'root' User string FixOut bool NoWrapCmdWithTimeout bool }
ExecRequest wraps parameters need for exec
type ExecResult ¶
func (*ExecResult) SampleOutput ¶
func (r *ExecResult) SampleOutput() (stdout string, stderr string)
func (*ExecResult) SampleOutputLength ¶
func (r *ExecResult) SampleOutputLength(length int) (stdout string, stderr string)
type Interface ¶
type Interface interface { MetaStore // CopyToContainer copies file to container CopyToContainer(ctx context.Context, c *Container, srcPath, dstPath string) error // CopyFromContainer copies file from container CopyFromContainer(ctx context.Context, c *Container, srcPath, dstPath string) error // Exec runs command in target container Exec(ctx context.Context, c *Container, req ExecRequest) (ExecResult, error) // ExecAsync runs command in target container ExecAsync(ctx context.Context, c *Container, req ExecRequest) (ExecAsyncResult, error) Start() error Stop() // Engine returns the underlying ContainerEngine Engine() ContainerEngine }
Interface is the entrance of accessing pod/container meta and executing container commands.
type LocalAgentMeta ¶
type LocalAgentMeta interface { Namespace() string PodName() string PodIP() string NodeName() string NodeIP() string Node() *v1.Node IsLocalPod(pod *v1.Pod) bool }
LocalAgentMeta providers local agent basic info
type MetaListener ¶
type MetaListener interface {
OnAnyPodChanged()
}
type MetaStore ¶
type MetaStore interface { // GetAllPods returns all local pods GetAllPods() []*Pod // GetPod queries one local pod by namespace and podName. // Returns an error if not found. GetPod(namespace, podName string) (*Pod, error) // GetPod queries one local pod by its sandbox id. // Returns an error if not found. GetPodBySandboxId(sandboxId string) (*Pod, error) // GetContainerByCid queries one container by cid GetContainerByCid(cid string) (*Container, bool) LocalAgentMeta() LocalAgentMeta Start() error Stop() AddListener(MetaListener) RemoveListener(MetaListener) }
type MountPoint ¶
type NsEnterType ¶
type NsEnterType uint8
Click to show internal directories.
Click to hide internal directories.