mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-05 15:37:02 +08:00
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:
@@ -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
|
|
||||||
}
|
|
@@ -28,7 +28,7 @@ const (
|
|||||||
var idRegex = regexp.MustCompile(`^[\w+-\.]+$`)
|
var idRegex = regexp.MustCompile(`^[\w+-\.]+$`)
|
||||||
|
|
||||||
// New returns a linux based container factory based in the root directory.
|
// 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 root != "" {
|
||||||
if err := os.MkdirAll(root, 0o700); err != nil {
|
if err := os.MkdirAll(root, 0o700); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -45,6 +45,17 @@ type LinuxFactory struct {
|
|||||||
Root string
|
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) {
|
func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, error) {
|
||||||
if l.Root == "" {
|
if l.Root == "" {
|
||||||
return nil, errors.New("root not set")
|
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
|
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) {
|
func (l *LinuxFactory) Load(id string) (Container, error) {
|
||||||
if l.Root == "" {
|
if l.Root == "" {
|
||||||
return nil, errors.New("root not set")
|
return nil, errors.New("root not set")
|
||||||
@@ -155,10 +169,6 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
|
|||||||
return c, nil
|
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
|
// 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
|
// This is a low level implementation detail of the reexec and should not be consumed externally
|
||||||
func (l *LinuxFactory) StartInitialization() (err error) {
|
func (l *LinuxFactory) StartInitialization() (err error) {
|
||||||
|
@@ -21,16 +21,8 @@ func TestFactoryNew(t *testing.T) {
|
|||||||
if factory == nil {
|
if factory == nil {
|
||||||
t.Fatal("factory should not be nil")
|
t.Fatal("factory should not be nil")
|
||||||
}
|
}
|
||||||
lfactory, ok := factory.(*LinuxFactory)
|
if factory.Root != root {
|
||||||
if !ok {
|
t.Fatalf("expected factory root to be %q but received %q", root, factory.Root)
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user