Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-daemon/pkg/container/container.go
2499 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package container
6
7
import (
8
"context"
9
10
"golang.org/x/xerrors"
11
12
"github.com/containerd/containerd/api/types/task"
13
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
14
)
15
16
// Runtime abstracts over the different container runtimes out there w.r.t. to the features we need from those runtimes
17
type Runtime interface {
18
// WaitForContainer waits for workspace container to come into existence.
19
// When this function returns no guarantee is made about the lifecycle state of the container, just its mere existence.
20
// Implementors have to respect context cancelation.
21
WaitForContainer(ctx context.Context, workspaceInstanceID string) (id ID, err error)
22
23
// WaitForContainerStop waits for a workspace container to be deleted.
24
// When this function returns without error, it's guaranteed that the container is gone.
25
// Implementors have to respect context cancelation.
26
WaitForContainerStop(ctx context.Context, workspaceInstanceID string) error
27
28
// ContainerExists finds out if a container with the given ID exists. The existence of the container says nothing about the
29
// container's state, which may be running, stopped, deleted, unkown or something else.
30
ContainerExists(ctx context.Context, id ID) (exists bool, err error)
31
32
// ContainerRootfs finds the workspace container's rootfs. By default the location returned here has to be accessible from
33
// the calling process (i.e. if the calling process runs in a container itself, the returned location has to be accessible from
34
// within that container).
35
// If opts.Unmapped == true, the location returned here is relative to root mount namespace, i.e. not the container.
36
//
37
// If the container, or its rootfs, is not found ErrNotFound is returned.
38
ContainerRootfs(ctx context.Context, id ID, opts OptsContainerRootfs) (loc string, err error)
39
40
// ContainerCGroupPath finds the container's cgroup path on the node. Note: this path is not the complete path to the container's cgroup,
41
// 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 cgroup
42
// you care for, e.g. cpu: filepath.Join("/sys/fs/cgroup", "cpu", cgroupPath).
43
//
44
// If the container is not found ErrNotFound is returned.
45
// If the container has no cgroup ErrNoCGroup is returned.
46
ContainerCGroupPath(ctx context.Context, id ID) (loc string, err error)
47
48
// ContainerPID returns the PID of the container's namespace root process, e.g. the container shim.
49
ContainerPID(ctx context.Context, id ID) (pid uint64, err error)
50
51
// IsContainerdReady returns is the status of containerd.
52
IsContainerdReady(ctx context.Context) (bool, error)
53
54
GetContainerImageInfo(ctx context.Context, id ID) (*workspacev1.WorkspaceImageInfo, error)
55
56
// DisposeContainer removes a stopped container, and everything we know about it
57
DisposeContainer(ctx context.Context, workspaceInstanceID string)
58
59
GetContainerTaskInfo(ctx context.Context, id ID) (*task.Process, error)
60
61
ForceKillContainerTask(ctx context.Context, id ID) error
62
}
63
64
var (
65
// ErrNotFound means the container was not found
66
ErrNotFound = xerrors.Errorf("not found")
67
68
// ErrNoUpperdir means the container has no upperdir
69
ErrNoUpperdir = xerrors.Errorf("no upperdir available")
70
71
// ErrNoCGroup means the container has no cgroup
72
ErrNoCGroup = xerrors.Errorf("no cgroup available")
73
)
74
75
// ID represents the ID of a CRI container
76
type ID string
77
78
// OptsContainerRootfs provides options for the ContainerRootfs function
79
type OptsContainerRootfs struct {
80
Unmapped bool
81
}
82
83