libct: remove Factory interface

The only implementation is LinuxFactory, let's use this directly.

Move the piece of documentation about Create from removed factory.go to
the factory_linux.go.

The LinuxFactory is to be removed later.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2022-02-10 19:13:17 -08:00
parent 71bc308b7f
commit a78c9a0184
3 changed files with 17 additions and 45 deletions

View File

@@ -1,30 +0,0 @@
package libcontainer
import (
"github.com/opencontainers/runc/libcontainer/configs"
)
type Factory interface {
// Creates a new container with the given id and starts the initial process inside it.
// id must be a string containing only letters, digits and underscores and must contain
// between 1 and 1024 characters, inclusive.
//
// The id must not already be in use by an existing container. Containers created using
// a factory with the same path (and filesystem) must have distinct ids.
//
// Returns the new container with a running process.
//
// On error, any partially created container parts are cleaned up (the operation is atomic).
Create(id string, config *configs.Config) (Container, error)
// Load takes an ID for an existing container and returns the container information
// from the state. This presents a read only view of the container.
Load(id string) (Container, error)
// StartInitialization is an internal API to libcontainer used during the reexec of the
// container.
StartInitialization() error
// Type returns info string about factory type (e.g. lxc, libcontainer...)
Type() string
}

View File

@@ -28,7 +28,7 @@ const (
var idRegex = regexp.MustCompile(`^[\w+-\.]+$`)
// New returns a linux based container factory based in the root directory.
func New(root string) (Factory, error) {
func New(root string) (*LinuxFactory, error) {
if root != "" {
if err := os.MkdirAll(root, 0o700); err != nil {
return nil, err
@@ -45,6 +45,17 @@ type LinuxFactory struct {
Root string
}
// Create creates a new container with the given id and starts the initial
// process inside it.
//
// The id must not be empty and consists of only the following characters:
// ASCII letters, digits, underscore, plus, minus, period. The id must be
// unique and non-existent for the factory with same root path.
//
// Returns the new container with a running process.
//
// On error, any partially created container parts are cleaned up (the
// operation is atomic).
func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, error) {
if l.Root == "" {
return nil, errors.New("root not set")
@@ -113,6 +124,9 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
return c, nil
}
// Load takes an ID for an existing container and returns the container
// information from the state. This presents a read only view of the
// container.
func (l *LinuxFactory) Load(id string) (Container, error) {
if l.Root == "" {
return nil, errors.New("root not set")
@@ -155,10 +169,6 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
return c, nil
}
func (l *LinuxFactory) Type() string {
return "libcontainer"
}
// StartInitialization loads a container by opening the pipe fd from the parent to read the configuration and state
// This is a low level implementation detail of the reexec and should not be consumed externally
func (l *LinuxFactory) StartInitialization() (err error) {

View File

@@ -21,16 +21,8 @@ func TestFactoryNew(t *testing.T) {
if factory == nil {
t.Fatal("factory should not be nil")
}
lfactory, ok := factory.(*LinuxFactory)
if !ok {
t.Fatal("expected linux factory returned on linux based systems")
}
if lfactory.Root != root {
t.Fatalf("expected factory root to be %q but received %q", root, lfactory.Root)
}
if factory.Type() != "libcontainer" {
t.Fatalf("unexpected factory type: %q, expected %q", factory.Type(), "libcontainer")
if factory.Root != root {
t.Fatalf("expected factory root to be %q but received %q", root, factory.Root)
}
}