Skip to content

Commit 9d56fd8

Browse files
committed
Add skeleton of new libpod API
Signed-off-by: Matthew Heon <[email protected]>
1 parent 8c496a1 commit 9d56fd8

File tree

4 files changed

+348
-0
lines changed

4 files changed

+348
-0
lines changed

libpod/ctr/container.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package ctr
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
var (
8+
// ErrNotImplemented indicates that functionality is not yet implemented
9+
ErrNotImplemented = fmt.Errorf("NOT IMPLEMENTED")
10+
)
11+
12+
// Container is a single OCI container
13+
type Container struct {
14+
// TODO populate
15+
}
16+
17+
// Create creates a container in the OCI runtime
18+
func (c *Container) Create() error {
19+
return ErrNotImplemented
20+
}
21+
22+
// Start starts a container
23+
func (c *Container) Start() error {
24+
return ErrNotImplemented
25+
}
26+
27+
// Stop stops a container
28+
func (c *Container) Stop() error {
29+
return ErrNotImplemented
30+
}
31+
32+
// Kill sends a signal to a container
33+
func (c *Container) Kill(signal uint) error {
34+
return ErrNotImplemented
35+
}
36+
37+
// Exec starts a new process inside the container
38+
// TODO does this need arguments?
39+
// TODO should this return anything besides error?
40+
func (c *Container) Exec() error {
41+
return ErrNotImplemented
42+
}
43+
44+
// Attach attaches to a container
45+
// TODO does this need arguments?
46+
// TODO should this return anything besides error?
47+
func (c *Container) Attach() error {
48+
return ErrNotImplemented
49+
}
50+
51+
// Mount mounts a container's filesystem on the host
52+
// The path where the container has been mounted is returned
53+
func (c *Container) Mount() (string, error) {
54+
return "", ErrNotImplemented
55+
}
56+
57+
// Status gets a container's status
58+
// TODO this should return relevant information about container state
59+
func (c *Container) Status() error {
60+
return ErrNotImplemented
61+
}

libpod/options.go

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package libpod
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/containers/storage"
7+
"github.com/kubernetes-incubator/cri-o/libpod/ctr"
8+
"github.com/kubernetes-incubator/cri-o/libpod/pod"
9+
)
10+
11+
var (
12+
runtimeNotImplemented = func(rt *Runtime) error {
13+
return fmt.Errorf("NOT IMPLEMENTED")
14+
}
15+
ctrNotImplemented = func(c *ctr.Container) error {
16+
return fmt.Errorf("NOT IMPLEMENTED")
17+
}
18+
)
19+
20+
const (
21+
// IPCNamespace represents the IPC namespace
22+
IPCNamespace = "ipc"
23+
// MountNamespace represents the mount namespace
24+
MountNamespace = "mount"
25+
// NetNamespace represents the network namespace
26+
NetNamespace = "net"
27+
// PIDNamespace represents the PID namespace
28+
PIDNamespace = "pid"
29+
// UserNamespace represents the user namespace
30+
UserNamespace = "user"
31+
// UTSNamespace represents the UTS namespace
32+
UTSNamespace = "uts"
33+
)
34+
35+
// Runtime Creation Options
36+
37+
// WithStorageConfig uses the given configuration to set up container storage
38+
// If this is not specified, the system default configuration will be used
39+
// instead
40+
func WithStorageConfig(config *storage.StoreOptions) RuntimeOption {
41+
return runtimeNotImplemented
42+
}
43+
44+
// WithImageConfig uses the given configuration to set up image handling
45+
// If this is not specified, the system default configuration will be used
46+
// instead
47+
func WithImageConfig(defaultTransport string, insecureRegistries, registries []string) RuntimeOption {
48+
return runtimeNotImplemented
49+
}
50+
51+
// WithSignaturePolicy specifies the path of a file which decides how trust is
52+
// managed for images we've pulled.
53+
// If this is not specified, the system default configuration will be used
54+
// instead
55+
func WithSignaturePolicy(path string) RuntimeOption {
56+
return runtimeNotImplemented
57+
}
58+
59+
// WithOCIRuntime specifies an OCI runtime to use for running containers
60+
func WithOCIRuntime(runtimePath string) RuntimeOption {
61+
return runtimeNotImplemented
62+
}
63+
64+
// WithConmonPath specifies the path to the conmon binary which manages the
65+
// runtime
66+
func WithConmonPath(path string) RuntimeOption {
67+
return runtimeNotImplemented
68+
}
69+
70+
// WithConmonEnv specifies the environment variable list for the conmon process
71+
func WithConmonEnv(environment []string) RuntimeOption {
72+
return runtimeNotImplemented
73+
}
74+
75+
// WithCgroupManager specifies the manager implementation name which is used to
76+
// handle cgroups for containers
77+
func WithCgroupManager(manager string) RuntimeOption {
78+
return runtimeNotImplemented
79+
}
80+
81+
// WithSELinux enables SELinux on the container server
82+
func WithSELinux() RuntimeOption {
83+
return runtimeNotImplemented
84+
}
85+
86+
// WithApparmorProfile specifies the apparmor profile name which will be used as
87+
// the default for created containers
88+
func WithApparmorProfile(profile string) RuntimeOption {
89+
return runtimeNotImplemented
90+
}
91+
92+
// WithSeccompProfile specifies the seccomp profile which will be used as the
93+
// default for created containers
94+
func WithSeccompProfile(profilePath string) RuntimeOption {
95+
return runtimeNotImplemented
96+
}
97+
98+
// WithPidsLimit specifies the maximum number of processes each container is
99+
// restricted to
100+
func WithPidsLimit(limit int64) RuntimeOption {
101+
return runtimeNotImplemented
102+
}
103+
104+
// Container Creation Options
105+
106+
// WithRootFSFromPath uses the given path as a container's root filesystem
107+
// No further setup is performed on this path
108+
func WithRootFSFromPath(path string) CtrCreateOption {
109+
return ctrNotImplemented
110+
}
111+
112+
// WithRootFSFromImage sets up a fresh root filesystem using the given image
113+
// If useImageConfig is specified, image volumes, environment variables, and
114+
// other configuration from the image will be added to the config
115+
func WithRootFSFromImage(image string, useImageConfig bool) CtrCreateOption {
116+
return ctrNotImplemented
117+
}
118+
119+
// WithSharedNamespaces sets a container to share namespaces with another
120+
// container. If the from container belongs to a pod, the new container will
121+
// be added to the pod.
122+
// By default no namespaces are shared. To share a namespace, add the Namespace
123+
// string constant to the map as a key
124+
func WithSharedNamespaces(from *ctr.Container, namespaces map[string]string) CtrCreateOption {
125+
return ctrNotImplemented
126+
}
127+
128+
// WithPod adds the container to a pod
129+
func WithPod(pod *pod.Pod) CtrCreateOption {
130+
return ctrNotImplemented
131+
}
132+
133+
// WithLabels adds labels to the pod
134+
func WithLabels(labels map[string]string) CtrCreateOption {
135+
return ctrNotImplemented
136+
}
137+
138+
// WithAnnotations adds annotations to the pod
139+
func WithAnnotations(annotations map[string]string) CtrCreateOption {
140+
return ctrNotImplemented
141+
}
142+
143+
// WithName sets the container's name
144+
func WithName(name string) CtrCreateOption {
145+
return ctrNotImplemented
146+
}
147+
148+
// WithStopSignal sets the signal that will be sent to stop the container
149+
func WithStopSignal(signal uint) CtrCreateOption {
150+
return ctrNotImplemented
151+
}

libpod/pod/pod.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package pod
2+
3+
import (
4+
"github.com/kubernetes-incubator/cri-o/libpod/ctr"
5+
)
6+
7+
// Pod represents a group of containers that may share namespaces
8+
type Pod struct {
9+
// TODO populate
10+
}
11+
12+
// Start starts all containers within a pod that are not already running
13+
func (p *Pod) Start() error {
14+
return ctr.ErrNotImplemented
15+
}
16+
17+
// Stop stops all containers within a pod that are not already stopped
18+
func (p *Pod) Stop() error {
19+
return ctr.ErrNotImplemented
20+
}
21+
22+
// Kill sends a signal to all running containers within a pod
23+
func (p *Pod) Kill(signal uint) error {
24+
return ctr.ErrNotImplemented
25+
}
26+
27+
// GetContainers retrieves the containers in the pod
28+
func (p *Pod) GetContainers() ([]*ctr.Container, error) {
29+
return nil, ctr.ErrNotImplemented
30+
}
31+
32+
// Status gets the status of all containers in the pod
33+
// TODO This should return a summary of the states of all containers in the pod
34+
func (p *Pod) Status() error {
35+
return ctr.ErrNotImplemented
36+
}

libpod/runtime.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package libpod
2+
3+
import (
4+
"github.com/kubernetes-incubator/cri-o/libpod/ctr"
5+
"github.com/kubernetes-incubator/cri-o/libpod/pod"
6+
spec "github.com/opencontainers/runtime-spec/specs-go"
7+
)
8+
9+
// ContainerFilter is a function to determine whether a container is included
10+
// in command output. Containers to be outputted are tested using the function.
11+
// A true return will include the container, a false return will exclude it.
12+
type ContainerFilter func(*ctr.Container) bool
13+
14+
// PodFilter is a function to determine whether a pod is included in command
15+
// output. Pods to be outputted are tested using the function. A true return
16+
// will include the pod, a false return will exclude it.
17+
type PodFilter func(*pod.Pod) bool
18+
19+
// A RuntimeOption is a functional option which alters the Runtime created by
20+
// NewRuntime
21+
type RuntimeOption func(*Runtime) error
22+
23+
// A CtrCreateOption is a functional option which alters the Container created
24+
// by NewContainer
25+
type CtrCreateOption func(*ctr.Container) error
26+
27+
// Runtime is the core libpod runtime
28+
type Runtime struct {
29+
// TODO populate
30+
}
31+
32+
// NewRuntime creates a new container runtime
33+
func NewRuntime(options ...RuntimeOption) (*Runtime, error) {
34+
return nil, ctr.ErrNotImplemented
35+
}
36+
37+
// NewContainer creates a new container from a given OCI config
38+
func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (*ctr.Container, error) {
39+
return nil, ctr.ErrNotImplemented
40+
}
41+
42+
// RemoveContainer removes the given container
43+
// If force is specified, the container will be stopped first
44+
// Otherwise, RemoveContainer will return an error if the container is running
45+
func (r *Runtime) RemoveContainer(c *ctr.Container, force bool) error {
46+
return ctr.ErrNotImplemented
47+
}
48+
49+
// GetContainer retrieves a container by its ID
50+
func (r *Runtime) GetContainer(id string) (*ctr.Container, error) {
51+
return nil, ctr.ErrNotImplemented
52+
}
53+
54+
// LookupContainer looks up a container by its name or a partial ID
55+
// If a partial ID is not unique, an error will be returned
56+
func (r *Runtime) LookupContainer(idOrName string) (*ctr.Container, error) {
57+
return nil, ctr.ErrNotImplemented
58+
}
59+
60+
// GetContainers retrieves all containers from the state
61+
// Filters can be provided which will determine what containers are included in
62+
// the output. Multiple filters are handled by ANDing their output, so only
63+
// containers matching all filters are returned
64+
func (r *Runtime) GetContainers(filters ...ContainerFilter) ([]*ctr.Container, error) {
65+
return nil, ctr.ErrNotImplemented
66+
}
67+
68+
// NewPod makes a new, empty pod
69+
func (r *Runtime) NewPod() (*pod.Pod, error) {
70+
return nil, ctr.ErrNotImplemented
71+
}
72+
73+
// RemovePod removes a pod and all containers in it
74+
// If force is specified, all containers in the pod will be stopped first
75+
// Otherwise, RemovePod will return an error if any container in the pod is running
76+
// Remove acts atomically, removing all containers or no containers
77+
func (r *Runtime) RemovePod(p *pod.Pod, force bool) error {
78+
return ctr.ErrNotImplemented
79+
}
80+
81+
// GetPod retrieves a pod by its ID
82+
func (r *Runtime) GetPod(id string) (*pod.Pod, error) {
83+
return nil, ctr.ErrNotImplemented
84+
}
85+
86+
// LookupPod retrieves a pod by its name or a partial ID
87+
// If a partial ID is not unique, an error will be returned
88+
func (r *Runtime) LookupPod(idOrName string) (*pod.Pod, error) {
89+
return nil, ctr.ErrNotImplemented
90+
}
91+
92+
// GetPods retrieves all pods
93+
// Filters can be provided which will determine which pods are included in the
94+
// output. Multiple filters are handled by ANDing their output, so only pods
95+
// matching all filters are returned
96+
func (r *Runtime) GetPods(filters ...PodFilter) ([]*pod.Pod, error) {
97+
return nil, ctr.ErrNotImplemented
98+
}
99+
100+
// TODO Add image API

0 commit comments

Comments
 (0)