Path: blob/main/components/ws-daemon/pkg/container/container.go
2499 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package container56import (7"context"89"golang.org/x/xerrors"1011"github.com/containerd/containerd/api/types/task"12workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"13)1415// Runtime abstracts over the different container runtimes out there w.r.t. to the features we need from those runtimes16type Runtime interface {17// WaitForContainer waits for workspace container to come into existence.18// When this function returns no guarantee is made about the lifecycle state of the container, just its mere existence.19// Implementors have to respect context cancelation.20WaitForContainer(ctx context.Context, workspaceInstanceID string) (id ID, err error)2122// WaitForContainerStop waits for a workspace container to be deleted.23// When this function returns without error, it's guaranteed that the container is gone.24// Implementors have to respect context cancelation.25WaitForContainerStop(ctx context.Context, workspaceInstanceID string) error2627// ContainerExists finds out if a container with the given ID exists. The existence of the container says nothing about the28// container's state, which may be running, stopped, deleted, unkown or something else.29ContainerExists(ctx context.Context, id ID) (exists bool, err error)3031// ContainerRootfs finds the workspace container's rootfs. By default the location returned here has to be accessible from32// the calling process (i.e. if the calling process runs in a container itself, the returned location has to be accessible from33// within that container).34// If opts.Unmapped == true, the location returned here is relative to root mount namespace, i.e. not the container.35//36// If the container, or its rootfs, is not found ErrNotFound is returned.37ContainerRootfs(ctx context.Context, id ID, opts OptsContainerRootfs) (loc string, err error)3839// ContainerCGroupPath finds the container's cgroup path on the node. Note: this path is not the complete path to the container's cgroup,40// but merely the suffix. To make it a complete path you need to add the cgroup base path (e.g. /sys/fs/cgroup) and the type of cgroup41// you care for, e.g. cpu: filepath.Join("/sys/fs/cgroup", "cpu", cgroupPath).42//43// If the container is not found ErrNotFound is returned.44// If the container has no cgroup ErrNoCGroup is returned.45ContainerCGroupPath(ctx context.Context, id ID) (loc string, err error)4647// ContainerPID returns the PID of the container's namespace root process, e.g. the container shim.48ContainerPID(ctx context.Context, id ID) (pid uint64, err error)4950// IsContainerdReady returns is the status of containerd.51IsContainerdReady(ctx context.Context) (bool, error)5253GetContainerImageInfo(ctx context.Context, id ID) (*workspacev1.WorkspaceImageInfo, error)5455// DisposeContainer removes a stopped container, and everything we know about it56DisposeContainer(ctx context.Context, workspaceInstanceID string)5758GetContainerTaskInfo(ctx context.Context, id ID) (*task.Process, error)5960ForceKillContainerTask(ctx context.Context, id ID) error61}6263var (64// ErrNotFound means the container was not found65ErrNotFound = xerrors.Errorf("not found")6667// ErrNoUpperdir means the container has no upperdir68ErrNoUpperdir = xerrors.Errorf("no upperdir available")6970// ErrNoCGroup means the container has no cgroup71ErrNoCGroup = xerrors.Errorf("no cgroup available")72)7374// ID represents the ID of a CRI container75type ID string7677// OptsContainerRootfs provides options for the ContainerRootfs function78type OptsContainerRootfs struct {79Unmapped bool80}818283