runtime: Convert to the new internal types package

We can now remove all the sandbox shared types and convert the rest of
the code to using the new internal types package.

This commit includes virtcontainers, cli and containerd-shim changes in
one atomic change in order to not break bisect'ibility.

Fixes: #1095

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2018-12-21 15:41:31 +01:00
parent 701afe9e60
commit b05dbe3886
52 changed files with 430 additions and 645 deletions

View File

@ -16,6 +16,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -163,7 +164,7 @@ func TestDeleteSandbox(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "ready",
},
}, nil
@ -180,8 +181,8 @@ func TestDeleteSandbox(t *testing.T) {
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
return vc.SandboxStatus{
ID: sandbox.ID(),
State: vc.State{
State: vc.StateReady,
State: types.State{
State: types.StateReady,
},
}, nil
}
@ -241,7 +242,7 @@ func TestDeleteInvalidContainerType(t *testing.T) {
vcAnnotations.ContainerTypeKey: "InvalidType",
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "created",
},
}, nil
@ -280,7 +281,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "running",
},
}, nil
@ -298,8 +299,8 @@ func TestDeleteSandboxRunning(t *testing.T) {
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
return vc.SandboxStatus{
ID: sandbox.ID(),
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}
@ -360,7 +361,7 @@ func TestDeleteRunningContainer(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "running",
},
}, nil
@ -443,7 +444,7 @@ func TestDeleteContainer(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "ready",
},
}, nil
@ -543,7 +544,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "ready",
},
}, nil
@ -552,8 +553,8 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
return vc.SandboxStatus{
ID: sandbox.ID(),
State: vc.State{
State: vc.StateReady,
State: types.State{
State: types.StateReady,
},
}, nil
}

View File

@ -14,6 +14,7 @@ import (
"time"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/pkg/katautils"
"github.com/sirupsen/logrus"
@ -175,7 +176,7 @@ information is displayed once every 5 seconds.`,
span.SetTag("container", containerID)
span.SetTag("sandbox", sandboxID)
if status.State.State == vc.StateStopped {
if status.State.State == types.StateStopped {
return fmt.Errorf("container with id %s is not running", status.ID)
}

View File

@ -15,6 +15,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -111,8 +112,8 @@ func TestEventsCLISuccessful(t *testing.T) {
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
},
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}

View File

@ -15,8 +15,9 @@ import (
"syscall"
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"
)
@ -226,8 +227,8 @@ func execute(ctx context.Context, context *cli.Context) error {
span.SetTag("container", containerID)
// container MUST be ready or running.
if status.State.State != vc.StateReady &&
status.State.State != vc.StateRunning {
if status.State.State != types.StateReady &&
status.State.State != types.StateRunning {
return fmt.Errorf("Container %s is not ready or running",
params.cID)
}
@ -248,7 +249,7 @@ func execute(ctx context.Context, context *cli.Context) error {
user = params.ociProcess.User.Username
}
cmd := vc.Cmd{
cmd := types.Cmd{
Args: params.ociProcess.Args,
Envs: envVars,
WorkDir: params.ociProcess.Cwd,

View File

@ -18,6 +18,7 @@ import (
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -77,7 +78,7 @@ func TestExecuteErrors(t *testing.T) {
}
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, vc.State{}, annotations), nil
return newSingleContainerStatus(testContainerID, types.State{}, annotations), nil
}
defer func() {
@ -99,7 +100,7 @@ func TestExecuteErrors(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
containerState := vc.State{}
containerState := types.State{}
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
}
@ -109,8 +110,8 @@ func TestExecuteErrors(t *testing.T) {
assert.False(vcmock.IsMockError(err))
// Container paused
containerState = vc.State{
State: vc.StatePaused,
containerState = types.State{
State: types.StatePaused,
}
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
@ -121,8 +122,8 @@ func TestExecuteErrors(t *testing.T) {
assert.False(vcmock.IsMockError(err))
// Container stopped
containerState = vc.State{
State: vc.StateStopped,
containerState = types.State{
State: types.StateStopped,
}
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
@ -158,8 +159,8 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -207,8 +208,8 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -274,8 +275,8 @@ func TestExecuteWithFlags(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -299,7 +300,7 @@ func TestExecuteWithFlags(t *testing.T) {
assert.True(vcmock.IsMockError(err))
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
return &vcmock.Sandbox{}, &vcmock.Container{}, &vc.Process{}, nil
}
@ -316,7 +317,7 @@ func TestExecuteWithFlags(t *testing.T) {
os.Remove(pidFilePath)
// Process ran and exited successfully
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
workload := []string{"cat", "/dev/null"}
command := exec.Command(workload[0], workload[1:]...)
@ -364,8 +365,8 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -380,7 +381,7 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
testingImpl.StatusContainerFunc = nil
}()
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
workload := []string{"cat", "/dev/null"}
command := exec.Command(workload[0], workload[1:]...)
@ -443,8 +444,8 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -495,8 +496,8 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -542,7 +543,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
workload := []string{"cat", "/dev/null"}
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
command := exec.Command(workload[0], workload[1:]...)
err := command.Start()
@ -596,8 +597,8 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -644,7 +645,7 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
workload := []string{"cat", "/dev/null"}
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
command := exec.Command(workload[0], workload[1:]...)
err := command.Start()

View File

@ -15,6 +15,7 @@ import (
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -132,7 +133,7 @@ func kill(ctx context.Context, containerID, signal string, all bool) error {
kataLog.WithField("signal", signal).WithField("container state", status.State.State).Info("kill")
// container MUST be created, running or paused
if status.State.State == vc.StateReady || status.State.State == vc.StateRunning || status.State.State == vc.StatePaused {
if status.State.State == types.StateReady || status.State.State == types.StateRunning || status.State.State == types.StatePaused {
if err := vci.KillContainer(ctx, sandboxID, containerID, signum, all); err != nil {
return err
}

View File

@ -16,6 +16,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
@ -64,8 +65,8 @@ func TestProcessSignal(t *testing.T) {
func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
annotations := map[string]string{
@ -122,8 +123,8 @@ func TestKillCLIFunctionSigtermSuccessful(t *testing.T) {
func TestKillCLIFunctionNotTerminationSignalSuccessful(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
@ -150,8 +151,8 @@ func TestKillCLIFunctionNotTerminationSignalSuccessful(t *testing.T) {
func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
annotations := map[string]string{
@ -200,8 +201,8 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
annotations := map[string]string{
@ -288,8 +289,8 @@ func TestKillCLIFunctionContainerNotExistFailure(t *testing.T) {
func TestKillCLIFunctionInvalidSignalFailure(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
@ -316,8 +317,8 @@ func TestKillCLIFunctionInvalidSignalFailure(t *testing.T) {
func TestKillCLIFunctionStatePausedSuccessful(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StatePaused,
state := types.State{
State: types.StatePaused,
}
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
@ -347,8 +348,8 @@ func TestKillCLIFunctionStatePausedSuccessful(t *testing.T) {
func TestKillCLIFunctionInvalidStateStoppedFailure(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateStopped,
state := types.State{
State: types.StateStopped,
}
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
@ -375,8 +376,8 @@ func TestKillCLIFunctionInvalidStateStoppedFailure(t *testing.T) {
func TestKillCLIFunctionKillContainerFailure(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -400,8 +401,8 @@ func TestKillCLIFunctionKillContainerFailure(t *testing.T) {
func TestKillCLIFunctionInvalidStateStoppedAllSuccess(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateStopped,
state := types.State{
State: types.StateStopped,
}
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil

View File

@ -26,6 +26,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
jaeger "github.com/uber/jaeger-client-go"
@ -444,7 +445,7 @@ func writeOCIConfigFile(spec oci.CompatOCISpec, configPath string) error {
return ioutil.WriteFile(configPath, bytes, testFileMode)
}
func newSingleContainerStatus(containerID string, containerState vc.State, annotations map[string]string) vc.ContainerStatus {
func newSingleContainerStatus(containerID string, containerState types.State, annotations map[string]string) vc.ContainerStatus {
return vc.ContainerStatus{
ID: containerID,
State: containerState,

View File

@ -11,8 +11,8 @@ import (
"fmt"
"os"
vc "github.com/kata-containers/runtime/virtcontainers"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -132,7 +132,7 @@ func networkModifyCommand(ctx context.Context, containerID, input string, opType
setExternalLoggers(ctx, kataLog)
// container MUST be running
if status.State.State != vc.StateRunning {
if status.State.State != types.StateRunning {
return fmt.Errorf("container %s is not running", containerID)
}
@ -201,7 +201,7 @@ func networkListCommand(ctx context.Context, containerID string, opType networkT
setExternalLoggers(ctx, kataLog)
// container MUST be running
if status.State.State != vc.StateRunning {
if status.State.State != types.StateRunning {
return fmt.Errorf("container %s is not running", containerID)
}

View File

@ -14,6 +14,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
@ -38,8 +39,8 @@ var (
func TestNetworkCliFunction(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
testingImpl.AddInterfaceFunc = testAddInterfaceFuncReturnNil

View File

@ -13,6 +13,7 @@ import (
"testing"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
@ -29,8 +30,8 @@ var (
func TestPauseCLIFunctionSuccessful(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
testingImpl.PauseContainerFunc = testPauseContainerFuncReturnNil
@ -77,8 +78,8 @@ func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) {
func TestPauseCLIFunctionPauseContainerFailure(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
@ -102,8 +103,8 @@ func TestPauseCLIFunctionPauseContainerFailure(t *testing.T) {
func TestResumeCLIFunctionSuccessful(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
testingImpl.ResumeContainerFunc = testResumeContainerFuncReturnNil
@ -149,8 +150,8 @@ func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) {
func TestResumeCLIFunctionPauseContainerFailure(t *testing.T) {
assert := assert.New(t)
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)

View File

@ -12,6 +12,8 @@ import (
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -80,7 +82,7 @@ func ps(ctx context.Context, containerID, format string, args []string) error {
span.SetTag("sandbox", sandboxID)
// container MUST be running
if status.State.State != vc.StateRunning {
if status.State.State != types.StateRunning {
return fmt.Errorf("Container %s is not running", containerID)
}

View File

@ -14,6 +14,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
@ -95,8 +96,8 @@ func TestPSSuccessful(t *testing.T) {
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return vc.ContainerStatus{
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
ID: sandbox.ID(),
Annotations: map[string]string{

View File

@ -14,7 +14,8 @@ import (
"github.com/docker/go-units"
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@ -164,7 +165,7 @@ other options are ignored.
span.SetTag("sandbox", sandboxID)
// container MUST be running
if status.State.State != vc.StateRunning {
if status.State.State != types.StateRunning {
return fmt.Errorf("Container %s is not running", containerID)
}

View File

@ -15,6 +15,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
@ -94,8 +95,8 @@ func TestUpdateCLIFailure(t *testing.T) {
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
},
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}
@ -167,8 +168,8 @@ func TestUpdateCLISuccessful(t *testing.T) {
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
},
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}

View File

@ -11,7 +11,8 @@ import (
"github.com/containerd/containerd/mount"
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/sirupsen/logrus"
)
@ -21,7 +22,7 @@ func deleteContainer(ctx context.Context, s *service, c *container) error {
if err != nil {
return err
}
if status.State.State != vc.StateStopped {
if status.State.State != types.StateStopped {
_, err = s.sandbox.StopContainer(c.id)
if err != nil {
return err

View File

@ -14,13 +14,13 @@ import (
"github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/errdefs"
googleProtobuf "github.com/gogo/protobuf/types"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
type exec struct {
container *container
cmds *vc.Cmd
cmds *types.Cmd
tty *tty
ttyio *ttyIO
id string
@ -44,17 +44,17 @@ type tty struct {
terminal bool
}
func getEnvs(envs []string) []vc.EnvVar {
var vcEnvs = []vc.EnvVar{}
var env vc.EnvVar
func getEnvs(envs []string) []types.EnvVar {
var vcEnvs = []types.EnvVar{}
var env types.EnvVar
for _, v := range envs {
pair := strings.SplitN(v, "=", 2)
if len(pair) == 2 {
env = vc.EnvVar{Var: pair[0], Value: pair[1]}
env = types.EnvVar{Var: pair[0], Value: pair[1]}
} else if len(pair) == 1 {
env = vc.EnvVar{Var: pair[0], Value: ""}
env = types.EnvVar{Var: pair[0], Value: ""}
}
vcEnvs = append(vcEnvs, env)
@ -91,7 +91,7 @@ func newExec(c *container, stdin, stdout, stderr string, terminal bool, jspec *g
terminal: terminal,
}
cmds := &vc.Cmd{
cmds := &types.Cmd{
Args: spec.Args,
Envs: getEnvs(spec.Env),
User: fmt.Sprintf("%d", spec.User.UID),

View File

@ -15,6 +15,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
@ -38,8 +39,8 @@ func TestPauseContainerSuccess(t *testing.T) {
return vc.ContainerStatus{
ID: testContainerID,
Annotations: make(map[string]string),
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}
@ -86,8 +87,8 @@ func TestPauseContainerFail(t *testing.T) {
return vc.ContainerStatus{
ID: testContainerID,
Annotations: make(map[string]string),
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}
@ -129,8 +130,8 @@ func TestResumeContainerSuccess(t *testing.T) {
return vc.ContainerStatus{
ID: testContainerID,
Annotations: make(map[string]string),
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}
@ -177,8 +178,8 @@ func TestResumeContainerFail(t *testing.T) {
return vc.ContainerStatus{
ID: testContainerID,
Annotations: make(map[string]string),
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}

View File

@ -27,6 +27,7 @@ import (
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/containerd/containerd/api/types/task"
@ -782,13 +783,13 @@ func (s *service) getContainerStatus(containerID string) (task.Status, error) {
var status task.Status
switch cStatus.State.State {
case vc.StateReady:
case types.StateReady:
status = task.StatusCreated
case vc.StateRunning:
case types.StateRunning:
status = task.StatusRunning
case vc.StatePaused:
case types.StatePaused:
status = task.StatusPaused
case vc.StateStopped:
case types.StateStopped:
status = task.StatusStopped
}

View File

@ -12,6 +12,7 @@ import (
"github.com/kata-containers/agent/protocols/grpc"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/mitchellh/mapstructure"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
@ -160,7 +161,7 @@ type agent interface {
createSandbox(sandbox *Sandbox) error
// exec will tell the agent to run a command in an already running container.
exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error)
exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, error)
// startSandbox will tell the agent to start all containers related to the Sandbox.
startSandbox(sandbox *Sandbox) error

View File

@ -14,6 +14,7 @@ import (
deviceApi "github.com/kata-containers/runtime/virtcontainers/device/api"
deviceConfig "github.com/kata-containers/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
@ -489,7 +490,7 @@ func StopContainer(ctx context.Context, sandboxID, containerID string) (VCContai
// EnterContainer is the virtcontainers container command execution entry point.
// EnterContainer enters an already running container and runs a given command.
func EnterContainer(ctx context.Context, sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) {
func EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (VCSandbox, VCContainer, *Process, error) {
span, ctx := trace(ctx, "EnterContainer")
defer span.Finish()
@ -569,9 +570,9 @@ func statusContainer(sandbox *Sandbox, containerID string) (ContainerStatus, err
// We have to check for the process state to make sure
// we update the status in case the process is supposed
// to be running but has been killed or terminated.
if (container.state.State == StateReady ||
container.state.State == StateRunning ||
container.state.State == StatePaused) &&
if (container.state.State == types.StateReady ||
container.state.State == types.StateRunning ||
container.state.State == types.StatePaused) &&
container.process.Pid > 0 {
running, err := isShimRunning(container.process.Pid)

View File

@ -20,6 +20,7 @@ import (
"github.com/containernetworking/plugins/pkg/ns"
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
)
@ -38,15 +39,15 @@ var containerAnnotations = map[string]string{
"container.hello": "container.world",
}
func newBasicTestCmd() Cmd {
envs := []EnvVar{
func newBasicTestCmd() types.Cmd {
envs := []types.EnvVar{
{
Var: "PATH",
Value: "/bin:/usr/bin:/sbin:/usr/sbin",
},
}
cmd := Cmd{
cmd := types.Cmd{
Args: strings.Split("/bin/sh", " "),
Envs: envs,
WorkDir: "/",
@ -581,7 +582,7 @@ func TestPauseThenResumeSandboxNoopAgentSuccessful(t *testing.T) {
pImpl, ok := p.(*Sandbox)
assert.True(t, ok)
expectedState := StatePaused
expectedState := types.StatePaused
assert.Equal(t, pImpl.state.State, expectedState, "unexpected paused sandbox state")
@ -601,7 +602,7 @@ func TestPauseThenResumeSandboxNoopAgentSuccessful(t *testing.T) {
pImpl, ok = p.(*Sandbox)
assert.True(t, ok)
expectedState = StateRunning
expectedState = types.StateRunning
assert.Equal(t, pImpl.state.State, expectedState, "unexpected resumed sandbox state")
@ -868,8 +869,8 @@ func TestStatusSandboxSuccessfulStateReady(t *testing.T) {
expectedStatus := SandboxStatus{
ID: testSandboxID,
State: State{
State: StateReady,
State: types.State{
State: types.StateReady,
},
Hypervisor: MockHypervisor,
HypervisorConfig: hypervisorConfig,
@ -878,8 +879,8 @@ func TestStatusSandboxSuccessfulStateReady(t *testing.T) {
ContainersStatus: []ContainerStatus{
{
ID: containerID,
State: State{
State: StateReady,
State: types.State{
State: types.StateReady,
},
PID: 0,
RootFs: filepath.Join(testDir, testBundle),
@ -926,8 +927,8 @@ func TestStatusSandboxSuccessfulStateRunning(t *testing.T) {
expectedStatus := SandboxStatus{
ID: testSandboxID,
State: State{
State: StateRunning,
State: types.State{
State: types.StateRunning,
},
Hypervisor: MockHypervisor,
HypervisorConfig: hypervisorConfig,
@ -936,8 +937,8 @@ func TestStatusSandboxSuccessfulStateRunning(t *testing.T) {
ContainersStatus: []ContainerStatus{
{
ID: containerID,
State: State{
State: StateRunning,
State: types.State{
State: types.StateRunning,
},
PID: 0,
RootFs: filepath.Join(testDir, testBundle),
@ -1776,8 +1777,8 @@ func TestStatusContainerStateReady(t *testing.T) {
expectedStatus := ContainerStatus{
ID: contID,
State: State{
State: StateReady,
State: types.State{
State: types.StateReady,
},
PID: 0,
RootFs: filepath.Join(testDir, testBundle),
@ -1851,8 +1852,8 @@ func TestStatusContainerStateRunning(t *testing.T) {
expectedStatus := ContainerStatus{
ID: contID,
State: State{
State: StateRunning,
State: types.State{
State: types.StateRunning,
},
PID: 0,
RootFs: filepath.Join(testDir, testBundle),
@ -2044,14 +2045,14 @@ func createNewSandboxConfig(hType HypervisorType, aType AgentType, aConfig inter
func createNewContainerConfigs(numOfContainers int) []ContainerConfig {
var contConfigs []ContainerConfig
envs := []EnvVar{
envs := []types.EnvVar{
{
Var: "PATH",
Value: "/bin:/usr/bin:/sbin:/usr/sbin",
},
}
cmd := Cmd{
cmd := types.Cmd{
Args: strings.Split("/bin/ps -A", " "),
Envs: envs,
WorkDir: "/",

View File

@ -17,6 +17,7 @@ import (
"time"
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
specs "github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go"
@ -66,7 +67,7 @@ type Process struct {
// ContainerStatus describes a container status.
type ContainerStatus struct {
ID string
State State
State types.State
PID int
StartTime time.Time
RootFs string
@ -210,7 +211,7 @@ type ContainerConfig struct {
ReadonlyRootfs bool
// Cmd specifies the command to run on a container
Cmd Cmd
Cmd types.Cmd
// Annotations allow clients to store arbitrary values,
// for example to add additional status values required
@ -273,7 +274,7 @@ type Container struct {
configPath string
containerPath string
state State
state types.State
process Process
@ -399,7 +400,7 @@ func (c *Container) storeContainer() error {
// setContainerState sets both the in-memory and on-disk state of the
// container.
func (c *Container) setContainerState(state stateString) error {
func (c *Container) setContainerState(state types.StateString) error {
if state == "" {
return errNeedState
}
@ -614,7 +615,7 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err
runPath: filepath.Join(runStoragePath, sandbox.id, contConfig.ID),
configPath: filepath.Join(configStoragePath, sandbox.id, contConfig.ID),
containerPath: filepath.Join(sandbox.id, contConfig.ID),
state: State{},
state: types.State{},
process: Process{},
mounts: contConfig.Mounts,
ctx: sandbox.ctx,
@ -772,7 +773,7 @@ func (c *Container) create() (err error) {
return
}
if err = c.setContainerState(StateReady); err != nil {
if err = c.setContainerState(types.StateReady); err != nil {
return
}
@ -780,8 +781,8 @@ func (c *Container) create() (err error) {
}
func (c *Container) delete() error {
if c.state.State != StateReady &&
c.state.State != StateStopped {
if c.state.State != types.StateReady &&
c.state.State != types.StateStopped {
return fmt.Errorf("Container not ready or stopped, impossible to delete")
}
@ -803,7 +804,7 @@ func (c *Container) checkSandboxRunning(cmd string) error {
return fmt.Errorf("Cmd cannot be empty")
}
if c.sandbox.state.State != StateRunning {
if c.sandbox.state.State != types.StateRunning {
return fmt.Errorf("Sandbox not running, impossible to %s the container", cmd)
}
@ -828,12 +829,12 @@ func (c *Container) start() error {
return err
}
if c.state.State != StateReady &&
c.state.State != StateStopped {
if c.state.State != types.StateReady &&
c.state.State != types.StateStopped {
return fmt.Errorf("Container not ready or stopped, impossible to start")
}
if err := c.state.validTransition(c.state.State, StateRunning); err != nil {
if err := c.state.ValidTransition(c.state.State, types.StateRunning); err != nil {
return err
}
@ -846,7 +847,7 @@ func (c *Container) start() error {
return err
}
return c.setContainerState(StateRunning)
return c.setContainerState(types.StateRunning)
}
func (c *Container) stop() error {
@ -860,16 +861,16 @@ func (c *Container) stop() error {
//
// This has to be handled before the transition validation since this
// is an exception.
if c.state.State == StateStopped {
if c.state.State == types.StateStopped {
c.Logger().Info("Container already stopped")
return nil
}
if c.sandbox.state.State != StateReady && c.sandbox.state.State != StateRunning {
if c.sandbox.state.State != types.StateReady && c.sandbox.state.State != types.StateRunning {
return fmt.Errorf("Sandbox not ready or running, impossible to stop the container")
}
if err := c.state.validTransition(c.state.State, StateStopped); err != nil {
if err := c.state.ValidTransition(c.state.State, types.StateStopped); err != nil {
return err
}
@ -938,16 +939,16 @@ func (c *Container) stop() error {
return err
}
return c.setContainerState(StateStopped)
return c.setContainerState(types.StateStopped)
}
func (c *Container) enter(cmd Cmd) (*Process, error) {
func (c *Container) enter(cmd types.Cmd) (*Process, error) {
if err := c.checkSandboxRunning("enter"); err != nil {
return nil, err
}
if c.state.State != StateReady &&
c.state.State != StateRunning {
if c.state.State != types.StateReady &&
c.state.State != types.StateRunning {
return nil, fmt.Errorf("Container not ready or running, " +
"impossible to enter")
}
@ -961,8 +962,8 @@ func (c *Container) enter(cmd Cmd) (*Process, error) {
}
func (c *Container) wait(processID string) (int32, error) {
if c.state.State != StateReady &&
c.state.State != StateRunning {
if c.state.State != types.StateReady &&
c.state.State != types.StateRunning {
return 0, fmt.Errorf("Container not ready or running, " +
"impossible to wait")
}
@ -975,11 +976,11 @@ func (c *Container) kill(signal syscall.Signal, all bool) error {
}
func (c *Container) signalProcess(processID string, signal syscall.Signal, all bool) error {
if c.sandbox.state.State != StateReady && c.sandbox.state.State != StateRunning {
if c.sandbox.state.State != types.StateReady && c.sandbox.state.State != types.StateRunning {
return fmt.Errorf("Sandbox not ready or running, impossible to signal the container")
}
if c.state.State != StateReady && c.state.State != StateRunning && c.state.State != StatePaused {
if c.state.State != types.StateReady && c.state.State != types.StateRunning && c.state.State != types.StatePaused {
return fmt.Errorf("Container not ready, running or paused, impossible to signal the container")
}
@ -987,7 +988,7 @@ func (c *Container) signalProcess(processID string, signal syscall.Signal, all b
}
func (c *Container) winsizeProcess(processID string, height, width uint32) error {
if c.state.State != StateReady && c.state.State != StateRunning {
if c.state.State != types.StateReady && c.state.State != types.StateRunning {
return fmt.Errorf("Container not ready or running, impossible to signal the container")
}
@ -995,7 +996,7 @@ func (c *Container) winsizeProcess(processID string, height, width uint32) error
}
func (c *Container) ioStream(processID string) (io.WriteCloser, io.Reader, io.Reader, error) {
if c.state.State != StateReady && c.state.State != StateRunning {
if c.state.State != types.StateReady && c.state.State != types.StateRunning {
return nil, nil, nil, fmt.Errorf("Container not ready or running, impossible to signal the container")
}
@ -1009,7 +1010,7 @@ func (c *Container) processList(options ProcessListOptions) (ProcessList, error)
return nil, err
}
if c.state.State != StateRunning {
if c.state.State != types.StateRunning {
return nil, fmt.Errorf("Container not running, impossible to list processes")
}
@ -1028,7 +1029,7 @@ func (c *Container) update(resources specs.LinuxResources) error {
return err
}
if c.state.State != StateRunning {
if c.state.State != types.StateRunning {
return fmt.Errorf("Container not running, impossible to update")
}
@ -1065,7 +1066,7 @@ func (c *Container) pause() error {
return err
}
if c.state.State != StateRunning && c.state.State != StateReady {
if c.state.State != types.StateRunning && c.state.State != types.StateReady {
return fmt.Errorf("Container not running or ready, impossible to pause")
}
@ -1073,7 +1074,7 @@ func (c *Container) pause() error {
return err
}
return c.setContainerState(StatePaused)
return c.setContainerState(types.StatePaused)
}
func (c *Container) resume() error {
@ -1081,7 +1082,7 @@ func (c *Container) resume() error {
return err
}
if c.state.State != StatePaused {
if c.state.State != types.StatePaused {
return fmt.Errorf("Container not paused, impossible to resume")
}
@ -1089,7 +1090,7 @@ func (c *Container) resume() error {
return err
}
return c.setContainerState(StateRunning)
return c.setContainerState(types.StateRunning)
}
func (c *Container) hotplugDrive() error {

View File

@ -20,6 +20,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
"github.com/kata-containers/runtime/virtcontainers/device/manager"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
@ -289,8 +290,8 @@ func TestCheckSandboxRunningNotRunningFailure(t *testing.T) {
func TestCheckSandboxRunningSuccessful(t *testing.T) {
c := &Container{
sandbox: &Sandbox{
state: State{
State: StateRunning,
state: types.State{
State: types.StateRunning,
},
},
}
@ -302,24 +303,24 @@ func TestContainerEnterErrorsOnContainerStates(t *testing.T) {
assert := assert.New(t)
c := &Container{
sandbox: &Sandbox{
state: State{
State: StateRunning,
state: types.State{
State: types.StateRunning,
},
},
}
cmd := Cmd{}
cmd := types.Cmd{}
// Container state undefined
_, err := c.enter(cmd)
assert.Error(err)
// Container paused
c.state.State = StatePaused
c.state.State = types.StatePaused
_, err = c.enter(cmd)
assert.Error(err)
// Container stopped
c.state.State = StateStopped
c.state.State = types.StateStopped
_, err = c.enter(cmd)
assert.Error(err)
}
@ -328,8 +329,8 @@ func TestContainerWaitErrorState(t *testing.T) {
assert := assert.New(t)
c := &Container{
sandbox: &Sandbox{
state: State{
State: StateRunning,
state: types.State{
State: types.StateRunning,
},
},
}
@ -340,12 +341,12 @@ func TestContainerWaitErrorState(t *testing.T) {
assert.Error(err)
// Container paused
c.state.State = StatePaused
c.state.State = types.StatePaused
_, err = c.wait(processID)
assert.Error(err)
// Container stopped
c.state.State = StateStopped
c.state.State = types.StateStopped
_, err = c.wait(processID)
assert.Error(err)
}
@ -354,8 +355,8 @@ func TestKillContainerErrorState(t *testing.T) {
assert := assert.New(t)
c := &Container{
sandbox: &Sandbox{
state: State{
State: StateRunning,
state: types.State{
State: types.StateRunning,
},
},
}
@ -364,7 +365,7 @@ func TestKillContainerErrorState(t *testing.T) {
assert.Error(err)
// Container stopped
c.state.State = StateStopped
c.state.State = types.StateStopped
err = c.kill(syscall.SIGKILL, true)
assert.Error(err)
}
@ -373,8 +374,8 @@ func TestWinsizeProcessErrorState(t *testing.T) {
assert := assert.New(t)
c := &Container{
sandbox: &Sandbox{
state: State{
State: StateRunning,
state: types.State{
State: types.StateRunning,
},
},
}
@ -385,12 +386,12 @@ func TestWinsizeProcessErrorState(t *testing.T) {
assert.Error(err)
// Container paused
c.state.State = StatePaused
c.state.State = types.StatePaused
err = c.winsizeProcess(processID, 100, 200)
assert.Error(err)
// Container stopped
c.state.State = StateStopped
c.state.State = types.StateStopped
err = c.winsizeProcess(processID, 100, 200)
assert.Error(err)
}
@ -399,8 +400,8 @@ func TestProcessIOStream(t *testing.T) {
assert := assert.New(t)
c := &Container{
sandbox: &Sandbox{
state: State{
State: StateRunning,
state: types.State{
State: types.StateRunning,
},
},
}
@ -411,12 +412,12 @@ func TestProcessIOStream(t *testing.T) {
assert.Error(err)
// Container paused
c.state.State = StatePaused
c.state.State = types.StatePaused
_, _, _, err = c.ioStream(processID)
assert.Error(err)
// Container stopped
c.state.State = StateStopped
c.state.State = types.StateStopped
_, _, _, err = c.ioStream(processID)
assert.Error(err)
}

View File

@ -11,6 +11,7 @@ import (
"strings"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"
)
const containerRootfs = "/var/lib/container/bundle/"
@ -18,14 +19,14 @@ const containerRootfs = "/var/lib/container/bundle/"
// This example creates and starts a single container sandbox,
// using qemu as the hypervisor and hyperstart as the VM agent.
func Example_createAndStartSandbox() {
envs := []vc.EnvVar{
envs := []types.EnvVar{
{
Var: "PATH",
Value: "/bin:/usr/bin:/sbin:/usr/sbin",
},
}
cmd := vc.Cmd{
cmd := types.Cmd{
Args: strings.Split("/bin/sh", " "),
Envs: envs,
WorkDir: "/",

View File

@ -19,6 +19,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
"github.com/kata-containers/runtime/virtcontainers/types"
)
// sandboxResource is an int representing a sandbox resource type.
@ -630,7 +631,7 @@ func (fs *filesystem) storeResource(sandboxSpecific bool, sandboxID, containerID
case SandboxConfig, ContainerConfig:
return fs.storeSandboxAndContainerConfigResource(sandboxSpecific, sandboxID, containerID, resource, file)
case State:
case types.State:
return fs.storeStateResource(sandboxSpecific, sandboxID, containerID, resource, file)
case NetworkNamespace:
@ -690,11 +691,11 @@ func (fs *filesystem) fetchSandboxConfig(sandboxID string) (SandboxConfig, error
return sandboxConfig, nil
}
func (fs *filesystem) fetchSandboxState(sandboxID string) (State, error) {
var state State
func (fs *filesystem) fetchSandboxState(sandboxID string) (types.State, error) {
var state types.State
if err := fs.fetchResource(true, sandboxID, "", stateFileType, &state); err != nil {
return State{}, err
return types.State{}, err
}
return state, nil
@ -797,11 +798,11 @@ func (fs *filesystem) fetchContainerConfig(sandboxID, containerID string) (Conta
return config, nil
}
func (fs *filesystem) fetchContainerState(sandboxID, containerID string) (State, error) {
var state State
func (fs *filesystem) fetchContainerState(sandboxID, containerID string) (types.State, error) {
var state types.State
if err := fs.fetchResource(false, sandboxID, containerID, stateFileType, &state); err != nil {
return State{}, err
return types.State{}, err
}
return state, nil

View File

@ -15,6 +15,7 @@ import (
"testing"
"github.com/kata-containers/runtime/virtcontainers/device/manager"
"github.com/kata-containers/runtime/virtcontainers/types"
)
func TestFilesystemCreateAllResourcesSuccessful(t *testing.T) {
@ -520,7 +521,7 @@ func TestFilesystemStoreResourceFailingContainerConfigResourceURI(t *testing.T)
func TestFilesystemStoreResourceFailingStateConfigFileType(t *testing.T) {
fs := &filesystem{}
data := State{}
data := types.State{}
for _, b := range []bool{true, false} {
err := fs.storeResource(b, testSandboxID, "100", configFileType, data)
@ -532,7 +533,7 @@ func TestFilesystemStoreResourceFailingStateConfigFileType(t *testing.T) {
func TestFilesystemStoreResourceFailingStateResourceURI(t *testing.T) {
fs := &filesystem{}
data := State{}
data := types.State{}
for _, b := range []bool{true, false} {
err := fs.storeResource(b, "", "100", stateFileType, data)

View File

@ -14,6 +14,7 @@ import (
"text/tabwriter"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@ -582,14 +583,14 @@ func createContainer(context *cli.Context) error {
interactive = true
}
envs := []vc.EnvVar{
envs := []types.EnvVar{
{
Var: "PATH",
Value: "/bin:/usr/bin:/sbin:/usr/sbin",
},
}
cmd := vc.Cmd{
cmd := types.Cmd{
Args: strings.Split(context.String("cmd"), " "),
Envs: envs,
WorkDir: "/",
@ -660,14 +661,14 @@ func enterContainer(context *cli.Context) error {
interactive = true
}
envs := []vc.EnvVar{
envs := []types.EnvVar{
{
Var: "PATH",
Value: "/bin:/usr/bin:/sbin:/usr/sbin",
},
}
cmd := vc.Cmd{
cmd := types.Cmd{
Args: strings.Split(context.String("cmd"), " "),
Envs: envs,
WorkDir: "/",

View File

@ -23,6 +23,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/pkg/hyperstart"
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
@ -58,7 +59,7 @@ func (h *hyper) generateSockets(sandbox *Sandbox, c HyperConfig) {
}
for i := 0; i < len(sandboxSocketPaths); i++ {
s := Socket{
s := types.Socket{
DeviceID: fmt.Sprintf(defaultDeviceIDTemplate, i),
ID: fmt.Sprintf(defaultIDTemplate, i),
HostPath: sandboxSocketPaths[i],
@ -83,7 +84,7 @@ type hyper struct {
client *proxyClient.Client
state HyperAgentState
sockets []Socket
sockets []types.Socket
ctx context.Context
}
@ -99,7 +100,7 @@ func (h *hyper) Logger() *logrus.Entry {
return virtLog.WithField("subsystem", "hyper")
}
func (h *hyper) buildHyperContainerProcess(cmd Cmd) (*hyperstart.Process, error) {
func (h *hyper) buildHyperContainerProcess(cmd types.Cmd) (*hyperstart.Process, error) {
var envVars []hyperstart.EnvironmentVar
for _, e := range cmd.Envs {
@ -313,7 +314,7 @@ func (h *hyper) configure(hv hypervisor, id, sharePath string, builtin bool, con
// Adding the hyper shared volume.
// This volume contains all bind mounted container bundles.
sharedVolume := Volume{
sharedVolume := types.Volume{
MountTag: mountTag,
HostPath: sharePath,
}
@ -339,7 +340,7 @@ func (h *hyper) capabilities() capabilities {
}
// exec is the agent command execution implementation for hyperstart.
func (h *hyper) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) {
func (h *hyper) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, error) {
token, err := h.attach()
if err != nil {
return nil, err
@ -610,7 +611,7 @@ func (h *hyper) startContainer(sandbox *Sandbox, c *Container) error {
// stopContainer is the agent Container stopping implementation for hyperstart.
func (h *hyper) stopContainer(sandbox *Sandbox, c Container) error {
// Nothing to be done in case the container has not been started.
if c.state.State == StateReady {
if c.state.State == types.StateReady {
return nil
}
@ -648,7 +649,7 @@ func (h *hyper) stopOneContainer(sandboxID string, c Container) error {
func (h *hyper) signalProcess(c *Container, processID string, signal syscall.Signal, all bool) error {
// Send the signal to the shim directly in case the container has not
// been started yet.
if c.state.State == StateReady {
if c.state.State == types.StateReady {
return signalShim(c.process.Pid, signal)
}

View File

@ -13,6 +13,7 @@ import (
"testing"
"github.com/kata-containers/runtime/virtcontainers/pkg/hyperstart"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
)
@ -36,7 +37,7 @@ func TestHyperstartGenerateSocketsSuccessful(t *testing.T) {
h.generateSockets(sandbox, config)
expectedSockets := []Socket{
expectedSockets := []types.Socket{
{
DeviceID: fmt.Sprintf(defaultDeviceIDTemplate, 0),
ID: fmt.Sprintf(defaultIDTemplate, 0),
@ -67,7 +68,7 @@ func TestHyperstartGenerateSocketsSuccessfulNoPathProvided(t *testing.T) {
h.generateSockets(sandbox, config)
expectedSockets := []Socket{
expectedSockets := []types.Socket{
{
DeviceID: fmt.Sprintf(defaultDeviceIDTemplate, 0),
ID: fmt.Sprintf(defaultIDTemplate, 0),

View File

@ -16,6 +16,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
@ -107,7 +108,7 @@ func (impl *VCImpl) StopContainer(ctx context.Context, sandboxID, containerID st
}
// EnterContainer implements the VC function of the same name.
func (impl *VCImpl) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) {
func (impl *VCImpl) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (VCSandbox, VCContainer, *Process, error) {
return EnterContainer(ctx, sandboxID, containerID, cmd)
}

View File

@ -13,6 +13,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
@ -35,7 +36,7 @@ type VC interface {
CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error)
DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error)
EnterContainer(ctx context.Context, sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error)
EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (VCSandbox, VCContainer, *Process, error)
KillContainer(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error
StartContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error)
StatusContainer(ctx context.Context, sandboxID, containerID string) (ContainerStatus, error)
@ -83,7 +84,7 @@ type VCSandbox interface {
StatsContainer(containerID string) (ContainerStats, error)
PauseContainer(containerID string) error
ResumeContainer(containerID string) error
EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error)
EnterContainer(containerID string, cmd types.Cmd) (VCContainer, *Process, error)
UpdateContainer(containerID string, resources specs.LinuxResources) error
ProcessListContainer(containerID string, options ProcessListOptions) (ProcessList, error)
WaitProcess(containerID, processID string) (int32, error)

View File

@ -27,6 +27,7 @@ import (
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
opentracing "github.com/opentracing/opentracing-go"
@ -151,7 +152,7 @@ func (k *kataAgent) generateVMSocket(id string, c KataAgentConfig) error {
return err
}
k.vmSocket = Socket{
k.vmSocket = types.Socket{
DeviceID: defaultKataDeviceID,
ID: defaultKataID,
HostPath: kataSock,
@ -201,7 +202,7 @@ func (k *kataAgent) init(ctx context.Context, sandbox *Sandbox, config interface
func (k *kataAgent) agentURL() (string, error) {
switch s := k.vmSocket.(type) {
case Socket:
case types.Socket:
return s.HostPath, nil
case kataVSOCK:
return s.String(), nil
@ -233,7 +234,7 @@ func (k *kataAgent) configure(h hypervisor, id, sharePath string, builtin bool,
}
switch s := k.vmSocket.(type) {
case Socket:
case types.Socket:
err := h.addDevice(s, serialPortDev)
if err != nil {
return err
@ -266,7 +267,7 @@ func (k *kataAgent) configure(h hypervisor, id, sharePath string, builtin bool,
// Create shared directory and add the shared volume if filesystem sharing is supported.
// This volume contains all bind mounted container bundles.
sharedVolume := Volume{
sharedVolume := types.Volume{
MountTag: mountGuest9pTag,
HostPath: sharePath,
}
@ -285,7 +286,7 @@ func (k *kataAgent) createSandbox(sandbox *Sandbox) error {
return k.configure(sandbox.hypervisor, sandbox.id, k.getSharePath(sandbox.id), k.proxyBuiltIn, nil)
}
func cmdToKataProcess(cmd Cmd) (process *grpc.Process, err error) {
func cmdToKataProcess(cmd types.Cmd) (process *grpc.Process, err error) {
var i uint64
var extraGids []uint32
@ -351,7 +352,7 @@ func cmdToKataProcess(cmd Cmd) (process *grpc.Process, err error) {
return process, nil
}
func cmdEnvsToStringSlice(ev []EnvVar) []string {
func cmdEnvsToStringSlice(ev []types.EnvVar) []string {
var env []string
for _, e := range ev {
@ -362,7 +363,7 @@ func cmdEnvsToStringSlice(ev []EnvVar) []string {
return env
}
func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) {
func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, error) {
span, _ := k.trace("exec")
defer span.Finish()

View File

@ -32,6 +32,7 @@ import (
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
)
var (
@ -637,7 +638,7 @@ func TestAgentPathAPI(t *testing.T) {
err = k1.generateVMSocket(id, c)
assert.Nil(err)
_, ok := k1.vmSocket.(Socket)
_, ok := k1.vmSocket.(types.Socket)
assert.True(ok)
c.UseVSock = true
@ -676,9 +677,9 @@ func TestAgentConfigure(t *testing.T) {
func TestCmdToKataProcess(t *testing.T) {
assert := assert.New(t)
cmd := Cmd{
cmd := types.Cmd{
Args: strings.Split("foo", " "),
Envs: []EnvVar{},
Envs: []types.EnvVar{},
WorkDir: "/",
User: "1000",
PrimaryGroup: "1000",
@ -738,7 +739,7 @@ func TestAgentCreateContainer(t *testing.T) {
id: "barfoo",
sandboxID: "foobar",
sandbox: sandbox,
state: State{
state: types.State{
Fstype: "xfs",
},
config: &ContainerConfig{

View File

@ -11,6 +11,7 @@ import (
"github.com/kata-containers/agent/protocols/grpc"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
)
@ -46,7 +47,7 @@ func (n *noopAgent) disconnect() error {
}
// exec is the Noop agent command execution implementation. It does nothing.
func (n *noopAgent) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) {
func (n *noopAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, error) {
return nil, nil
}

View File

@ -10,6 +10,7 @@ import (
"context"
"testing"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
@ -45,7 +46,7 @@ func TestNoopAgentInit(t *testing.T) {
func TestNoopAgentExec(t *testing.T) {
n := &noopAgent{}
cmd := Cmd{}
cmd := types.Cmd{}
sandbox, container, err := testCreateNoopContainer()
if err != nil {
t.Fatal(err)

View File

@ -7,6 +7,7 @@ package virtcontainers
import (
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/types"
)
type noopResourceStorage struct{}
@ -35,8 +36,8 @@ func (n *noopResourceStorage) fetchSandboxConfig(sandboxID string) (SandboxConfi
return SandboxConfig{}, nil
}
func (n *noopResourceStorage) fetchSandboxState(sandboxID string) (State, error) {
return State{}, nil
func (n *noopResourceStorage) fetchSandboxState(sandboxID string) (types.State, error) {
return types.State{}, nil
}
func (n *noopResourceStorage) fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error) {
@ -83,8 +84,8 @@ func (n *noopResourceStorage) fetchContainerConfig(sandboxID, containerID string
return ContainerConfig{}, nil
}
func (n *noopResourceStorage) fetchContainerState(sandboxID, containerID string) (State, error) {
return State{}, nil
func (n *noopResourceStorage) fetchContainerState(sandboxID, containerID string) (types.State, error) {
return types.State{}, nil
}
func (n *noopResourceStorage) fetchContainerProcess(sandboxID, containerID string) (Process, error) {

View File

@ -25,6 +25,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
dockershimAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations/dockershim"
"github.com/kata-containers/runtime/virtcontainers/types"
)
type annotationContainerType struct {
@ -146,7 +147,7 @@ func SetLogger(ctx context.Context, logger *logrus.Entry) {
ociLog = logger.WithFields(fields)
}
func cmdEnvs(spec CompatOCISpec, envs []vc.EnvVar) []vc.EnvVar {
func cmdEnvs(spec CompatOCISpec, envs []types.EnvVar) []types.EnvVar {
for _, env := range spec.Process.Env {
kv := strings.Split(env, "=")
if len(kv) < 2 {
@ -154,7 +155,7 @@ func cmdEnvs(spec CompatOCISpec, envs []vc.EnvVar) []vc.EnvVar {
}
envs = append(envs,
vc.EnvVar{
types.EnvVar{
Var: kv[0],
Value: kv[1],
})
@ -248,9 +249,9 @@ func containerDeviceInfos(spec CompatOCISpec) ([]config.DeviceInfo, error) {
return devices, nil
}
func containerCapabilities(s CompatOCISpec) (vc.LinuxCapabilities, error) {
func containerCapabilities(s CompatOCISpec) (types.LinuxCapabilities, error) {
capabilities := s.Process.Capabilities
var c vc.LinuxCapabilities
var c types.LinuxCapabilities
// In spec v1.0.0-rc4, capabilities was a list of strings. This was changed
// to an object with v1.0.0-rc5.
@ -289,7 +290,7 @@ func containerCapabilities(s CompatOCISpec) (vc.LinuxCapabilities, error) {
list = append(list, str.(string))
}
c = vc.LinuxCapabilities{
c = types.LinuxCapabilities{
Bounding: list,
Effective: list,
Inheritable: list,
@ -307,9 +308,9 @@ func containerCapabilities(s CompatOCISpec) (vc.LinuxCapabilities, error) {
}
// ContainerCapabilities return a LinuxCapabilities for virtcontainer
func ContainerCapabilities(s CompatOCISpec) (vc.LinuxCapabilities, error) {
func ContainerCapabilities(s CompatOCISpec) (types.LinuxCapabilities, error) {
if s.Process == nil {
return vc.LinuxCapabilities{}, fmt.Errorf("ContainerCapabilities, Process is nil")
return types.LinuxCapabilities{}, fmt.Errorf("ContainerCapabilities, Process is nil")
}
return containerCapabilities(s)
}
@ -516,9 +517,9 @@ func ContainerConfig(ocispec CompatOCISpec, bundlePath, cid, console string, det
}
ociLog.Debugf("container rootfs: %s", rootfs)
cmd := vc.Cmd{
cmd := types.Cmd{
Args: ocispec.Process.Args,
Envs: cmdEnvs(ocispec, []vc.EnvVar{}),
Envs: cmdEnvs(ocispec, []types.EnvVar{}),
WorkDir: ocispec.Process.Cwd,
User: strconv.FormatUint(uint64(ocispec.Process.User.UID), 10),
PrimaryGroup: strconv.FormatUint(uint64(ocispec.Process.User.GID), 10),
@ -539,7 +540,7 @@ func ContainerConfig(ocispec CompatOCISpec, bundlePath, cid, console string, det
}
if ocispec.Process != nil {
caps, ok := ocispec.Process.Capabilities.(vc.LinuxCapabilities)
caps, ok := ocispec.Process.Capabilities.(types.LinuxCapabilities)
if !ok {
return vc.ContainerConfig{}, fmt.Errorf("Unexpected format for capabilities: %v", ocispec.Process.Capabilities)
}
@ -609,15 +610,15 @@ func StatusToOCIState(status vc.ContainerStatus) spec.State {
}
// StateToOCIState translates a virtcontainers container state into an OCI one.
func StateToOCIState(state vc.State) string {
func StateToOCIState(state types.State) string {
switch state.State {
case vc.StateReady:
case types.StateReady:
return StateCreated
case vc.StateRunning:
case types.StateRunning:
return StateRunning
case vc.StateStopped:
case types.StateStopped:
return StateStopped
case vc.StatePaused:
case types.StatePaused:
return StatePaused
default:
return ""
@ -626,8 +627,8 @@ func StateToOCIState(state vc.State) string {
// EnvVars converts an OCI process environment variables slice
// into a virtcontainers EnvVar slice.
func EnvVars(envs []string) ([]vc.EnvVar, error) {
var envVars []vc.EnvVar
func EnvVars(envs []string) ([]types.EnvVar, error) {
var envVars []types.EnvVar
envDelimiter := "="
expectedEnvLen := 2
@ -636,17 +637,17 @@ func EnvVars(envs []string) ([]vc.EnvVar, error) {
envSlice := strings.SplitN(env, envDelimiter, expectedEnvLen)
if len(envSlice) < expectedEnvLen {
return []vc.EnvVar{}, fmt.Errorf("Wrong string format: %s, expecting only %v parameters separated with %q",
return []types.EnvVar{}, fmt.Errorf("Wrong string format: %s, expecting only %v parameters separated with %q",
env, expectedEnvLen, envDelimiter)
}
if envSlice[0] == "" {
return []vc.EnvVar{}, fmt.Errorf("Environment variable cannot be empty")
return []types.EnvVar{}, fmt.Errorf("Environment variable cannot be empty")
}
envSlice[1] = strings.Trim(envSlice[1], "' ")
envVar := vc.EnvVar{
envVar := types.EnvVar{
Var: envSlice[0],
Value: envSlice[1],
}

View File

@ -24,6 +24,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/types"
)
const (
@ -114,9 +115,9 @@ func TestMinimalSandboxConfig(t *testing.T) {
capList := []string{"CAP_AUDIT_WRITE", "CAP_KILL", "CAP_NET_BIND_SERVICE"}
expectedCmd := vc.Cmd{
expectedCmd := types.Cmd{
Args: []string{"sh"},
Envs: []vc.EnvVar{
Envs: []types.EnvVar{
{
Var: "PATH",
Value: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
@ -133,7 +134,7 @@ func TestMinimalSandboxConfig(t *testing.T) {
Interactive: true,
Console: consolePath,
NoNewPrivileges: true,
Capabilities: vc.LinuxCapabilities{
Capabilities: types.LinuxCapabilities{
Bounding: capList,
Effective: capList,
Inheritable: capList,
@ -271,8 +272,8 @@ func TestStatusToOCIStateSuccessfulWithReadyState(t *testing.T) {
testPID := 12345
testRootFs := "testRootFs"
state := vc.State{
State: vc.StateReady,
state := types.State{
State: types.StateReady,
}
containerAnnotations := map[string]string{
@ -307,8 +308,8 @@ func TestStatusToOCIStateSuccessfulWithRunningState(t *testing.T) {
testPID := 12345
testRootFs := "testRootFs"
state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}
containerAnnotations := map[string]string{
@ -342,8 +343,8 @@ func TestStatusToOCIStateSuccessfulWithStoppedState(t *testing.T) {
testPID := 12345
testRootFs := "testRootFs"
state := vc.State{
State: vc.StateStopped,
state := types.State{
State: types.StateStopped,
}
containerAnnotations := map[string]string{
@ -403,28 +404,28 @@ func TestStatusToOCIStateSuccessfulWithNoState(t *testing.T) {
}
func TestStateToOCIState(t *testing.T) {
var state vc.State
var state types.State
if ociState := StateToOCIState(state); ociState != "" {
t.Fatalf("Expecting \"created\" state, got \"%s\"", ociState)
}
state.State = vc.StateReady
state.State = types.StateReady
if ociState := StateToOCIState(state); ociState != "created" {
t.Fatalf("Expecting \"created\" state, got \"%s\"", ociState)
}
state.State = vc.StateRunning
state.State = types.StateRunning
if ociState := StateToOCIState(state); ociState != "running" {
t.Fatalf("Expecting \"created\" state, got \"%s\"", ociState)
}
state.State = vc.StateStopped
state.State = types.StateStopped
if ociState := StateToOCIState(state); ociState != "stopped" {
t.Fatalf("Expecting \"created\" state, got \"%s\"", ociState)
}
state.State = vc.StatePaused
state.State = types.StatePaused
if ociState := StateToOCIState(state); ociState != "paused" {
t.Fatalf("Expecting \"paused\" state, got \"%s\"", ociState)
}
@ -432,7 +433,7 @@ func TestStateToOCIState(t *testing.T) {
func TestEnvVars(t *testing.T) {
envVars := []string{"foo=bar", "TERM=xterm", "HOME=/home/foo", "TERM=\"bar\"", "foo=\"\""}
expectecVcEnvVars := []vc.EnvVar{
expectecVcEnvVars := []types.EnvVar{
{
Var: "foo",
Value: "bar",

View File

@ -24,6 +24,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
@ -173,7 +174,7 @@ func (m *VCMock) StopContainer(ctx context.Context, sandboxID, containerID strin
}
// EnterContainer implements the VC function of the same name.
func (m *VCMock) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
func (m *VCMock) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
if m.EnterContainerFunc != nil {
return m.EnterContainerFunc(ctx, sandboxID, containerID, cmd)
}

View File

@ -14,6 +14,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/factory"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
@ -421,12 +422,12 @@ func TestVCMockEnterContainer(t *testing.T) {
assert.Nil(m.EnterContainerFunc)
ctx := context.Background()
cmd := vc.Cmd{}
cmd := types.Cmd{}
_, _, _, err := m.EnterContainer(ctx, testSandboxID, testContainerID, cmd)
assert.Error(err)
assert.True(IsMockError(err))
m.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
m.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
return &Sandbox{}, &Container{}, &vc.Process{}, nil
}

View File

@ -13,6 +13,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@ -143,7 +144,7 @@ func (s *Sandbox) Status() vc.SandboxStatus {
}
// EnterContainer implements the VCSandbox function of the same name.
func (s *Sandbox) EnterContainer(containerID string, cmd vc.Cmd) (vc.VCContainer, *vc.Process, error) {
func (s *Sandbox) EnterContainer(containerID string, cmd types.Cmd) (vc.VCContainer, *vc.Process, error) {
return &Container{}, &vc.Process{}, nil
}

View File

@ -13,6 +13,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
@ -57,7 +58,7 @@ type VCMock struct {
CreateContainerFunc func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error)
DeleteContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
EnterContainerFunc func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error)
EnterContainerFunc func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error)
KillContainerFunc func(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error
StartContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
StatusContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error)

View File

@ -22,6 +22,7 @@ import (
"unsafe"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
"golang.org/x/sys/unix"
)
@ -1207,9 +1208,9 @@ func (q *qemu) addDevice(devInfo interface{}, devType deviceType) error {
defer span.Finish()
switch v := devInfo.(type) {
case Volume:
case types.Volume:
q.qemuConfig.Devices = q.arch.append9PVolume(q.qemuConfig.Devices, v)
case Socket:
case types.Socket:
q.qemuConfig.Devices = q.arch.appendSocket(q.qemuConfig.Devices, v)
case kataVSOCK:
q.fds = append(q.fds, v.vhostFd)

View File

@ -14,6 +14,7 @@ import (
govmmQemu "github.com/intel/govmm/qemu"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
)
@ -71,10 +72,10 @@ type qemuArch interface {
appendBridges(devices []govmmQemu.Device, bridges []Bridge) []govmmQemu.Device
// append9PVolume appends a 9P volume to devices
append9PVolume(devices []govmmQemu.Device, volume Volume) []govmmQemu.Device
append9PVolume(devices []govmmQemu.Device, volume types.Volume) []govmmQemu.Device
// appendSocket appends a socket to devices
appendSocket(devices []govmmQemu.Device, socket Socket) []govmmQemu.Device
appendSocket(devices []govmmQemu.Device, socket types.Socket) []govmmQemu.Device
// appendVSockPCI appends a vsock PCI to devices
appendVSockPCI(devices []govmmQemu.Device, vsock kataVSOCK) []govmmQemu.Device
@ -370,7 +371,7 @@ func (q *qemuArchBase) appendBridges(devices []govmmQemu.Device, bridges []Bridg
return devices
}
func (q *qemuArchBase) append9PVolume(devices []govmmQemu.Device, volume Volume) []govmmQemu.Device {
func (q *qemuArchBase) append9PVolume(devices []govmmQemu.Device, volume types.Volume) []govmmQemu.Device {
if volume.MountTag == "" || volume.HostPath == "" {
return devices
}
@ -395,7 +396,7 @@ func (q *qemuArchBase) append9PVolume(devices []govmmQemu.Device, volume Volume)
return devices
}
func (q *qemuArchBase) appendSocket(devices []govmmQemu.Device, socket Socket) []govmmQemu.Device {
func (q *qemuArchBase) appendSocket(devices []govmmQemu.Device, socket types.Socket) []govmmQemu.Device {
devID := socket.ID
if len(devID) > maxDevIDSize {
devID = devID[:maxDevIDSize]

View File

@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/types"
)
const (
@ -204,9 +205,9 @@ func testQemuArchBaseAppend(t *testing.T, structure interface{}, expected []govm
qemuArchBase := newQemuArchBase()
switch s := structure.(type) {
case Volume:
case types.Volume:
devices = qemuArchBase.append9PVolume(devices, s)
case Socket:
case types.Socket:
devices = qemuArchBase.appendSocket(devices, s)
case config.BlockDrive:
devices = qemuArchBase.appendBlockDevice(devices, s)
@ -316,7 +317,7 @@ func TestQemuArchBaseAppend9PVolume(t *testing.T) {
},
}
volume := Volume{
volume := types.Volume{
MountTag: mountTag,
HostPath: hostPath,
}
@ -341,7 +342,7 @@ func TestQemuArchBaseAppendSocket(t *testing.T) {
},
}
socket := Socket{
socket := types.Socket{
DeviceID: deviceID,
ID: id,
HostPath: hostPath,

View File

@ -15,6 +15,7 @@ import (
"testing"
govmmQemu "github.com/intel/govmm/qemu"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
@ -213,7 +214,7 @@ func TestQemuAddDeviceFsDev(t *testing.T) {
},
}
volume := Volume{
volume := types.Volume{
MountTag: mountTag,
HostPath: hostPath,
}
@ -238,7 +239,7 @@ func TestQemuAddDeviceSerialPortDev(t *testing.T) {
},
}
socket := Socket{
socket := types.Socket{
DeviceID: deviceID,
ID: id,
HostPath: hostPath,

View File

@ -10,6 +10,7 @@ import (
"encoding/json"
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/types"
)
// TypedDevice is used as an intermediate representation for marshalling
@ -39,7 +40,7 @@ type resourceStorage interface {
storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error
deleteSandboxResources(sandboxID string, resources []sandboxResource) error
fetchSandboxConfig(sandboxID string) (SandboxConfig, error)
fetchSandboxState(sandboxID string) (State, error)
fetchSandboxState(sandboxID string) (types.State, error)
fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error)
storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error
fetchSandboxDevices(sandboxID string) ([]api.Device, error)
@ -57,7 +58,7 @@ type resourceStorage interface {
storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error
deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error
fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error)
fetchContainerState(sandboxID, containerID string) (State, error)
fetchContainerState(sandboxID, containerID string) (types.State, error)
fetchContainerProcess(sandboxID, containerID string) (Process, error)
storeContainerProcess(sandboxID, containerID string, process Process) error
fetchContainerMounts(sandboxID, containerID string) ([]Mount, error)

View File

@ -12,7 +12,6 @@ import (
"net"
"os"
"path/filepath"
"strings"
"sync"
"syscall"
@ -27,6 +26,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
deviceManager "github.com/kata-containers/runtime/virtcontainers/device/manager"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
"github.com/vishvananda/netlink"
)
@ -37,274 +37,10 @@ const (
vmStartTimeout = 10
)
// stateString is a string representing a sandbox state.
type stateString string
const (
// StateReady represents a sandbox/container that's ready to be run
StateReady stateString = "ready"
// StateRunning represents a sandbox/container that's currently running.
StateRunning stateString = "running"
// StatePaused represents a sandbox/container that has been paused.
StatePaused stateString = "paused"
// StateStopped represents a sandbox/container that has been stopped.
StateStopped stateString = "stopped"
)
// State is a sandbox state structure.
type State struct {
State stateString `json:"state"`
BlockDeviceID string
// Index of the block device passed to hypervisor.
BlockIndex int `json:"blockIndex"`
// File system of the rootfs incase it is block device
Fstype string `json:"fstype"`
// Pid is the process id of the sandbox container which is the first
// container to be started.
Pid int `json:"pid"`
// GuestMemoryBlockSizeMB is the size of memory block of guestos
GuestMemoryBlockSizeMB uint32 `json:"guestMemoryBlockSize"`
}
// valid checks that the sandbox state is valid.
func (state *State) valid() bool {
for _, validState := range []stateString{StateReady, StateRunning, StatePaused, StateStopped} {
if state.State == validState {
return true
}
}
return false
}
// validTransition returns an error if we want to move to
// an unreachable state.
func (state *State) validTransition(oldState stateString, newState stateString) error {
if state.State != oldState {
return fmt.Errorf("Invalid state %s (Expecting %s)", state.State, oldState)
}
switch state.State {
case StateReady:
if newState == StateRunning || newState == StateStopped {
return nil
}
case StateRunning:
if newState == StatePaused || newState == StateStopped {
return nil
}
case StatePaused:
if newState == StateRunning || newState == StateStopped {
return nil
}
case StateStopped:
if newState == StateRunning {
return nil
}
}
return fmt.Errorf("Can not move from %s to %s",
state.State, newState)
}
// Volume is a shared volume between the host and the VM,
// defined by its mount tag and its host path.
type Volume struct {
// MountTag is a label used as a hint to the guest.
MountTag string
// HostPath is the host filesystem path for this volume.
HostPath string
}
// Volumes is a Volume list.
type Volumes []Volume
// Set assigns volume values from string to a Volume.
func (v *Volumes) Set(volStr string) error {
if volStr == "" {
return fmt.Errorf("volStr cannot be empty")
}
volSlice := strings.Split(volStr, " ")
const expectedVolLen = 2
const volDelimiter = ":"
for _, vol := range volSlice {
volArgs := strings.Split(vol, volDelimiter)
if len(volArgs) != expectedVolLen {
return fmt.Errorf("Wrong string format: %s, expecting only %v parameters separated with %q",
vol, expectedVolLen, volDelimiter)
}
if volArgs[0] == "" || volArgs[1] == "" {
return fmt.Errorf("Volume parameters cannot be empty")
}
volume := Volume{
MountTag: volArgs[0],
HostPath: volArgs[1],
}
*v = append(*v, volume)
}
return nil
}
// String converts a Volume to a string.
func (v *Volumes) String() string {
var volSlice []string
for _, volume := range *v {
volSlice = append(volSlice, fmt.Sprintf("%s:%s", volume.MountTag, volume.HostPath))
}
return strings.Join(volSlice, " ")
}
// Socket defines a socket to communicate between
// the host and any process inside the VM.
type Socket struct {
DeviceID string
ID string
HostPath string
Name string
}
// Sockets is a Socket list.
type Sockets []Socket
// Set assigns socket values from string to a Socket.
func (s *Sockets) Set(sockStr string) error {
if sockStr == "" {
return fmt.Errorf("sockStr cannot be empty")
}
sockSlice := strings.Split(sockStr, " ")
const expectedSockCount = 4
const sockDelimiter = ":"
for _, sock := range sockSlice {
sockArgs := strings.Split(sock, sockDelimiter)
if len(sockArgs) != expectedSockCount {
return fmt.Errorf("Wrong string format: %s, expecting only %v parameters separated with %q", sock, expectedSockCount, sockDelimiter)
}
for _, a := range sockArgs {
if a == "" {
return fmt.Errorf("Socket parameters cannot be empty")
}
}
socket := Socket{
DeviceID: sockArgs[0],
ID: sockArgs[1],
HostPath: sockArgs[2],
Name: sockArgs[3],
}
*s = append(*s, socket)
}
return nil
}
// String converts a Socket to a string.
func (s *Sockets) String() string {
var sockSlice []string
for _, sock := range *s {
sockSlice = append(sockSlice, fmt.Sprintf("%s:%s:%s:%s", sock.DeviceID, sock.ID, sock.HostPath, sock.Name))
}
return strings.Join(sockSlice, " ")
}
// EnvVar is a key/value structure representing a command
// environment variable.
type EnvVar struct {
Var string
Value string
}
// LinuxCapabilities specify the capabilities to keep when executing
// the process inside the container.
type LinuxCapabilities struct {
// Bounding is the set of capabilities checked by the kernel.
Bounding []string
// Effective is the set of capabilities checked by the kernel.
Effective []string
// Inheritable is the capabilities preserved across execve.
Inheritable []string
// Permitted is the limiting superset for effective capabilities.
Permitted []string
// Ambient is the ambient set of capabilities that are kept.
Ambient []string
}
// Cmd represents a command to execute in a running container.
type Cmd struct {
Args []string
Envs []EnvVar
SupplementaryGroups []string
// Note that these fields *MUST* remain as strings.
//
// The reason being that we want runtimes to be able to support CLI
// operations like "exec --user=". That option allows the
// specification of a user (either as a string username or a numeric
// UID), and may optionally also include a group (groupame or GID).
//
// Since this type is the interface to allow the runtime to specify
// the user and group the workload can run as, these user and group
// fields cannot be encoded as integer values since that would imply
// the runtime itself would need to perform a UID/GID lookup on the
// user-specified username/groupname. But that isn't practically
// possible given that to do so would require the runtime to access
// the image to allow it to interrogate the appropriate databases to
// convert the username/groupnames to UID/GID values.
//
// Note that this argument applies solely to the _runtime_ supporting
// a "--user=" option when running in a "standalone mode" - there is
// no issue when the runtime is called by a container manager since
// all the user and group mapping is handled by the container manager
// and specified to the runtime in terms of UID/GID's in the
// configuration file generated by the container manager.
User string
PrimaryGroup string
WorkDir string
Console string
Capabilities LinuxCapabilities
Interactive bool
Detach bool
NoNewPrivileges bool
}
// Resources describes VM resources configuration.
type Resources struct {
// Memory is the amount of available memory in MiB.
Memory uint
MemorySlots uint8
}
// SandboxStatus describes a sandbox status.
type SandboxStatus struct {
ID string
State State
State types.State
Hypervisor HypervisorType
HypervisorConfig HypervisorConfig
Agent AgentType
@ -338,7 +74,7 @@ type SandboxConfig struct {
NetworkConfig NetworkConfig
// Volumes is a list of shared volumes between the host and the Sandbox.
Volumes []Volume
Volumes []types.Volume
// Containers describe the list of containers within a Sandbox.
// This list can be empty and populated by adding containers
@ -355,7 +91,7 @@ type SandboxConfig struct {
// SharePidNs sets all containers to share the same sandbox level pid namespace.
SharePidNs bool
// Stateful keeps sandbox resources in memory across APIs. Users will be responsible
// types.Stateful keeps sandbox resources in memory across APIs. Users will be responsible
// for calling Release() to release the memory resources.
Stateful bool
@ -477,14 +213,14 @@ type Sandbox struct {
devManager api.DeviceManager
volumes []Volume
volumes []types.Volume
containers map[string]*Container
runPath string
configPath string
state State
state types.State
networkNS NetworkNamespace
@ -625,7 +361,7 @@ func (s *Sandbox) Status() SandboxStatus {
// Monitor returns a error channel for watcher to watch at
func (s *Sandbox) Monitor() (chan error, error) {
if s.state.State != StateRunning {
if s.state.State != types.StateRunning {
return nil, fmt.Errorf("Sandbox is not running")
}
@ -640,7 +376,7 @@ func (s *Sandbox) Monitor() (chan error, error) {
// WaitProcess waits on a container process and return its exit code
func (s *Sandbox) WaitProcess(containerID, processID string) (int32, error) {
if s.state.State != StateRunning {
if s.state.State != types.StateRunning {
return 0, fmt.Errorf("Sandbox not running")
}
@ -655,7 +391,7 @@ func (s *Sandbox) WaitProcess(containerID, processID string) (int32, error) {
// SignalProcess sends a signal to a process of a container when all is false.
// When all is true, it sends the signal to all processes of a container.
func (s *Sandbox) SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error {
if s.state.State != StateRunning {
if s.state.State != types.StateRunning {
return fmt.Errorf("Sandbox not running")
}
@ -669,7 +405,7 @@ func (s *Sandbox) SignalProcess(containerID, processID string, signal syscall.Si
// WinsizeProcess resizes the tty window of a process
func (s *Sandbox) WinsizeProcess(containerID, processID string, height, width uint32) error {
if s.state.State != StateRunning {
if s.state.State != types.StateRunning {
return fmt.Errorf("Sandbox not running")
}
@ -683,7 +419,7 @@ func (s *Sandbox) WinsizeProcess(containerID, processID string, height, width ui
// IOStream returns stdin writer, stdout reader and stderr reader of a process
func (s *Sandbox) IOStream(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error) {
if s.state.State != StateRunning {
if s.state.State != types.StateRunning {
return nil, nil, nil, fmt.Errorf("Sandbox not running")
}
@ -795,7 +531,7 @@ func createSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac
}
// Set sandbox state
if err := s.setSandboxState(StateReady); err != nil {
if err := s.setSandboxState(types.StateReady); err != nil {
return nil, err
}
@ -831,7 +567,7 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
containers: map[string]*Container{},
runPath: filepath.Join(runStoragePath, sandboxConfig.ID),
configPath: filepath.Join(configStoragePath, sandboxConfig.ID),
state: State{},
state: types.State{},
annotationsLock: &sync.RWMutex{},
wg: &sync.WaitGroup{},
shmSize: sandboxConfig.ShmSize,
@ -984,9 +720,9 @@ func (s *Sandbox) removeContainer(containerID string) error {
// Delete deletes an already created sandbox.
// The VM in which the sandbox is running will be shut down.
func (s *Sandbox) Delete() error {
if s.state.State != StateReady &&
s.state.State != StatePaused &&
s.state.State != StateStopped {
if s.state.State != types.StateReady &&
s.state.State != types.StatePaused &&
s.state.State != types.StateStopped {
return fmt.Errorf("Sandbox not ready, paused or stopped, impossible to delete")
}
@ -1464,7 +1200,7 @@ func (s *Sandbox) StatusContainer(containerID string) (ContainerStatus, error) {
// EnterContainer is the virtcontainers container command execution entry point.
// EnterContainer enters an already running container and runs a given command.
func (s *Sandbox) EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error) {
func (s *Sandbox) EnterContainer(containerID string, cmd types.Cmd) (VCContainer, *Process, error) {
// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
@ -1566,11 +1302,11 @@ func (s *Sandbox) createContainers() error {
// Start starts a sandbox. The containers that are making the sandbox
// will be started.
func (s *Sandbox) Start() error {
if err := s.state.validTransition(s.state.State, StateRunning); err != nil {
if err := s.state.ValidTransition(s.state.State, types.StateRunning); err != nil {
return err
}
if err := s.setSandboxState(StateRunning); err != nil {
if err := s.setSandboxState(types.StateRunning); err != nil {
return err
}
@ -1591,12 +1327,12 @@ func (s *Sandbox) Stop() error {
span, _ := s.trace("stop")
defer span.Finish()
if s.state.State == StateStopped {
if s.state.State == types.StateStopped {
s.Logger().Info("sandbox already stopped")
return nil
}
if err := s.state.validTransition(s.state.State, StateStopped); err != nil {
if err := s.state.ValidTransition(s.state.State, types.StateStopped); err != nil {
return err
}
@ -1610,7 +1346,7 @@ func (s *Sandbox) Stop() error {
return err
}
if err := s.setSandboxState(StateStopped); err != nil {
if err := s.setSandboxState(types.StateStopped); err != nil {
return err
}
@ -1656,7 +1392,7 @@ func (s *Sandbox) enter(args []string) error {
// setSandboxState sets both the in-memory and on-disk state of the
// sandbox.
func (s *Sandbox) setSandboxState(state stateString) error {
func (s *Sandbox) setSandboxState(state types.StateString) error {
if state == "" {
return errNeedState
}
@ -1671,21 +1407,21 @@ func (s *Sandbox) setSandboxState(state stateString) error {
func (s *Sandbox) pauseSetStates() error {
// XXX: When a sandbox is paused, all its containers are forcibly
// paused too.
if err := s.setContainersState(StatePaused); err != nil {
if err := s.setContainersState(types.StatePaused); err != nil {
return err
}
return s.setSandboxState(StatePaused)
return s.setSandboxState(types.StatePaused)
}
func (s *Sandbox) resumeSetStates() error {
// XXX: Resuming a paused sandbox puts all containers back into the
// running state.
if err := s.setContainersState(StateRunning); err != nil {
if err := s.setContainersState(types.StateRunning); err != nil {
return err
}
return s.setSandboxState(StateRunning)
return s.setSandboxState(types.StateRunning)
}
// getAndSetSandboxBlockIndex retrieves sandbox block index and increments it for
@ -1729,7 +1465,7 @@ func (s *Sandbox) setSandboxPid(pid int) error {
return s.storage.storeSandboxResource(s.id, stateFileType, s.state)
}
func (s *Sandbox) setContainersState(state stateString) error {
func (s *Sandbox) setContainersState(state types.StateString) error {
if state == "" {
return errNeedState
}

View File

@ -24,6 +24,7 @@ import (
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
"github.com/kata-containers/runtime/virtcontainers/device/manager"
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/types"
"golang.org/x/sys/unix"
)
@ -41,7 +42,7 @@ func newHypervisorConfig(kernelParams []Param, hParams []Param) HypervisorConfig
func testCreateSandbox(t *testing.T, id string,
htype HypervisorType, hconfig HypervisorConfig, atype AgentType,
nmodel NetworkModel, nconfig NetworkConfig, containers []ContainerConfig,
volumes []Volume) (*Sandbox, error) {
volumes []types.Volume) (*Sandbox, error) {
sconfig := SandboxConfig{
ID: id,
@ -114,7 +115,7 @@ func TestCreateSandboxEmtpyID(t *testing.T) {
defer cleanUp()
}
func testSandboxStateTransition(t *testing.T, state stateString, newState stateString) error {
func testSandboxStateTransition(t *testing.T, state types.StateString, newState types.StateString) error {
hConfig := newHypervisorConfig(nil, nil)
p, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil)
@ -123,57 +124,57 @@ func testSandboxStateTransition(t *testing.T, state stateString, newState stateS
}
defer cleanUp()
p.state = State{
p.state = types.State{
State: state,
}
return p.state.validTransition(state, newState)
return p.state.ValidTransition(state, newState)
}
func TestSandboxStateReadyRunning(t *testing.T) {
err := testSandboxStateTransition(t, StateReady, StateRunning)
err := testSandboxStateTransition(t, types.StateReady, types.StateRunning)
if err != nil {
t.Fatal(err)
}
}
func TestSandboxStateRunningPaused(t *testing.T) {
err := testSandboxStateTransition(t, StateRunning, StatePaused)
err := testSandboxStateTransition(t, types.StateRunning, types.StatePaused)
if err != nil {
t.Fatal(err)
}
}
func TestSandboxStatePausedRunning(t *testing.T) {
err := testSandboxStateTransition(t, StatePaused, StateRunning)
err := testSandboxStateTransition(t, types.StatePaused, types.StateRunning)
if err != nil {
t.Fatal(err)
}
}
func TestSandboxStatePausedStopped(t *testing.T) {
err := testSandboxStateTransition(t, StatePaused, StateStopped)
err := testSandboxStateTransition(t, types.StatePaused, types.StateStopped)
if err != nil {
t.Fatal(err)
}
}
func TestSandboxStateRunningStopped(t *testing.T) {
err := testSandboxStateTransition(t, StateRunning, StateStopped)
err := testSandboxStateTransition(t, types.StateRunning, types.StateStopped)
if err != nil {
t.Fatal(err)
}
}
func TestSandboxStateReadyPaused(t *testing.T) {
err := testSandboxStateTransition(t, StateReady, StateStopped)
err := testSandboxStateTransition(t, types.StateReady, types.StateStopped)
if err != nil {
t.Fatal(err)
}
}
func TestSandboxStatePausedReady(t *testing.T) {
err := testSandboxStateTransition(t, StateStopped, StateReady)
err := testSandboxStateTransition(t, types.StateStopped, types.StateReady)
if err == nil {
t.Fatal("Invalid transition from Ready to Paused")
}
@ -265,22 +266,22 @@ func TestSandboxFileNegative(t *testing.T) {
}
}
func testStateValid(t *testing.T, stateStr stateString, expected bool) {
state := &State{
func testStateValid(t *testing.T, stateStr types.StateString, expected bool) {
state := &types.State{
State: stateStr,
}
ok := state.valid()
ok := state.Valid()
if ok != expected {
t.Fatal()
}
}
func TestStateValidSuccessful(t *testing.T) {
testStateValid(t, StateReady, true)
testStateValid(t, StateRunning, true)
testStateValid(t, StatePaused, true)
testStateValid(t, StateStopped, true)
testStateValid(t, types.StateReady, true)
testStateValid(t, types.StateRunning, true)
testStateValid(t, types.StatePaused, true)
testStateValid(t, types.StateStopped, true)
}
func TestStateValidFailing(t *testing.T) {
@ -288,22 +289,22 @@ func TestStateValidFailing(t *testing.T) {
}
func TestValidTransitionFailingOldStateMismatch(t *testing.T) {
state := &State{
State: StateReady,
state := &types.State{
State: types.StateReady,
}
err := state.validTransition(StateRunning, StateStopped)
err := state.ValidTransition(types.StateRunning, types.StateStopped)
if err == nil {
t.Fatal()
}
}
func TestVolumesSetSuccessful(t *testing.T) {
volumes := &Volumes{}
volumes := &types.Volumes{}
volStr := "mountTag1:hostPath1 mountTag2:hostPath2"
expected := Volumes{
expected := types.Volumes{
{
MountTag: "mountTag1",
HostPath: "hostPath1",
@ -325,7 +326,7 @@ func TestVolumesSetSuccessful(t *testing.T) {
}
func TestVolumesSetFailingTooFewArguments(t *testing.T) {
volumes := &Volumes{}
volumes := &types.Volumes{}
volStr := "mountTag1 mountTag2"
@ -336,7 +337,7 @@ func TestVolumesSetFailingTooFewArguments(t *testing.T) {
}
func TestVolumesSetFailingTooManyArguments(t *testing.T) {
volumes := &Volumes{}
volumes := &types.Volumes{}
volStr := "mountTag1:hostPath1:Foo1 mountTag2:hostPath2:Foo2"
@ -347,7 +348,7 @@ func TestVolumesSetFailingTooManyArguments(t *testing.T) {
}
func TestVolumesSetFailingVoidArguments(t *testing.T) {
volumes := &Volumes{}
volumes := &types.Volumes{}
volStr := ": : :"
@ -358,7 +359,7 @@ func TestVolumesSetFailingVoidArguments(t *testing.T) {
}
func TestVolumesStringSuccessful(t *testing.T) {
volumes := &Volumes{
volumes := &types.Volumes{
{
MountTag: "mountTag1",
HostPath: "hostPath1",
@ -378,11 +379,11 @@ func TestVolumesStringSuccessful(t *testing.T) {
}
func TestSocketsSetSuccessful(t *testing.T) {
sockets := &Sockets{}
sockets := &types.Sockets{}
sockStr := "devID1:id1:hostPath1:Name1 devID2:id2:hostPath2:Name2"
expected := Sockets{
expected := types.Sockets{
{
DeviceID: "devID1",
ID: "id1",
@ -408,7 +409,7 @@ func TestSocketsSetSuccessful(t *testing.T) {
}
func TestSocketsSetFailingWrongArgsAmount(t *testing.T) {
sockets := &Sockets{}
sockets := &types.Sockets{}
sockStr := "devID1:id1:hostPath1"
@ -419,7 +420,7 @@ func TestSocketsSetFailingWrongArgsAmount(t *testing.T) {
}
func TestSocketsSetFailingVoidArguments(t *testing.T) {
sockets := &Sockets{}
sockets := &types.Sockets{}
sockStr := ":::"
@ -430,7 +431,7 @@ func TestSocketsSetFailingVoidArguments(t *testing.T) {
}
func TestSocketsStringSuccessful(t *testing.T) {
sockets := &Sockets{
sockets := &types.Sockets{
{
DeviceID: "devID1",
ID: "id1",
@ -471,7 +472,7 @@ func TestSandboxEnterSuccessful(t *testing.T) {
}
}
func testCheckInitSandboxAndContainerStates(p *Sandbox, initialSandboxState State, c *Container, initialContainerState State) error {
func testCheckInitSandboxAndContainerStates(p *Sandbox, initialSandboxState types.State, c *Container, initialContainerState types.State) error {
if p.state.State != initialSandboxState.State {
return fmt.Errorf("Expected sandbox state %v, got %v", initialSandboxState.State, p.state.State)
}
@ -483,7 +484,7 @@ func testCheckInitSandboxAndContainerStates(p *Sandbox, initialSandboxState Stat
return nil
}
func testForceSandboxStateChangeAndCheck(t *testing.T, p *Sandbox, newSandboxState State) error {
func testForceSandboxStateChangeAndCheck(t *testing.T, p *Sandbox, newSandboxState types.State) error {
// force sandbox state change
if err := p.setSandboxState(newSandboxState.State); err != nil {
t.Fatalf("Unexpected error: %v (sandbox %+v)", err, p)
@ -497,7 +498,7 @@ func testForceSandboxStateChangeAndCheck(t *testing.T, p *Sandbox, newSandboxSta
return nil
}
func testForceContainerStateChangeAndCheck(t *testing.T, p *Sandbox, c *Container, newContainerState State) error {
func testForceContainerStateChangeAndCheck(t *testing.T, p *Sandbox, c *Container, newContainerState types.State) error {
// force container state change
if err := c.setContainerState(newContainerState.State); err != nil {
t.Fatalf("Unexpected error: %v (sandbox %+v)", err, p)
@ -511,7 +512,7 @@ func testForceContainerStateChangeAndCheck(t *testing.T, p *Sandbox, c *Containe
return nil
}
func testCheckSandboxOnDiskState(p *Sandbox, sandboxState State) error {
func testCheckSandboxOnDiskState(p *Sandbox, sandboxState types.State) error {
// check on-disk state is correct
if p.state.State != sandboxState.State {
return fmt.Errorf("Expected state %v, got %v", sandboxState.State, p.state.State)
@ -520,7 +521,7 @@ func testCheckSandboxOnDiskState(p *Sandbox, sandboxState State) error {
return nil
}
func testCheckContainerOnDiskState(c *Container, containerState State) error {
func testCheckContainerOnDiskState(c *Container, containerState types.State) error {
// check on-disk state is correct
if c.state.State != containerState.State {
return fmt.Errorf("Expected state %v, got %v", containerState.State, c.state.State)
@ -546,13 +547,13 @@ func TestSandboxSetSandboxAndContainerState(t *testing.T) {
t.Fatalf("Expected 1 container found %v", l)
}
initialSandboxState := State{
State: StateReady,
initialSandboxState := types.State{
State: types.StateReady,
}
// After a sandbox creation, a container has a READY state
initialContainerState := State{
State: StateReady,
initialContainerState := types.State{
State: types.StateReady,
}
c, err := p.findContainer(contID)
@ -571,16 +572,16 @@ func TestSandboxSetSandboxAndContainerState(t *testing.T) {
t.Fatal(err)
}
newSandboxState := State{
State: StateRunning,
newSandboxState := types.State{
State: types.StateRunning,
}
if err := testForceSandboxStateChangeAndCheck(t, p, newSandboxState); err != nil {
t.Error(err)
}
newContainerState := State{
State: StateStopped,
newContainerState := types.State{
State: types.StateStopped,
}
if err := testForceContainerStateChangeAndCheck(t, p, c, newContainerState); err != nil {
@ -625,7 +626,7 @@ func TestSandboxSetSandboxStateFailingStoreSandboxResource(t *testing.T) {
storage: fs,
}
err := sandbox.setSandboxState(StateReady)
err := sandbox.setSandboxState(types.StateReady)
if err == nil {
t.Fatal()
}
@ -645,7 +646,7 @@ func TestSandboxSetContainersStateFailingEmptySandboxID(t *testing.T) {
sandbox.containers = containers
err := sandbox.setContainersState(StateReady)
err := sandbox.setContainersState(types.StateReady)
if err == nil {
t.Fatal()
}
@ -970,7 +971,7 @@ func TestContainerSetStateBlockIndex(t *testing.T) {
t.Fatal(err)
}
state := State{
state := types.State{
State: "stopped",
Fstype: "vfs",
}
@ -1011,7 +1012,7 @@ func TestContainerSetStateBlockIndex(t *testing.T) {
t.Fatal()
}
var res State
var res types.State
err = json.Unmarshal([]byte(string(fileData)), &res)
if err != nil {
t.Fatal(err)
@ -1068,7 +1069,7 @@ func TestContainerStateSetFstype(t *testing.T) {
t.Fatal(err)
}
state := State{
state := types.State{
State: "ready",
Fstype: "vfs",
BlockIndex: 3,
@ -1111,7 +1112,7 @@ func TestContainerStateSetFstype(t *testing.T) {
t.Fatal()
}
var res State
var res types.State
err = json.Unmarshal([]byte(string(fileData)), &res)
if err != nil {
t.Fatal(err)
@ -1391,7 +1392,7 @@ func TestEnterContainer(t *testing.T) {
defer cleanUp()
contID := "999"
cmd := Cmd{}
cmd := types.Cmd{}
_, _, err = s.EnterContainer(contID, cmd)
assert.NotNil(t, err, "Entering non-existing container should fail")
@ -1613,7 +1614,7 @@ func TestAttachBlockDevice(t *testing.T) {
err = device.Detach(sandbox)
assert.Nil(t, err)
container.state.State = StateReady
container.state.State = types.StateReady
err = device.Attach(sandbox)
assert.Nil(t, err)
@ -1627,7 +1628,7 @@ func TestAttachBlockDevice(t *testing.T) {
err = device.Detach(sandbox)
assert.Nil(t, err)
container.state.State = StateReady
container.state.State = types.StateReady
err = device.Attach(sandbox)
assert.Nil(t, err)
@ -1664,7 +1665,7 @@ func TestPreAddDevice(t *testing.T) {
id: contID,
sandboxID: testSandboxID,
}
container.state.State = StateReady
container.state.State = types.StateReady
// create state file
path := filepath.Join(runStoragePath, testSandboxID, container.ID())
@ -1756,7 +1757,7 @@ func TestStartNetworkMonitor(t *testing.T) {
}
func TestSandboxStopStopped(t *testing.T) {
s := &Sandbox{state: State{State: StateStopped}}
s := &Sandbox{state: types.State{State: types.StateStopped}}
err := s.Stop()
assert.Nil(t, err)

View File

@ -13,6 +13,7 @@ import (
"time"
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/mitchellh/mapstructure"
"github.com/sirupsen/logrus"
)
@ -155,7 +156,7 @@ func stopShim(pid int) error {
return nil
}
func prepareAndStartShim(sandbox *Sandbox, shim shim, cid, token, url string, cmd Cmd,
func prepareAndStartShim(sandbox *Sandbox, shim shim, cid, token, url string, cmd types.Cmd,
createNSList []ns.NSType, enterNSList []ns.Namespace) (*Process, error) {
process := &Process{
Token: token,

View File

@ -10,26 +10,26 @@ import (
"strings"
)
// stateString is a string representing a sandbox state.
type stateString string
// StateString is a string representing a sandbox state.
type StateString string
const (
// StateReady represents a sandbox/container that's ready to be run
StateReady stateString = "ready"
StateReady StateString = "ready"
// StateRunning represents a sandbox/container that's currently running.
StateRunning stateString = "running"
StateRunning StateString = "running"
// StatePaused represents a sandbox/container that has been paused.
StatePaused stateString = "paused"
StatePaused StateString = "paused"
// StateStopped represents a sandbox/container that has been stopped.
StateStopped stateString = "stopped"
StateStopped StateString = "stopped"
)
// State is a sandbox state structure.
type State struct {
State stateString `json:"state"`
State StateString `json:"state"`
BlockDeviceID string
// Index of the block device passed to hypervisor.
@ -46,9 +46,9 @@ type State struct {
GuestMemoryBlockSizeMB uint32 `json:"guestMemoryBlockSize"`
}
// valid checks that the sandbox state is valid.
func (state *State) valid() bool {
for _, validState := range []stateString{StateReady, StateRunning, StatePaused, StateStopped} {
// Valid checks that the sandbox state is valid.
func (state *State) Valid() bool {
for _, validState := range []StateString{StateReady, StateRunning, StatePaused, StateStopped} {
if state.State == validState {
return true
}
@ -57,9 +57,9 @@ func (state *State) valid() bool {
return false
}
// validTransition returns an error if we want to move to
// ValidTransition returns an error if we want to move to
// an unreachable state.
func (state *State) validTransition(oldState stateString, newState stateString) error {
func (state *State) ValidTransition(oldState StateString, newState StateString) error {
if state.State != oldState {
return fmt.Errorf("Invalid state %s (Expecting %s)", state.State, oldState)
}