From 723e37b5725107182c2846bc6a33d93013f0df71 Mon Sep 17 00:00:00 2001 From: z00404060 Date: Wed, 7 Nov 2018 03:58:20 -0500 Subject: [PATCH] virtcontainers: Extract shim related operations to a separate package reason: With the increase of code in the "virtcontainers" package, code coupling is also increasing. Therefore, I want to recfactor the code of shim, agent, proxy, network and other related modules, decouple them and put them into a separate package. Now I put the relevant code of "shim" into the independent "shim" package. I hope it can be perfected through your suggestions. If possible, I will continue to reconstruct agent, proxy, network and so on. Fixes: #890 Signed-off-by: Shucheng Zhang --- cli/create.go | 3 +- cli/delete_test.go | 2 +- cli/events.go | 2 +- cli/events_test.go | 2 +- cli/exec.go | 3 +- cli/exec_test.go | 22 ++--- cli/kata-env.go | 3 +- cli/kata-env_test.go | 3 +- cli/kill.go | 2 +- cli/kill_test.go | 2 +- cli/main_test.go | 5 +- cli/network.go | 11 +-- cli/network_test.go | 13 ++- cli/pause_test.go | 2 +- cli/ps.go | 2 +- cli/ps_test.go | 2 +- cli/update.go | 2 +- cli/update_test.go | 2 +- containerd-shim-v2/delete.go | 2 +- containerd-shim-v2/exec.go | 2 +- containerd-shim-v2/pause_test.go | 2 +- containerd-shim-v2/service.go | 2 +- containerd-shim-v2/utils_test.go | 3 +- pkg/katautils/config.go | 17 ++-- pkg/katautils/config_test.go | 9 +- pkg/katautils/create.go | 31 +++--- pkg/katautils/create_test.go | 3 +- virtcontainers/agent.go | 15 ++- virtcontainers/api.go | 20 ++-- virtcontainers/api_test.go | 7 +- virtcontainers/cc_shim_test.go | 78 ++++++++------- virtcontainers/container.go | 36 ++----- virtcontainers/container_test.go | 2 +- virtcontainers/example_pod_run_test.go | 2 +- virtcontainers/fc.go | 2 +- virtcontainers/filesystem_resource_storage.go | 12 +-- .../filesystem_resource_storage_test.go | 2 +- virtcontainers/hack/virtc/main.go | 13 +-- virtcontainers/hyperstart_agent.go | 26 ++--- virtcontainers/hyperstart_agent_test.go | 2 +- virtcontainers/hypervisor.go | 2 +- virtcontainers/implementation.go | 15 ++- virtcontainers/interfaces.go | 29 +++--- virtcontainers/kata_agent.go | 47 ++++----- virtcontainers/kata_agent_test.go | 5 +- virtcontainers/kata_builtin_shim.go | 15 --- virtcontainers/kata_shim_test.go | 77 ++++++++------- virtcontainers/mock_hypervisor.go | 2 +- virtcontainers/noop_agent.go | 17 ++-- virtcontainers/noop_agent_test.go | 2 +- virtcontainers/noop_resource_storage.go | 8 +- virtcontainers/noop_resource_storage_test.go | 3 +- virtcontainers/noop_shim.go | 14 --- virtcontainers/noop_shim_test.go | 15 ++- virtcontainers/pkg/oci/utils.go | 5 +- virtcontainers/pkg/oci/utils_test.go | 7 +- virtcontainers/{ => pkg}/types/asset.go | 0 virtcontainers/{ => pkg}/types/asset_test.go | 0 .../{ => pkg}/types/capabilities.go | 0 .../{ => pkg}/types/capabilities_test.go | 0 virtcontainers/pkg/types/container.go | 27 ++++++ virtcontainers/{ => pkg}/types/pci.go | 0 virtcontainers/{ => pkg}/types/pci_test.go | 0 virtcontainers/{ => pkg}/types/sandbox.go | 0 virtcontainers/pkg/vcmock/container.go | 3 +- virtcontainers/pkg/vcmock/mock.go | 15 ++- virtcontainers/pkg/vcmock/mock_test.go | 19 ++-- virtcontainers/pkg/vcmock/sandbox.go | 17 ++-- virtcontainers/pkg/vcmock/types.go | 17 ++-- virtcontainers/qemu.go | 2 +- virtcontainers/qemu_amd64.go | 2 +- virtcontainers/qemu_amd64_test.go | 2 +- virtcontainers/qemu_arch_base.go | 2 +- virtcontainers/qemu_arch_base_test.go | 2 +- virtcontainers/qemu_ppc64le.go | 2 +- virtcontainers/qemu_test.go | 2 +- virtcontainers/resource_storage.go | 6 +- virtcontainers/sandbox.go | 20 ++-- virtcontainers/sandbox_test.go | 2 +- virtcontainers/{ => shim}/cc_shim.go | 14 ++- virtcontainers/shim/kata_builtin_shim.go | 16 ++++ virtcontainers/{ => shim}/kata_shim.go | 17 ++-- virtcontainers/shim/noop_shim.go | 15 +++ virtcontainers/{ => shim}/shim.go | 96 ++++++++++--------- virtcontainers/shim_test.go | 82 ++++++++-------- 85 files changed, 533 insertions(+), 481 deletions(-) delete mode 100644 virtcontainers/kata_builtin_shim.go delete mode 100644 virtcontainers/noop_shim.go rename virtcontainers/{ => pkg}/types/asset.go (100%) rename virtcontainers/{ => pkg}/types/asset_test.go (100%) rename virtcontainers/{ => pkg}/types/capabilities.go (100%) rename virtcontainers/{ => pkg}/types/capabilities_test.go (100%) create mode 100644 virtcontainers/pkg/types/container.go rename virtcontainers/{ => pkg}/types/pci.go (100%) rename virtcontainers/{ => pkg}/types/pci_test.go (100%) rename virtcontainers/{ => pkg}/types/sandbox.go (100%) rename virtcontainers/{ => shim}/cc_shim.go (71%) create mode 100644 virtcontainers/shim/kata_builtin_shim.go rename virtcontainers/{ => shim}/kata_shim.go (72%) create mode 100644 virtcontainers/shim/noop_shim.go rename virtcontainers/{ => shim}/shim.go (64%) diff --git a/cli/create.go b/cli/create.go index 5f719299e1..c13b3b7d8b 100644 --- a/cli/create.go +++ b/cli/create.go @@ -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/pkg/types" "github.com/urfave/cli" ) @@ -127,7 +128,7 @@ func create(ctx context.Context, containerID, bundlePath, console, pidFilePath s disableOutput := noNeedForOutput(detach, ociSpec.Process.Terminal) - var process vc.Process + var process types.Process switch containerType { case vc.PodSandbox: _, process, err = katautils.CreateSandbox(ctx, vci, ociSpec, runtimeConfig, containerID, bundlePath, console, disableOutput, systemdCgroup, false) diff --git a/cli/delete_test.go b/cli/delete_test.go index e3cde76f71..c08ad59652 100644 --- a/cli/delete_test.go +++ b/cli/delete_test.go @@ -15,8 +15,8 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/runtime/virtcontainers/types" "github.com/stretchr/testify/assert" "github.com/urfave/cli" ) diff --git a/cli/events.go b/cli/events.go index 9e9200a6f1..99c5d0da8f 100644 --- a/cli/events.go +++ b/cli/events.go @@ -14,7 +14,7 @@ import ( "time" vc "github.com/kata-containers/runtime/virtcontainers" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/pkg/katautils" "github.com/sirupsen/logrus" diff --git a/cli/events_test.go b/cli/events_test.go index b71ca1b3f8..d01e8af221 100644 --- a/cli/events_test.go +++ b/cli/events_test.go @@ -14,8 +14,8 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/runtime/virtcontainers/types" "github.com/stretchr/testify/assert" "github.com/urfave/cli" ) diff --git a/cli/exec.go b/cli/exec.go index 1c1574ce08..67e21c951d 100644 --- a/cli/exec.go +++ b/cli/exec.go @@ -16,8 +16,7 @@ import ( "github.com/kata-containers/runtime/pkg/katautils" "github.com/kata-containers/runtime/virtcontainers/pkg/oci" - "github.com/kata-containers/runtime/virtcontainers/types" - + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/urfave/cli" ) diff --git a/cli/exec_test.go b/cli/exec_test.go index 30edaf4cbb..5483506c08 100644 --- a/cli/exec_test.go +++ b/cli/exec_test.go @@ -17,8 +17,8 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" "github.com/kata-containers/runtime/virtcontainers/pkg/oci" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/runtime/virtcontainers/types" "github.com/stretchr/testify/assert" "github.com/urfave/cli" ) @@ -300,8 +300,8 @@ func TestExecuteWithFlags(t *testing.T) { assert.True(vcmock.IsMockError(err)) - 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 + testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *types.Process, error) { + return &vcmock.Sandbox{}, &vcmock.Container{}, &types.Process{}, nil } defer func() { @@ -317,14 +317,14 @@ func TestExecuteWithFlags(t *testing.T) { os.Remove(pidFilePath) // Process ran and exited successfully - testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { + testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *types.Process, error) { // create a fake container process workload := []string{"cat", "/dev/null"} command := exec.Command(workload[0], workload[1:]...) err := command.Start() assert.NoError(err, "Unable to start process %v: %s", workload, err) - vcProcess := vc.Process{} + vcProcess := types.Process{} vcProcess.Pid = command.Process.Pid return &vcmock.Sandbox{}, &vcmock.Container{}, &vcProcess, nil } @@ -381,14 +381,14 @@ func TestExecuteWithFlagsDetached(t *testing.T) { testingImpl.StatusContainerFunc = nil }() - testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { + testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *types.Process, error) { // create a fake container process workload := []string{"cat", "/dev/null"} command := exec.Command(workload[0], workload[1:]...) err := command.Start() assert.NoError(err, "Unable to start process %v: %s", workload, err) - vcProcess := vc.Process{} + vcProcess := types.Process{} vcProcess.Pid = command.Process.Pid return &vcmock.Sandbox{}, &vcmock.Container{}, &vcProcess, nil } @@ -543,13 +543,13 @@ func TestExecuteWithValidProcessJson(t *testing.T) { workload := []string{"cat", "/dev/null"} - testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { + testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *types.Process, error) { // create a fake container process command := exec.Command(workload[0], workload[1:]...) err := command.Start() assert.NoError(err, "Unable to start process %v: %s", workload, err) - vcProcess := vc.Process{} + vcProcess := types.Process{} vcProcess.Pid = command.Process.Pid return &vcmock.Sandbox{}, &vcmock.Container{}, &vcProcess, nil @@ -645,13 +645,13 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) { workload := []string{"cat", "/dev/null"} - testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { + testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *types.Process, error) { // create a fake container process command := exec.Command(workload[0], workload[1:]...) err := command.Start() assert.NoError(err, "Unable to start process %v: %s", workload, err) - vcProcess := vc.Process{} + vcProcess := types.Process{} vcProcess.Pid = command.Process.Pid return &vcmock.Sandbox{}, &vcmock.Container{}, &vcProcess, nil diff --git a/cli/kata-env.go b/cli/kata-env.go index 8bf2d05760..7a1ccee5ac 100644 --- a/cli/kata-env.go +++ b/cli/kata-env.go @@ -17,6 +17,7 @@ import ( "github.com/kata-containers/runtime/pkg/katautils" vc "github.com/kata-containers/runtime/virtcontainers" "github.com/kata-containers/runtime/virtcontainers/pkg/oci" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" vcUtils "github.com/kata-containers/runtime/virtcontainers/utils" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/urfave/cli" @@ -283,7 +284,7 @@ func getCommandVersion(cmd string) (string, error) { } func getShimInfo(config oci.RuntimeConfig) (ShimInfo, error) { - shimConfig, ok := config.ShimConfig.(vc.ShimConfig) + shimConfig, ok := config.ShimConfig.(vshim.Config) if !ok { return ShimInfo{}, errors.New("cannot determine shim config") } diff --git a/cli/kata-env_test.go b/cli/kata-env_test.go index 966b818bc6..71934d69d6 100644 --- a/cli/kata-env_test.go +++ b/cli/kata-env_test.go @@ -20,6 +20,7 @@ import ( "github.com/BurntSushi/toml" vc "github.com/kata-containers/runtime/virtcontainers" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" vcUtils "github.com/kata-containers/runtime/virtcontainers/utils" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/urfave/cli" @@ -223,7 +224,7 @@ func getExpectedNetmonDetails(config oci.RuntimeConfig) (NetmonInfo, error) { } func getExpectedShimDetails(config oci.RuntimeConfig) (ShimInfo, error) { - shimConfig, ok := config.ShimConfig.(vc.ShimConfig) + shimConfig, ok := config.ShimConfig.(vshim.Config) if !ok { return ShimInfo{}, fmt.Errorf("failed to get shim config") } diff --git a/cli/kill.go b/cli/kill.go index 97b3a549b2..d859f49595 100644 --- a/cli/kill.go +++ b/cli/kill.go @@ -15,7 +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/kata-containers/runtime/virtcontainers/pkg/types" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) diff --git a/cli/kill_test.go b/cli/kill_test.go index 45ba4225b2..abadf0de09 100644 --- a/cli/kill_test.go +++ b/cli/kill_test.go @@ -15,8 +15,8 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/runtime/virtcontainers/types" "github.com/stretchr/testify/assert" ) diff --git a/cli/main_test.go b/cli/main_test.go index f9a65fce81..e68aab5775 100644 --- a/cli/main_test.go +++ b/cli/main_test.go @@ -25,8 +25,9 @@ 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/pkg/types" "github.com/kata-containers/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/runtime/virtcontainers/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/stretchr/testify/assert" jaeger "github.com/uber/jaeger-client-go" @@ -244,7 +245,7 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf HypervisorConfig: hypervisorConfig, AgentType: vc.KataContainersAgent, ProxyType: vc.CCProxyType, - ShimType: vc.CCShimType, + ShimType: vshim.CCShimType, Console: consolePath, }, nil } diff --git a/cli/network.go b/cli/network.go index 881a235800..0556b2b490 100644 --- a/cli/network.go +++ b/cli/network.go @@ -11,8 +11,7 @@ import ( "fmt" "os" - vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -152,7 +151,7 @@ func networkModifyCommand(ctx context.Context, containerID, input string, opType } switch opType { case interfaceType: - var inf, resultingInf *vcTypes.Interface + var inf, resultingInf *types.Interface if err = json.NewDecoder(f).Decode(&inf); err != nil { return err } @@ -171,7 +170,7 @@ func networkModifyCommand(ctx context.Context, containerID, input string, opType } json.NewEncoder(output).Encode(resultingInf) case routeType: - var routes, resultingRoutes []*vcTypes.Route + var routes, resultingRoutes []*types.Route if err = json.NewDecoder(f).Decode(&routes); err != nil { return err } @@ -209,7 +208,7 @@ func networkListCommand(ctx context.Context, containerID string, opType networkT switch opType { case interfaceType: - var interfaces []*vcTypes.Interface + var interfaces []*types.Interface interfaces, err = vci.ListInterfaces(ctx, sandboxID) if err != nil { kataLog.WithField("existing-interfaces", fmt.Sprintf("%+v", interfaces)). @@ -217,7 +216,7 @@ func networkListCommand(ctx context.Context, containerID string, opType networkT } json.NewEncoder(file).Encode(interfaces) case routeType: - var routes []*vcTypes.Route + var routes []*types.Route routes, err = vci.ListRoutes(ctx, sandboxID) if err != nil { kataLog.WithField("resulting-routes", fmt.Sprintf("%+v", routes)). diff --git a/cli/network_test.go b/cli/network_test.go index a4d408d6dd..d95a824265 100644 --- a/cli/network_test.go +++ b/cli/network_test.go @@ -13,25 +13,24 @@ import ( "testing" 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/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" ) var ( - testAddInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { + testAddInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { return nil, nil } - testRemoveInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { + testRemoveInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { return nil, nil } - testListInterfacesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) { + testListInterfacesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*types.Interface, error) { return nil, nil } - testUpdateRoutsFuncReturnNil = func(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { + testUpdateRoutsFuncReturnNil = func(ctx context.Context, sandboxID string, routes []*types.Route) ([]*types.Route, error) { return nil, nil } - testListRoutesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) { + testListRoutesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*types.Route, error) { return nil, nil } ) diff --git a/cli/pause_test.go b/cli/pause_test.go index 2fa1df4be7..d912c9fb97 100644 --- a/cli/pause_test.go +++ b/cli/pause_test.go @@ -13,7 +13,7 @@ import ( "testing" vc "github.com/kata-containers/runtime/virtcontainers" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" ) diff --git a/cli/ps.go b/cli/ps.go index dd2f3c8ca3..df6e26e59c 100644 --- a/cli/ps.go +++ b/cli/ps.go @@ -12,7 +12,7 @@ import ( "github.com/kata-containers/runtime/pkg/katautils" vc "github.com/kata-containers/runtime/virtcontainers" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/sirupsen/logrus" "github.com/urfave/cli" diff --git a/cli/ps_test.go b/cli/ps_test.go index 5a5728533c..91149eb6e2 100644 --- a/cli/ps_test.go +++ b/cli/ps_test.go @@ -13,8 +13,8 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/runtime/virtcontainers/types" "github.com/stretchr/testify/assert" "github.com/urfave/cli" ) diff --git a/cli/update.go b/cli/update.go index edbe5262b2..a6bdc9d8c4 100644 --- a/cli/update.go +++ b/cli/update.go @@ -14,7 +14,7 @@ import ( "github.com/docker/go-units" "github.com/kata-containers/runtime/pkg/katautils" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" diff --git a/cli/update_test.go b/cli/update_test.go index c1d7cf3ca1..a924ed0d10 100644 --- a/cli/update_test.go +++ b/cli/update_test.go @@ -14,8 +14,8 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "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" diff --git a/containerd-shim-v2/delete.go b/containerd-shim-v2/delete.go index 936133b5c9..cd147ed874 100644 --- a/containerd-shim-v2/delete.go +++ b/containerd-shim-v2/delete.go @@ -11,7 +11,7 @@ import ( "github.com/containerd/containerd/mount" "github.com/kata-containers/runtime/pkg/katautils" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/sirupsen/logrus" ) diff --git a/containerd-shim-v2/exec.go b/containerd-shim-v2/exec.go index 1a91461303..28c7dd3aef 100644 --- a/containerd-shim-v2/exec.go +++ b/containerd-shim-v2/exec.go @@ -14,7 +14,7 @@ import ( "github.com/containerd/containerd/api/types/task" "github.com/containerd/containerd/errdefs" googleProtobuf "github.com/gogo/protobuf/types" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" ) diff --git a/containerd-shim-v2/pause_test.go b/containerd-shim-v2/pause_test.go index 212e64e8cd..5b12a55742 100644 --- a/containerd-shim-v2/pause_test.go +++ b/containerd-shim-v2/pause_test.go @@ -14,8 +14,8 @@ import ( taskAPI "github.com/containerd/containerd/runtime/v2/task" vc "github.com/kata-containers/runtime/virtcontainers" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/virtcontainers/pkg/vcmock" - "github.com/kata-containers/runtime/virtcontainers/types" "github.com/stretchr/testify/assert" ) diff --git a/containerd-shim-v2/service.go b/containerd-shim-v2/service.go index 8a36984b49..285ee5c0bd 100644 --- a/containerd-shim-v2/service.go +++ b/containerd-shim-v2/service.go @@ -27,7 +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/kata-containers/runtime/virtcontainers/pkg/types" "github.com/opencontainers/runtime-spec/specs-go" "github.com/containerd/containerd/api/types/task" diff --git a/containerd-shim-v2/utils_test.go b/containerd-shim-v2/utils_test.go index 4ae413ef93..47a69b5871 100644 --- a/containerd-shim-v2/utils_test.go +++ b/containerd-shim-v2/utils_test.go @@ -21,6 +21,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" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) const ( @@ -198,7 +199,7 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf HypervisorConfig: hypervisorConfig, AgentType: vc.KataContainersAgent, ProxyType: vc.KataBuiltInProxyType, - ShimType: vc.KataBuiltInShimType, + ShimType: vshim.KataBuiltInShimType, Console: consolePath, }, nil } diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index 3acaf75d34..a155322d8d 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -17,6 +17,7 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" "github.com/kata-containers/runtime/virtcontainers/device/config" "github.com/kata-containers/runtime/virtcontainers/pkg/oci" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" "github.com/kata-containers/runtime/virtcontainers/utils" "github.com/sirupsen/logrus" ) @@ -28,7 +29,7 @@ const ( var ( defaultProxy = vc.KataProxyType - defaultShim = vc.KataShimType + defaultShim = vshim.KataShimType // if true, enable opentracing support. tracing = false @@ -551,13 +552,13 @@ func newFactoryConfig(f factory) (oci.FactoryConfig, error) { return oci.FactoryConfig{Template: f.Template}, nil } -func newShimConfig(s shim) (vc.ShimConfig, error) { +func newShimConfig(s shim) (vshim.Config, error) { path, err := s.path() if err != nil { - return vc.ShimConfig{}, err + return vshim.Config{}, err } - return vc.ShimConfig{ + return vshim.Config{ Path: path, Debug: s.debug(), Trace: s.trace(), @@ -627,9 +628,9 @@ func updateRuntimeConfigShim(configPath string, tomlConf tomlConfig, config *oci for k, shim := range tomlConf.Shim { switch k { case ccShimTableType: - config.ShimType = vc.CCShimType + config.ShimType = vshim.CCShimType case kataShimTableType: - config.ShimType = vc.KataShimType + config.ShimType = vshim.KataShimType } shConfig, err := newShimConfig(shim) @@ -879,7 +880,7 @@ func updateConfig(configPath string, tomlConf tomlConfig, config *oci.RuntimeCon if builtIn { config.ProxyType = vc.KataBuiltInProxyType - config.ShimType = vc.KataBuiltInShimType + config.ShimType = vshim.KataBuiltInShimType config.AgentType = vc.KataContainersAgent config.AgentConfig = vc.KataAgentConfig{ LongLiveConn: true, @@ -900,7 +901,7 @@ func checkNetNsConfig(config oci.RuntimeConfig) error { if config.InterNetworkModel != vc.NetXConnectNoneModel { return fmt.Errorf("config disable_new_netns only works with 'none' internetworking_model") } - } else if config.ShimConfig.(vc.ShimConfig).Trace { + } else if config.ShimConfig.(vshim.Config).Trace { // Normally, the shim runs in a separate network namespace. // But when tracing, the shim process needs to be able to talk // to the Jaeger agent running in the host network namespace. diff --git a/pkg/katautils/config_test.go b/pkg/katautils/config_test.go index 2f624972bd..f1d124fa3d 100644 --- a/pkg/katautils/config_test.go +++ b/pkg/katautils/config_test.go @@ -22,6 +22,7 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" "github.com/kata-containers/runtime/virtcontainers/pkg/oci" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" "github.com/kata-containers/runtime/virtcontainers/utils" "github.com/stretchr/testify/assert" ) @@ -174,7 +175,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf Path: proxyPath, } - shimConfig := vc.ShimConfig{ + shimConfig := vshim.Config{ Path: shimPath, } @@ -407,7 +408,7 @@ func TestConfigLoadConfigurationFailMissingShim(t *testing.T) { func(config testRuntimeConfig, configFile string, ignoreLogging bool) (bool, error) { expectFail := true - shimConfig, ok := config.RuntimeConfig.ShimConfig.(vc.ShimConfig) + shimConfig, ok := config.RuntimeConfig.ShimConfig.(vshim.Config) if !ok { return expectFail, fmt.Errorf("cannot determine shim config") } @@ -616,7 +617,7 @@ func TestMinimalRuntimeConfig(t *testing.T) { Path: proxyPath, } - expectedShimConfig := vc.ShimConfig{ + expectedShimConfig := vshim.Config{ Path: shimPath, } @@ -1602,7 +1603,7 @@ func TestCheckNetNsConfigShimTrace(t *testing.T) { config := oci.RuntimeConfig{ DisableNewNetNs: d.disableNetNs, InterNetworkModel: d.networkModel, - ShimConfig: vc.ShimConfig{ + ShimConfig: vshim.Config{ Trace: d.shimTrace, }, } diff --git a/pkg/katautils/create.go b/pkg/katautils/create.go index 0e07e8003c..13f0e8fd13 100644 --- a/pkg/katautils/create.go +++ b/pkg/katautils/create.go @@ -13,6 +13,7 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" vf "github.com/kata-containers/runtime/virtcontainers/factory" "github.com/kata-containers/runtime/virtcontainers/pkg/oci" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) // GetKernelParamsFunc use a variable to allow tests to modify its value @@ -98,13 +99,13 @@ func SetEphemeralStorageType(ociSpec oci.CompatOCISpec) oci.CompatOCISpec { // CreateSandbox create a sandbox container func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig, - containerID, bundlePath, console string, disableOutput, systemdCgroup, builtIn bool) (vc.VCSandbox, vc.Process, error) { + containerID, bundlePath, console string, disableOutput, systemdCgroup, builtIn bool) (vc.VCSandbox, types.Process, error) { span, ctx := Trace(ctx, "createSandbox") defer span.Finish() sandboxConfig, err := oci.SandboxConfig(ociSpec, runtimeConfig, bundlePath, containerID, console, disableOutput, systemdCgroup) if err != nil { - return nil, vc.Process{}, err + return nil, types.Process{}, err } if builtIn { @@ -115,7 +116,7 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec oci.CompatOCISpec, ru // created, because it is not responsible for the creation of the // netns if it does not exist. if err := SetupNetworkNamespace(&sandboxConfig.NetworkConfig); err != nil { - return nil, vc.Process{}, err + return nil, types.Process{}, err } // Run pre-start OCI hooks. @@ -123,12 +124,12 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec oci.CompatOCISpec, ru return PreStartHooks(ctx, ociSpec, containerID, bundlePath) }) if err != nil { - return nil, vc.Process{}, err + return nil, types.Process{}, err } sandbox, err := vci.CreateSandbox(ctx, sandboxConfig) if err != nil { - return nil, vc.Process{}, err + return nil, types.Process{}, err } sid := sandbox.ID() @@ -137,13 +138,13 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec oci.CompatOCISpec, ru containers := sandbox.GetAllContainers() if len(containers) != 1 { - return nil, vc.Process{}, fmt.Errorf("BUG: Container list from sandbox is wrong, expecting only one container, found %d containers", len(containers)) + return nil, types.Process{}, fmt.Errorf("BUG: Container list from sandbox is wrong, expecting only one container, found %d containers", len(containers)) } if !builtIn { err = AddContainerIDMapping(ctx, containerID, sandbox.ID()) if err != nil { - return nil, vc.Process{}, err + return nil, types.Process{}, err } } @@ -151,7 +152,7 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec oci.CompatOCISpec, ru } // CreateContainer create a container -func CreateContainer(ctx context.Context, vci vc.VC, sandbox vc.VCSandbox, ociSpec oci.CompatOCISpec, containerID, bundlePath, console string, disableOutput, builtIn bool) (vc.Process, error) { +func CreateContainer(ctx context.Context, vci vc.VC, sandbox vc.VCSandbox, ociSpec oci.CompatOCISpec, containerID, bundlePath, console string, disableOutput, builtIn bool) (types.Process, error) { var c vc.VCContainer span, ctx := Trace(ctx, "createContainer") @@ -161,12 +162,12 @@ func CreateContainer(ctx context.Context, vci vc.VC, sandbox vc.VCSandbox, ociSp contConfig, err := oci.ContainerConfig(ociSpec, bundlePath, containerID, console, disableOutput) if err != nil { - return vc.Process{}, err + return types.Process{}, err } sandboxID, err := ociSpec.SandboxID() if err != nil { - return vc.Process{}, err + return types.Process{}, err } span.SetTag("sandbox", sandboxID) @@ -174,24 +175,24 @@ func CreateContainer(ctx context.Context, vci vc.VC, sandbox vc.VCSandbox, ociSp if builtIn { c, err = sandbox.CreateContainer(contConfig) if err != nil { - return vc.Process{}, err + return types.Process{}, err } } else { kataUtilsLogger = kataUtilsLogger.WithField("sandbox", sandboxID) sandbox, c, err = vci.CreateContainer(ctx, sandboxID, contConfig) if err != nil { - return vc.Process{}, err + return types.Process{}, err } if err := AddContainerIDMapping(ctx, containerID, sandboxID); err != nil { - return vc.Process{}, err + return types.Process{}, err } kataUtilsLogger = kataUtilsLogger.WithField("sandbox", sandboxID) if err := AddContainerIDMapping(ctx, containerID, sandboxID); err != nil { - return vc.Process{}, err + return types.Process{}, err } } @@ -200,7 +201,7 @@ func CreateContainer(ctx context.Context, vci vc.VC, sandbox vc.VCSandbox, ociSp return PreStartHooks(ctx, ociSpec, containerID, bundlePath) }) if err != nil { - return vc.Process{}, err + return types.Process{}, err } return c.Process(), nil diff --git a/pkg/katautils/create_test.go b/pkg/katautils/create_test.go index 77701838e9..15b783cfd6 100644 --- a/pkg/katautils/create_test.go +++ b/pkg/katautils/create_test.go @@ -21,6 +21,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" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" "github.com/opencontainers/runtime-spec/specs-go" "github.com/stretchr/testify/assert" ) @@ -121,7 +122,7 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf HypervisorConfig: hypervisorConfig, AgentType: vc.KataContainersAgent, ProxyType: vc.CCProxyType, - ShimType: vc.CCShimType, + ShimType: vshim.CCShimType, Console: consolePath, }, nil } diff --git a/virtcontainers/agent.go b/virtcontainers/agent.go index cf0c71c504..7736105129 100644 --- a/virtcontainers/agent.go +++ b/virtcontainers/agent.go @@ -11,8 +11,7 @@ import ( "time" "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/kata-containers/runtime/virtcontainers/pkg/types" "github.com/mitchellh/mapstructure" specs "github.com/opencontainers/runtime-spec/specs-go" "golang.org/x/net/context" @@ -161,7 +160,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 types.Cmd) (*Process, error) + exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*types.Process, error) // startSandbox will tell the agent to start all containers related to the Sandbox. startSandbox(sandbox *Sandbox) error @@ -170,7 +169,7 @@ type agent interface { stopSandbox(sandbox *Sandbox) error // createContainer will tell the agent to create a container related to a Sandbox. - createContainer(sandbox *Sandbox, c *Container) (*Process, error) + createContainer(sandbox *Sandbox, c *Container) (*types.Process, error) // startContainer will tell the agent to start a container related to a Sandbox. startContainer(sandbox *Sandbox, c *Container) error @@ -235,16 +234,16 @@ type agent interface { reseedRNG(data []byte) error // updateInterface will tell the agent to update a nic for an existed Sandbox. - updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) + updateInterface(inf *types.Interface) (*types.Interface, error) // listInterfaces will tell the agent to list interfaces of an existed Sandbox - listInterfaces() ([]*vcTypes.Interface, error) + listInterfaces() ([]*types.Interface, error) // updateRoutes will tell the agent to update route table for an existed Sandbox. - updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) + updateRoutes(routes []*types.Route) ([]*types.Route, error) // listRoutes will tell the agent to list routes of an existed Sandbox - listRoutes() ([]*vcTypes.Route, error) + listRoutes() ([]*types.Route, error) // getGuestDetails will tell the agent to get some information of guest getGuestDetails(*grpc.GuestDetailsRequest) (*grpc.GuestDetailsResponse, error) diff --git a/virtcontainers/api.go b/virtcontainers/api.go index 52caeb1d2b..eca2c4ceec 100644 --- a/virtcontainers/api.go +++ b/virtcontainers/api.go @@ -13,8 +13,8 @@ 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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" specs "github.com/opencontainers/runtime-spec/specs-go" opentracing "github.com/opentracing/opentracing-go" "github.com/sirupsen/logrus" @@ -490,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 types.Cmd) (VCSandbox, VCContainer, *Process, error) { +func EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (VCSandbox, VCContainer, *types.Process, error) { span, ctx := trace(ctx, "EnterContainer") defer span.Finish() @@ -575,7 +575,7 @@ func statusContainer(sandbox *Sandbox, containerID string) (ContainerStatus, err container.state.State == types.StatePaused) && container.process.Pid > 0 { - running, err := isShimRunning(container.process.Pid) + running, err := vshim.IsShimRunning(container.process.Pid) if err != nil { return ContainerStatus{}, err } @@ -805,7 +805,7 @@ func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceIn return s.AddDevice(info) } -func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface, add bool) (*vcTypes.Interface, error) { +func toggleInterface(ctx context.Context, sandboxID string, inf *types.Interface, add bool) (*types.Interface, error) { if sandboxID == "" { return nil, errNeedSandboxID } @@ -830,7 +830,7 @@ func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa } // AddInterface is the virtcontainers add interface entry point. -func AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func AddInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { span, ctx := trace(ctx, "AddInterface") defer span.Finish() @@ -838,7 +838,7 @@ func AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) } // RemoveInterface is the virtcontainers remove interface entry point. -func RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func RemoveInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { span, ctx := trace(ctx, "RemoveInterface") defer span.Finish() @@ -846,7 +846,7 @@ func RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa } // ListInterfaces is the virtcontainers list interfaces entry point. -func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) { +func ListInterfaces(ctx context.Context, sandboxID string) ([]*types.Interface, error) { span, ctx := trace(ctx, "ListInterfaces") defer span.Finish() @@ -870,7 +870,7 @@ func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface } // UpdateRoutes is the virtcontainers update routes entry point. -func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func UpdateRoutes(ctx context.Context, sandboxID string, routes []*types.Route) ([]*types.Route, error) { span, ctx := trace(ctx, "UpdateRoutes") defer span.Finish() @@ -894,7 +894,7 @@ func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route } // ListRoutes is the virtcontainers list routes entry point. -func ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) { +func ListRoutes(ctx context.Context, sandboxID string) ([]*types.Route, error) { span, ctx := trace(ctx, "ListRoutes") defer span.Finish() diff --git a/virtcontainers/api_test.go b/virtcontainers/api_test.go index eed59f6801..be08cd5634 100644 --- a/virtcontainers/api_test.go +++ b/virtcontainers/api_test.go @@ -19,8 +19,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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/stretchr/testify/assert" ) @@ -2423,12 +2422,12 @@ func TestNetworkOperation(t *testing.T) { cleanUp() assert := assert.New(t) - inf := &vcTypes.Interface{ + inf := &types.Interface{ Name: "eno1", Mtu: 1500, HwAddr: "02:00:ca:fe:00:48", } - ip := vcTypes.IPAddress{ + ip := types.IPAddress{ Family: 0, Address: "192.168.0.101", Mask: "24", diff --git a/virtcontainers/cc_shim_test.go b/virtcontainers/cc_shim_test.go index 9a1e1045e9..97159003a3 100644 --- a/virtcontainers/cc_shim_test.go +++ b/virtcontainers/cc_shim_test.go @@ -18,6 +18,7 @@ import ( "unsafe" . "github.com/kata-containers/runtime/virtcontainers/pkg/mock" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) // These tests don't care about the format of the container ID @@ -35,10 +36,21 @@ func getMockCCShimBinPath() string { return DefaultMockCCShimBinPath } -func testCCShimStart(t *testing.T, sandbox *Sandbox, params ShimParams, expectFail bool) { - s := &ccShim{} +func testCCShimStart(t *testing.T, sandbox *Sandbox, params vshim.Params, expectFail bool) { + sandboxConfig := sandbox.config + if sandboxConfig == nil { + if !expectFail { + //return -1, fmt.Errorf("Sandbox config cannot be nil") + t.Fatalf("Sandbox config cannot be nil (sandbox %+v, params %+v, expectFail %t)", + sandbox, params, expectFail) + } else { + return + } + } + + s := &vshim.CcShim{} - pid, err := s.start(sandbox, params) + pid, err := s.Start(sandboxConfig.ShimType, sandboxConfig.ShimConfig, params) if expectFail { if err == nil || pid != -1 { t.Fatalf("This test should fail (sandbox %+v, params %+v, expectFail %t)", @@ -58,7 +70,7 @@ func testCCShimStart(t *testing.T, sandbox *Sandbox, params ShimParams, expectFa } func TestCCShimStartNilSandboxConfigFailure(t *testing.T) { - testCCShimStart(t, &Sandbox{}, ShimParams{}, true) + testCCShimStart(t, &Sandbox{}, vshim.Params{}, true) } func TestCCShimStartNilShimConfigFailure(t *testing.T) { @@ -66,55 +78,55 @@ func TestCCShimStartNilShimConfigFailure(t *testing.T) { config: &SandboxConfig{}, } - testCCShimStart(t, sandbox, ShimParams{}, true) + testCCShimStart(t, sandbox, vshim.Params{}, true) } func TestCCShimStartShimPathEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{}, + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{}, }, } - testCCShimStart(t, sandbox, ShimParams{}, true) + testCCShimStart(t, sandbox, vshim.Params{}, true) } func TestCCShimStartShimTypeInvalid(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ ShimType: "foo", - ShimConfig: ShimConfig{}, + ShimConfig: vshim.Config{}, }, } - testCCShimStart(t, sandbox, ShimParams{}, true) + testCCShimStart(t, sandbox, vshim.Params{}, true) } func TestCCShimStartParamsTokenEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{ Path: getMockCCShimBinPath(), }, }, } - testCCShimStart(t, sandbox, ShimParams{}, true) + testCCShimStart(t, sandbox, vshim.Params{}, true) } func TestCCShimStartParamsURLEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{ Path: getMockCCShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", } @@ -124,14 +136,14 @@ func TestCCShimStartParamsURLEmptyFailure(t *testing.T) { func TestCCShimStartParamsContainerEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{ Path: getMockCCShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", URL: "unix://is/awesome", } @@ -150,14 +162,14 @@ func TestCCShimStartParamsInvalidCommand(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{ Path: cmd, }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", URL: "http://foo", } @@ -165,25 +177,25 @@ func TestCCShimStartParamsInvalidCommand(t *testing.T) { testCCShimStart(t, sandbox, params, true) } -func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, *Sandbox, ShimParams, error) { +func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, *Sandbox, vshim.Params, error) { saveStdout := os.Stdout rStdout, wStdout, err := os.Pipe() if err != nil { - return nil, nil, nil, &Sandbox{}, ShimParams{}, err + return nil, nil, nil, &Sandbox{}, vshim.Params{}, err } os.Stdout = wStdout sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{ Path: getMockCCShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Container: testContainer, Token: "testToken", URL: testProxyURL, @@ -262,14 +274,14 @@ func TestCCShimStartDetachSuccessful(t *testing.T) { func TestCCShimStartWithConsoleNonExistingFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{ Path: getMockCCShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", URL: testProxyURL, Console: testWrongConsolePath, @@ -338,14 +350,14 @@ func TestCCShimStartWithConsoleSuccessful(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: CCShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.CCShimType, + ShimConfig: vshim.Config{ Path: getMockCCShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Container: testContainer, Token: "testToken", URL: testProxyURL, diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 5e1cb96575..680c7beb5f 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -17,7 +17,6 @@ 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" @@ -26,6 +25,8 @@ import ( "github.com/kata-containers/runtime/virtcontainers/device/config" "github.com/kata-containers/runtime/virtcontainers/device/manager" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) // https://github.com/torvalds/linux/blob/master/include/uapi/linux/major.h @@ -47,23 +48,6 @@ var cdromMajors = map[int64]string{ 32: "CM206_CDROM_MAJOR", } -// Process gathers data related to a container process. -type Process struct { - // Token is the process execution context ID. It must be - // unique per sandbox. - // Token is used to manipulate processes for containers - // that have not started yet, and later identify them - // uniquely within a sandbox. - Token string - - // Pid is the process ID as seen by the host software - // stack, e.g. CRI-O, containerd. This is typically the - // shim PID. - Pid int - - StartTime time.Time -} - // ContainerStatus describes a container status. type ContainerStatus struct { ID string @@ -276,7 +260,7 @@ type Container struct { state types.State - process Process + process types.Process mounts []Mount @@ -319,7 +303,7 @@ func (c *Container) Sandbox() VCSandbox { } // Process returns the container process. -func (c *Container) Process() Process { +func (c *Container) Process() types.Process { return c.process } @@ -616,7 +600,7 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err configPath: filepath.Join(configStoragePath, sandbox.id, contConfig.ID), containerPath: filepath.Join(sandbox.id, contConfig.ID), state: types.State{}, - process: Process{}, + process: types.Process{}, mounts: contConfig.Mounts, ctx: sandbox.ctx, } @@ -880,10 +864,10 @@ func (c *Container) stop() error { // If shim is still running something went wrong // Make sure we stop the shim process - if running, _ := isShimRunning(c.process.Pid); running { + if running, _ := vshim.IsShimRunning(c.process.Pid); running { l := c.Logger() l.Error("Failed to stop container so stopping dangling shim") - if err := stopShim(c.process.Pid); err != nil { + if err := vshim.StopShim(c.process.Pid); err != nil { l.WithError(err).Warn("failed to stop shim") } } @@ -896,7 +880,7 @@ func (c *Container) stop() error { // However, if the signal didn't reach its goal, the caller still // expects this container to be stopped, that's why we should not // return an error, but instead try to kill it forcefully. - if err := waitForShim(c.process.Pid); err != nil { + if err := vshim.WaitForShim(c.process.Pid); err != nil { // Force the container to be killed. if err := c.kill(syscall.SIGKILL, true); err != nil { return err @@ -906,7 +890,7 @@ func (c *Container) stop() error { // to succeed. Indeed, we have already given a second chance // to the container by trying to kill it with SIGKILL, there // is no reason to try to go further if we got an error. - if err := waitForShim(c.process.Pid); err != nil { + if err := vshim.WaitForShim(c.process.Pid); err != nil { return err } } @@ -942,7 +926,7 @@ func (c *Container) stop() error { return c.setContainerState(types.StateStopped) } -func (c *Container) enter(cmd types.Cmd) (*Process, error) { +func (c *Container) enter(cmd types.Cmd) (*types.Process, error) { if err := c.checkSandboxRunning("enter"); err != nil { return nil, err } diff --git a/virtcontainers/container_test.go b/virtcontainers/container_test.go index 1a0bd7a4fb..718c56a125 100644 --- a/virtcontainers/container_test.go +++ b/virtcontainers/container_test.go @@ -20,7 +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/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" ) diff --git a/virtcontainers/example_pod_run_test.go b/virtcontainers/example_pod_run_test.go index 5b93479079..623ad0b46d 100644 --- a/virtcontainers/example_pod_run_test.go +++ b/virtcontainers/example_pod_run_test.go @@ -11,7 +11,7 @@ import ( "strings" vc "github.com/kata-containers/runtime/virtcontainers" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) const containerRootfs = "/var/lib/container/bundle/" diff --git a/virtcontainers/fc.go b/virtcontainers/fc.go index 203add79de..ff7ee3bbb9 100644 --- a/virtcontainers/fc.go +++ b/virtcontainers/fc.go @@ -21,7 +21,7 @@ import ( "github.com/sirupsen/logrus" "github.com/kata-containers/runtime/virtcontainers/device/config" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "net" "net/http" diff --git a/virtcontainers/filesystem_resource_storage.go b/virtcontainers/filesystem_resource_storage.go index 1cfb3ee568..131f517231 100644 --- a/virtcontainers/filesystem_resource_storage.go +++ b/virtcontainers/filesystem_resource_storage.go @@ -19,7 +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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) // sandboxResource is an int representing a sandbox resource type. @@ -637,7 +637,7 @@ func (fs *filesystem) storeResource(sandboxSpecific bool, sandboxID, containerID case NetworkNamespace: return fs.storeNetworkResource(sandboxSpecific, sandboxID, containerID, resource, file) - case Process: + case types.Process: return fs.storeProcessResource(sandboxSpecific, sandboxID, containerID, resource, file) case []Mount: @@ -808,17 +808,17 @@ func (fs *filesystem) fetchContainerState(sandboxID, containerID string) (types. return state, nil } -func (fs *filesystem) fetchContainerProcess(sandboxID, containerID string) (Process, error) { - var process Process +func (fs *filesystem) fetchContainerProcess(sandboxID, containerID string) (types.Process, error) { + var process types.Process if err := fs.fetchResource(false, sandboxID, containerID, processFileType, &process); err != nil { - return Process{}, err + return types.Process{}, err } return process, nil } -func (fs *filesystem) storeContainerProcess(sandboxID, containerID string, process Process) error { +func (fs *filesystem) storeContainerProcess(sandboxID, containerID string, process types.Process) error { return fs.storeContainerResource(sandboxID, containerID, processFileType, process) } diff --git a/virtcontainers/filesystem_resource_storage_test.go b/virtcontainers/filesystem_resource_storage_test.go index 3e51a845be..3078d5bf31 100644 --- a/virtcontainers/filesystem_resource_storage_test.go +++ b/virtcontainers/filesystem_resource_storage_test.go @@ -15,7 +15,7 @@ import ( "testing" "github.com/kata-containers/runtime/virtcontainers/device/manager" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) func TestFilesystemCreateAllResourcesSuccessful(t *testing.T) { diff --git a/virtcontainers/hack/virtc/main.go b/virtcontainers/hack/virtc/main.go index 7521d90ab2..045e2ea77e 100644 --- a/virtcontainers/hack/virtc/main.go +++ b/virtcontainers/hack/virtc/main.go @@ -14,11 +14,12 @@ 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" vc "github.com/kata-containers/runtime/virtcontainers" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) var virtcLog *logrus.Entry @@ -72,7 +73,7 @@ var sandboxConfigFlags = []cli.Flag{ cli.GenericFlag{ Name: "shim", - Value: new(vc.ShimType), + Value: new(vshim.Type), Usage: "the shim type", }, @@ -160,7 +161,7 @@ func buildSandboxConfig(context *cli.Context) (vc.SandboxConfig, error) { return vc.SandboxConfig{}, fmt.Errorf("Could not convert proxy type") } - shimType, ok := context.Generic("shim").(*vc.ShimType) + shimType, ok := context.Generic("shim").(*vshim.Type) if ok != true { return vc.SandboxConfig{}, fmt.Errorf("Could not convert shim type") } @@ -242,12 +243,12 @@ func getProxyConfig(proxyType vc.ProxyType, path string) vc.ProxyConfig { return proxyConfig } -func getShimConfig(shimType vc.ShimType, path string) interface{} { +func getShimConfig(shimType vshim.Type, path string) interface{} { var shimConfig interface{} switch shimType { - case vc.CCShimType, vc.KataShimType: - shimConfig = vc.ShimConfig{ + case vshim.CCShimType, vshim.KataShimType: + shimConfig = vshim.Config{ Path: path, } diff --git a/virtcontainers/hyperstart_agent.go b/virtcontainers/hyperstart_agent.go index feabc1f5a2..2d53f2f82e 100644 --- a/virtcontainers/hyperstart_agent.go +++ b/virtcontainers/hyperstart_agent.go @@ -22,8 +22,8 @@ import ( "github.com/kata-containers/runtime/virtcontainers/device/config" "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/pkg/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" "github.com/kata-containers/runtime/virtcontainers/utils" specs "github.com/opencontainers/runtime-spec/specs-go" "golang.org/x/net/context" @@ -79,7 +79,7 @@ type HyperAgentState struct { // hyper is the Agent interface implementation for hyperstart. type hyper struct { sandbox *Sandbox - shim shim + shim vshim.Shim proxy proxy client *proxyClient.Client state HyperAgentState @@ -283,7 +283,7 @@ func (h *hyper) init(ctx context.Context, sandbox *Sandbox, config interface{}) return err } - h.shim, err = newShim(sandbox.config.ShimType) + h.shim, err = vshim.NewShim(sandbox.config.ShimType) if err != nil { return err } @@ -340,7 +340,7 @@ func (h *hyper) capabilities() types.Capabilities { } // exec is the agent command execution implementation for hyperstart. -func (h *hyper) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, error) { +func (h *hyper) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*types.Process, error) { token, err := h.attach() if err != nil { return nil, err @@ -367,7 +367,7 @@ func (h *hyper) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, er }, } - process, err := prepareAndStartShim(sandbox, h.shim, c.id, + process, err := vshim.PrepareAndStartShim(sandbox.config.ShimType, sandbox.config.ShimConfig, h.shim, c.id, token, h.state.URL, cmd, []ns.NSType{}, enterNSList) if err != nil { return nil, err @@ -584,7 +584,7 @@ func (h *hyper) startOneContainer(sandbox *Sandbox, c *Container) error { } // createContainer is the agent Container creation implementation for hyperstart. -func (h *hyper) createContainer(sandbox *Sandbox, c *Container) (*Process, error) { +func (h *hyper) createContainer(sandbox *Sandbox, c *Container) (*types.Process, error) { token, err := h.attach() if err != nil { return nil, err @@ -599,7 +599,7 @@ func (h *hyper) createContainer(sandbox *Sandbox, c *Container) (*Process, error }, } - return prepareAndStartShim(sandbox, h.shim, c.id, token, + return vshim.PrepareAndStartShim(sandbox.config.ShimType, sandbox.config.ShimConfig, h.shim, c.id, token, h.state.URL, c.config.Cmd, createNSList, enterNSList) } @@ -650,7 +650,7 @@ func (h *hyper) signalProcess(c *Container, processID string, signal syscall.Sig // Send the signal to the shim directly in case the container has not // been started yet. if c.state.State == types.StateReady { - return signalShim(c.process.Pid, signal) + return vshim.SignalShim(c.process.Pid, signal) } return h.killOneContainer(c.id, signal, all) @@ -891,22 +891,22 @@ func (h *hyper) onlineCPUMem(cpus uint32, cpuOnly bool) error { return nil } -func (h *hyper) updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (h *hyper) updateInterface(inf *types.Interface) (*types.Interface, error) { // hyperstart-agent does not support update interface return nil, nil } -func (h *hyper) listInterfaces() ([]*vcTypes.Interface, error) { +func (h *hyper) listInterfaces() ([]*types.Interface, error) { // hyperstart-agent does not support list interfaces return nil, nil } -func (h *hyper) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func (h *hyper) updateRoutes(routes []*types.Route) ([]*types.Route, error) { // hyperstart-agent does not support update routes return nil, nil } -func (h *hyper) listRoutes() ([]*vcTypes.Route, error) { +func (h *hyper) listRoutes() ([]*types.Route, error) { // hyperstart-agent does not support list routes return nil, nil } diff --git a/virtcontainers/hyperstart_agent_test.go b/virtcontainers/hyperstart_agent_test.go index 6821601bed..83ee7e5b58 100644 --- a/virtcontainers/hyperstart_agent_test.go +++ b/virtcontainers/hyperstart_agent_test.go @@ -13,7 +13,7 @@ import ( "testing" "github.com/kata-containers/runtime/virtcontainers/pkg/hyperstart" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" "github.com/vishvananda/netlink" ) diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index 23cf82343d..2df51a9b6f 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -15,7 +15,7 @@ import ( "strings" "github.com/kata-containers/runtime/virtcontainers/device/config" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) // HypervisorType describes an hypervisor type. diff --git a/virtcontainers/implementation.go b/virtcontainers/implementation.go index 865a84271d..9e532398d5 100644 --- a/virtcontainers/implementation.go +++ b/virtcontainers/implementation.go @@ -15,8 +15,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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" ) @@ -108,7 +107,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 types.Cmd) (VCSandbox, VCContainer, *Process, error) { +func (impl *VCImpl) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (VCSandbox, VCContainer, *types.Process, error) { return EnterContainer(ctx, sandboxID, containerID, cmd) } @@ -153,26 +152,26 @@ func (impl *VCImpl) AddDevice(ctx context.Context, sandboxID string, info config } // AddInterface implements the VC function of the same name. -func (impl *VCImpl) AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (impl *VCImpl) AddInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { return AddInterface(ctx, sandboxID, inf) } // RemoveInterface implements the VC function of the same name. -func (impl *VCImpl) RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (impl *VCImpl) RemoveInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { return RemoveInterface(ctx, sandboxID, inf) } // ListInterfaces implements the VC function of the same name. -func (impl *VCImpl) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) { +func (impl *VCImpl) ListInterfaces(ctx context.Context, sandboxID string) ([]*types.Interface, error) { return ListInterfaces(ctx, sandboxID) } // UpdateRoutes implements the VC function of the same name. -func (impl *VCImpl) UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func (impl *VCImpl) UpdateRoutes(ctx context.Context, sandboxID string, routes []*types.Route) ([]*types.Route, error) { return UpdateRoutes(ctx, sandboxID, routes) } // ListRoutes implements the VC function of the same name. -func (impl *VCImpl) ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) { +func (impl *VCImpl) ListRoutes(ctx context.Context, sandboxID string) ([]*types.Route, error) { return ListRoutes(ctx, sandboxID) } diff --git a/virtcontainers/interfaces.go b/virtcontainers/interfaces.go index d62389d7f0..b1744f5f3f 100644 --- a/virtcontainers/interfaces.go +++ b/virtcontainers/interfaces.go @@ -12,8 +12,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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" ) @@ -36,7 +35,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 types.Cmd) (VCSandbox, VCContainer, *Process, error) + EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (VCSandbox, VCContainer, *types.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) @@ -49,11 +48,11 @@ type VC interface { AddDevice(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error) - AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) - RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) - ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) - UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) - ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) + AddInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) + RemoveInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) + ListInterfaces(ctx context.Context, sandboxID string) ([]*types.Interface, error) + UpdateRoutes(ctx context.Context, sandboxID string, routes []*types.Route) ([]*types.Route, error) + ListRoutes(ctx context.Context, sandboxID string) ([]*types.Route, error) } // VCSandbox is the Sandbox interface @@ -84,7 +83,7 @@ type VCSandbox interface { StatsContainer(containerID string) (ContainerStats, error) PauseContainer(containerID string) error ResumeContainer(containerID string) error - EnterContainer(containerID string, cmd types.Cmd) (VCContainer, *Process, error) + EnterContainer(containerID string, cmd types.Cmd) (VCContainer, *types.Process, error) UpdateContainer(containerID string, resources specs.LinuxResources) error ProcessListContainer(containerID string, options ProcessListOptions) (ProcessList, error) WaitProcess(containerID, processID string) (int32, error) @@ -94,11 +93,11 @@ type VCSandbox interface { AddDevice(info config.DeviceInfo) (api.Device, error) - AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) - RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) - ListInterfaces() ([]*vcTypes.Interface, error) - UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) - ListRoutes() ([]*vcTypes.Route, error) + AddInterface(inf *types.Interface) (*types.Interface, error) + RemoveInterface(inf *types.Interface) (*types.Interface, error) + ListInterfaces() ([]*types.Interface, error) + UpdateRoutes(routes []*types.Route) ([]*types.Route, error) + ListRoutes() ([]*types.Route, error) } // VCContainer is the Container interface @@ -109,6 +108,6 @@ type VCContainer interface { GetToken() string ID() string Sandbox() VCSandbox - Process() Process + Process() types.Process SetPid(pid int) error } diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 3f0abc423f..a40733408d 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -25,9 +25,9 @@ import ( "github.com/kata-containers/runtime/virtcontainers/device/config" vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" 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/types" "github.com/kata-containers/runtime/virtcontainers/pkg/uuid" - "github.com/kata-containers/runtime/virtcontainers/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" "github.com/kata-containers/runtime/virtcontainers/utils" opentracing "github.com/opentracing/opentracing-go" @@ -96,7 +96,7 @@ type KataAgentState struct { } type kataAgent struct { - shim shim + shim vshim.Shim proxy proxy // lock protects the client pointer @@ -185,7 +185,7 @@ func (k *kataAgent) init(ctx context.Context, sandbox *Sandbox, config interface return err } - k.shim, err = newShim(sandbox.config.ShimType) + k.shim, err = vshim.NewShim(sandbox.config.ShimType) if err != nil { return err } @@ -363,7 +363,7 @@ func cmdEnvsToStringSlice(ev []types.EnvVar) []string { return env } -func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process, error) { +func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*types.Process, error) { span, _ := k.trace("exec") defer span.Finish() @@ -395,11 +395,11 @@ func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process }, } - return prepareAndStartShim(sandbox, k.shim, c.id, req.ExecId, + return vshim.PrepareAndStartShim(sandbox.config.ShimType, sandbox.config.ShimConfig, k.shim, c.id, req.ExecId, k.state.URL, cmd, []ns.NSType{}, enterNSList) } -func (k *kataAgent) updateInterface(ifc *vcTypes.Interface) (*vcTypes.Interface, error) { +func (k *kataAgent) updateInterface(ifc *types.Interface) (*types.Interface, error) { // send update interface request ifcReq := &grpc.UpdateInterfaceRequest{ Interface: k.convertToKataAgentInterface(ifc), @@ -411,13 +411,13 @@ func (k *kataAgent) updateInterface(ifc *vcTypes.Interface) (*vcTypes.Interface, "resulting-interface": fmt.Sprintf("%+v", resultingInterface), }).WithError(err).Error("update interface request failed") } - if resultInterface, ok := resultingInterface.(*vcTypes.Interface); ok { + if resultInterface, ok := resultingInterface.(*types.Interface); ok { return resultInterface, err } return nil, err } -func (k *kataAgent) updateInterfaces(interfaces []*vcTypes.Interface) error { +func (k *kataAgent) updateInterfaces(interfaces []*types.Interface) error { for _, ifc := range interfaces { if _, err := k.updateInterface(ifc); err != nil { return err @@ -426,7 +426,7 @@ func (k *kataAgent) updateInterfaces(interfaces []*vcTypes.Interface) error { return nil } -func (k *kataAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func (k *kataAgent) updateRoutes(routes []*types.Route) ([]*types.Route, error) { if routes != nil { routesReq := &grpc.UpdateRoutesRequest{ Routes: &grpc.Routes{ @@ -449,7 +449,7 @@ func (k *kataAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, err return nil, nil } -func (k *kataAgent) listInterfaces() ([]*vcTypes.Interface, error) { +func (k *kataAgent) listInterfaces() ([]*types.Interface, error) { req := &grpc.ListInterfacesRequest{} resultingInterfaces, err := k.sendReq(req) if err != nil { @@ -462,7 +462,7 @@ func (k *kataAgent) listInterfaces() ([]*vcTypes.Interface, error) { return nil, err } -func (k *kataAgent) listRoutes() ([]*vcTypes.Route, error) { +func (k *kataAgent) listRoutes() ([]*types.Route, error) { req := &grpc.ListRoutesRequest{} resultingRoutes, err := k.sendReq(req) if err != nil { @@ -970,7 +970,8 @@ func (k *kataAgent) buildContainerRootfs(sandbox *Sandbox, c *Container, rootPat return nil, nil } -func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process, err error) { +func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *types. + Process, err error) { span, _ := k.trace("createContainer") defer span.Finish() @@ -1088,7 +1089,7 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process, }) } - return prepareAndStartShim(sandbox, k.shim, c.id, req.ExecId, + return vshim.PrepareAndStartShim(sandbox.config.ShimType, sandbox.config.ShimConfig, k.shim, c.id, req.ExecId, k.state.URL, c.config.Cmd, createNSList, enterNSList) } @@ -1665,7 +1666,7 @@ func (k *kataAgent) convertToIPFamily(ipFamily aTypes.IPFamily) int { return netlink.FAMILY_V4 } -func (k *kataAgent) convertToKataAgentIPAddresses(ipAddrs []*vcTypes.IPAddress) (aIPAddrs []*aTypes.IPAddress) { +func (k *kataAgent) convertToKataAgentIPAddresses(ipAddrs []*types.IPAddress) (aIPAddrs []*aTypes.IPAddress) { for _, ipAddr := range ipAddrs { if ipAddr == nil { continue @@ -1683,13 +1684,13 @@ func (k *kataAgent) convertToKataAgentIPAddresses(ipAddrs []*vcTypes.IPAddress) return aIPAddrs } -func (k *kataAgent) convertToIPAddresses(aIPAddrs []*aTypes.IPAddress) (ipAddrs []*vcTypes.IPAddress) { +func (k *kataAgent) convertToIPAddresses(aIPAddrs []*aTypes.IPAddress) (ipAddrs []*types.IPAddress) { for _, aIPAddr := range aIPAddrs { if aIPAddr == nil { continue } - ipAddr := &vcTypes.IPAddress{ + ipAddr := &types.IPAddress{ Family: k.convertToIPFamily(aIPAddr.Family), Address: aIPAddr.Address, Mask: aIPAddr.Mask, @@ -1701,7 +1702,7 @@ func (k *kataAgent) convertToIPAddresses(aIPAddrs []*aTypes.IPAddress) (ipAddrs return ipAddrs } -func (k *kataAgent) convertToKataAgentInterface(iface *vcTypes.Interface) *aTypes.Interface { +func (k *kataAgent) convertToKataAgentInterface(iface *types.Interface) *aTypes.Interface { if iface == nil { return nil } @@ -1716,13 +1717,13 @@ func (k *kataAgent) convertToKataAgentInterface(iface *vcTypes.Interface) *aType } } -func (k *kataAgent) convertToInterfaces(aIfaces []*aTypes.Interface) (ifaces []*vcTypes.Interface) { +func (k *kataAgent) convertToInterfaces(aIfaces []*aTypes.Interface) (ifaces []*types.Interface) { for _, aIface := range aIfaces { if aIface == nil { continue } - iface := &vcTypes.Interface{ + iface := &types.Interface{ Device: aIface.Device, Name: aIface.Name, IPAddresses: k.convertToIPAddresses(aIface.IPAddresses), @@ -1737,7 +1738,7 @@ func (k *kataAgent) convertToInterfaces(aIfaces []*aTypes.Interface) (ifaces []* return ifaces } -func (k *kataAgent) convertToKataAgentRoutes(routes []*vcTypes.Route) (aRoutes []*aTypes.Route) { +func (k *kataAgent) convertToKataAgentRoutes(routes []*types.Route) (aRoutes []*aTypes.Route) { for _, route := range routes { if route == nil { continue @@ -1757,13 +1758,13 @@ func (k *kataAgent) convertToKataAgentRoutes(routes []*vcTypes.Route) (aRoutes [ return aRoutes } -func (k *kataAgent) convertToRoutes(aRoutes []*aTypes.Route) (routes []*vcTypes.Route) { +func (k *kataAgent) convertToRoutes(aRoutes []*aTypes.Route) (routes []*types.Route) { for _, aRoute := range aRoutes { if aRoute == nil { continue } - route := &vcTypes.Route{ + route := &types.Route{ Dest: aRoute.Dest, Gateway: aRoute.Gateway, Device: aRoute.Device, diff --git a/virtcontainers/kata_agent_test.go b/virtcontainers/kata_agent_test.go index 5ea995a3a3..311c74e3eb 100644 --- a/virtcontainers/kata_agent_test.go +++ b/virtcontainers/kata_agent_test.go @@ -31,8 +31,7 @@ import ( "github.com/kata-containers/runtime/virtcontainers/device/manager" 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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) var ( @@ -818,7 +817,7 @@ func TestAgentNetworkOperation(t *testing.T) { _, err = k.listInterfaces() assert.Nil(err) - _, err = k.updateRoutes([]*vcTypes.Route{}) + _, err = k.updateRoutes([]*types.Route{}) assert.Nil(err) _, err = k.listRoutes() diff --git a/virtcontainers/kata_builtin_shim.go b/virtcontainers/kata_builtin_shim.go deleted file mode 100644 index a51da030f2..0000000000 --- a/virtcontainers/kata_builtin_shim.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2018 HyperHQ Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// - -package virtcontainers - -type kataBuiltInShim struct{} - -// start is the kataBuiltInShim start implementation for kata builtin shim. -// It does nothing. The shim functionality is provided by the virtcontainers -// library. -func (s *kataBuiltInShim) start(sandbox *Sandbox, params ShimParams) (int, error) { - return -1, nil -} diff --git a/virtcontainers/kata_shim_test.go b/virtcontainers/kata_shim_test.go index f0f16e448f..12296b1689 100644 --- a/virtcontainers/kata_shim_test.go +++ b/virtcontainers/kata_shim_test.go @@ -16,6 +16,7 @@ import ( "time" . "github.com/kata-containers/runtime/virtcontainers/pkg/mock" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) var testKataShimPath = "/usr/bin/virtcontainers/bin/test/kata-shim" @@ -29,10 +30,20 @@ func getMockKataShimBinPath() string { return DefaultMockKataShimBinPath } -func testKataShimStart(t *testing.T, sandbox *Sandbox, params ShimParams, expectFail bool) { - s := &kataShim{} +func testKataShimStart(t *testing.T, sandbox *Sandbox, params vshim.Params, expectFail bool) { + s := &vshim.KataShim{} + sandboxConfig := sandbox.config + if sandboxConfig == nil { + if !expectFail { + //return -1, fmt.Errorf("Sandbox config cannot be nil") + t.Fatalf("Sandbox config cannot be nil (sandbox %+v, params %+v, expectFail %t)", + sandbox, params, expectFail) + } else { + return + } + } - pid, err := s.start(sandbox, params) + pid, err := s.Start(sandboxConfig.ShimType, sandboxConfig.ShimConfig, params) if expectFail { if err == nil || pid != -1 { t.Fatalf("This test should fail (sandbox %+v, params %+v, expectFail %t)", @@ -52,7 +63,7 @@ func testKataShimStart(t *testing.T, sandbox *Sandbox, params ShimParams, expect } func TestKataShimStartNilSandboxConfigFailure(t *testing.T) { - testKataShimStart(t, &Sandbox{}, ShimParams{}, true) + testKataShimStart(t, &Sandbox{}, vshim.Params{}, true) } func TestKataShimStartNilShimConfigFailure(t *testing.T) { @@ -60,55 +71,55 @@ func TestKataShimStartNilShimConfigFailure(t *testing.T) { config: &SandboxConfig{}, } - testKataShimStart(t, sandbox, ShimParams{}, true) + testKataShimStart(t, sandbox, vshim.Params{}, true) } func TestKataShimStartShimPathEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{}, + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{}, }, } - testKataShimStart(t, sandbox, ShimParams{}, true) + testKataShimStart(t, sandbox, vshim.Params{}, true) } func TestKataShimStartShimTypeInvalid(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ ShimType: "foo", - ShimConfig: ShimConfig{}, + ShimConfig: vshim.Config{}, }, } - testKataShimStart(t, sandbox, ShimParams{}, true) + testKataShimStart(t, sandbox, vshim.Params{}, true) } func TestKataShimStartParamsTokenEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{ Path: getMockKataShimBinPath(), }, }, } - testKataShimStart(t, sandbox, ShimParams{}, true) + testKataShimStart(t, sandbox, vshim.Params{}, true) } func TestKataShimStartParamsURLEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{ Path: getMockKataShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", } @@ -118,14 +129,14 @@ func TestKataShimStartParamsURLEmptyFailure(t *testing.T) { func TestKataShimStartParamsContainerEmptyFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{ Path: getMockKataShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", URL: "unix://is/awesome", } @@ -144,14 +155,14 @@ func TestKataShimStartParamsInvalidCommand(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{ Path: cmd, }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", URL: "http://foo", } @@ -159,25 +170,25 @@ func TestKataShimStartParamsInvalidCommand(t *testing.T) { testKataShimStart(t, sandbox, params, true) } -func startKataShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, *Sandbox, ShimParams, error) { +func startKataShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, *Sandbox, vshim.Params, error) { saveStdout := os.Stdout rStdout, wStdout, err := os.Pipe() if err != nil { - return nil, nil, nil, &Sandbox{}, ShimParams{}, err + return nil, nil, nil, &Sandbox{}, vshim.Params{}, err } os.Stdout = wStdout sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{ Path: getMockKataShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Container: testContainer, Token: "testToken", URL: testKataShimProxyURL, @@ -256,14 +267,14 @@ func TestKataShimStartDetachSuccessful(t *testing.T) { func TestKataShimStartWithConsoleNonExistingFailure(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{ Path: getMockKataShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Token: "testToken", URL: testKataShimProxyURL, Console: testWrongConsolePath, @@ -284,14 +295,14 @@ func TestKataShimStartWithConsoleSuccessful(t *testing.T) { sandbox := &Sandbox{ config: &SandboxConfig{ - ShimType: KataShimType, - ShimConfig: ShimConfig{ + ShimType: vshim.KataShimType, + ShimConfig: vshim.Config{ Path: getMockKataShimBinPath(), }, }, } - params := ShimParams{ + params := vshim.Params{ Container: testContainer, Token: "testToken", URL: testKataShimProxyURL, diff --git a/virtcontainers/mock_hypervisor.go b/virtcontainers/mock_hypervisor.go index 1146c6f746..5e798897a4 100644 --- a/virtcontainers/mock_hypervisor.go +++ b/virtcontainers/mock_hypervisor.go @@ -9,7 +9,7 @@ import ( "context" "os" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) type mockHypervisor struct { diff --git a/virtcontainers/noop_agent.go b/virtcontainers/noop_agent.go index 1783454b93..8114e5b320 100644 --- a/virtcontainers/noop_agent.go +++ b/virtcontainers/noop_agent.go @@ -10,8 +10,7 @@ import ( "time" "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/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" "golang.org/x/net/context" ) @@ -47,7 +46,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 types.Cmd) (*Process, error) { +func (n *noopAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*types.Process, error) { return nil, nil } @@ -62,8 +61,8 @@ func (n *noopAgent) stopSandbox(sandbox *Sandbox) error { } // createContainer is the Noop agent Container creation implementation. It does nothing. -func (n *noopAgent) createContainer(sandbox *Sandbox, c *Container) (*Process, error) { - return &Process{}, nil +func (n *noopAgent) createContainer(sandbox *Sandbox, c *Container) (*types.Process, error) { + return &types.Process{}, nil } // startContainer is the Noop agent Container starting implementation. It does nothing. @@ -97,22 +96,22 @@ func (n *noopAgent) onlineCPUMem(cpus uint32, cpuOnly bool) error { } // updateInterface is the Noop agent Interface update implementation. It does nothing. -func (n *noopAgent) updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (n *noopAgent) updateInterface(inf *types.Interface) (*types.Interface, error) { return nil, nil } // listInterfaces is the Noop agent Interfaces list implementation. It does nothing. -func (n *noopAgent) listInterfaces() ([]*vcTypes.Interface, error) { +func (n *noopAgent) listInterfaces() ([]*types.Interface, error) { return nil, nil } // updateRoutes is the Noop agent Routes update implementation. It does nothing. -func (n *noopAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func (n *noopAgent) updateRoutes(routes []*types.Route) ([]*types.Route, error) { return nil, nil } // listRoutes is the Noop agent Routes list implementation. It does nothing. -func (n *noopAgent) listRoutes() ([]*vcTypes.Route, error) { +func (n *noopAgent) listRoutes() ([]*types.Route, error) { return nil, nil } diff --git a/virtcontainers/noop_agent_test.go b/virtcontainers/noop_agent_test.go index 9018c700d7..1e75cf401f 100644 --- a/virtcontainers/noop_agent_test.go +++ b/virtcontainers/noop_agent_test.go @@ -10,7 +10,7 @@ import ( "context" "testing" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" ) diff --git a/virtcontainers/noop_resource_storage.go b/virtcontainers/noop_resource_storage.go index 89db7c7faf..67108eb405 100644 --- a/virtcontainers/noop_resource_storage.go +++ b/virtcontainers/noop_resource_storage.go @@ -7,7 +7,7 @@ package virtcontainers import ( "github.com/kata-containers/runtime/virtcontainers/device/api" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) type noopResourceStorage struct{} @@ -88,11 +88,11 @@ func (n *noopResourceStorage) fetchContainerState(sandboxID, containerID string) return types.State{}, nil } -func (n *noopResourceStorage) fetchContainerProcess(sandboxID, containerID string) (Process, error) { - return Process{}, nil +func (n *noopResourceStorage) fetchContainerProcess(sandboxID, containerID string) (types.Process, error) { + return types.Process{}, nil } -func (n *noopResourceStorage) storeContainerProcess(sandboxID, containerID string, process Process) error { +func (n *noopResourceStorage) storeContainerProcess(sandboxID, containerID string, process types.Process) error { return nil } diff --git a/virtcontainers/noop_resource_storage_test.go b/virtcontainers/noop_resource_storage_test.go index 1e4a696bf6..7223cd781b 100644 --- a/virtcontainers/noop_resource_storage_test.go +++ b/virtcontainers/noop_resource_storage_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/kata-containers/runtime/virtcontainers/device/api" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" ) @@ -155,7 +156,7 @@ func TestNoopFetchContainerProcess(t *testing.T) { func TestNoopStoreContainerProcess(t *testing.T) { n := &noopResourceStorage{} - err := n.storeContainerProcess("", "", Process{}) + err := n.storeContainerProcess("", "", types.Process{}) assert.Nil(t, err) } diff --git a/virtcontainers/noop_shim.go b/virtcontainers/noop_shim.go deleted file mode 100644 index e700c07c1f..0000000000 --- a/virtcontainers/noop_shim.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2017 Intel Corporation -// -// SPDX-License-Identifier: Apache-2.0 -// - -package virtcontainers - -type noopShim struct{} - -// start is the noopShim start implementation for testing purpose. -// It does nothing. -func (s *noopShim) start(sandbox *Sandbox, params ShimParams) (int, error) { - return 0, nil -} diff --git a/virtcontainers/noop_shim_test.go b/virtcontainers/noop_shim_test.go index 8fd031c1a2..923025bc0a 100644 --- a/virtcontainers/noop_shim_test.go +++ b/virtcontainers/noop_shim_test.go @@ -7,15 +7,22 @@ package virtcontainers import ( "testing" + + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) func TestNoopShimStart(t *testing.T) { - s := &noopShim{} - sandbox := &Sandbox{} - params := ShimParams{} + s := &vshim.NoopShim{} + sandbox := &Sandbox{ + config: &SandboxConfig{ + ShimType: vshim.NoopShimType, + ShimConfig: vshim.Config{}, + }, + } + params := vshim.Params{} expected := 0 - pid, err := s.start(sandbox, params) + pid, err := s.Start(sandbox.config.ShimType, sandbox.config.ShimConfig, params) if err != nil { t.Fatal(err) } diff --git a/virtcontainers/pkg/oci/utils.go b/virtcontainers/pkg/oci/utils.go index 02d86f7e98..61ec6084fe 100644 --- a/virtcontainers/pkg/oci/utils.go +++ b/virtcontainers/pkg/oci/utils.go @@ -25,7 +25,8 @@ 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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) type annotationContainerType struct { @@ -111,7 +112,7 @@ type RuntimeConfig struct { ProxyType vc.ProxyType ProxyConfig vc.ProxyConfig - ShimType vc.ShimType + ShimType vshim.Type ShimConfig interface{} Console string diff --git a/virtcontainers/pkg/oci/utils_test.go b/virtcontainers/pkg/oci/utils_test.go index db7a33cb0b..eb39d50a0c 100644 --- a/virtcontainers/pkg/oci/utils_test.go +++ b/virtcontainers/pkg/oci/utils_test.go @@ -24,7 +24,8 @@ 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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) const ( @@ -109,7 +110,7 @@ func TestMinimalSandboxConfig(t *testing.T) { HypervisorType: vc.QemuHypervisor, AgentType: vc.HyperstartAgent, ProxyType: vc.CCProxyType, - ShimType: vc.CCShimType, + ShimType: vshim.CCShimType, Console: consolePath, } @@ -224,7 +225,7 @@ func TestMinimalSandboxConfig(t *testing.T) { HypervisorType: vc.QemuHypervisor, AgentType: vc.HyperstartAgent, ProxyType: vc.CCProxyType, - ShimType: vc.CCShimType, + ShimType: vshim.CCShimType, NetworkModel: vc.DefaultNetworkModel, NetworkConfig: expectedNetworkConfig, diff --git a/virtcontainers/types/asset.go b/virtcontainers/pkg/types/asset.go similarity index 100% rename from virtcontainers/types/asset.go rename to virtcontainers/pkg/types/asset.go diff --git a/virtcontainers/types/asset_test.go b/virtcontainers/pkg/types/asset_test.go similarity index 100% rename from virtcontainers/types/asset_test.go rename to virtcontainers/pkg/types/asset_test.go diff --git a/virtcontainers/types/capabilities.go b/virtcontainers/pkg/types/capabilities.go similarity index 100% rename from virtcontainers/types/capabilities.go rename to virtcontainers/pkg/types/capabilities.go diff --git a/virtcontainers/types/capabilities_test.go b/virtcontainers/pkg/types/capabilities_test.go similarity index 100% rename from virtcontainers/types/capabilities_test.go rename to virtcontainers/pkg/types/capabilities_test.go diff --git a/virtcontainers/pkg/types/container.go b/virtcontainers/pkg/types/container.go new file mode 100644 index 0000000000..e5b290ff01 --- /dev/null +++ b/virtcontainers/pkg/types/container.go @@ -0,0 +1,27 @@ +// Copyright 2018 Intel Corporation. +// +// SPDX-License-Identifier: Apache-2.0 +// + +package types + +import ( + "time" +) + +// Process gathers data related to a container process. +type Process struct { + // Token is the process execution context ID. It must be + // unique per sandbox. + // Token is used to manipulate processes for containers + // that have not started yet, and later identify them + // uniquely within a sandbox. + Token string + + // Pid is the process ID as seen by the host software + // stack, e.g. CRI-O, containerd. This is typically the + // shim PID. + Pid int + + StartTime time.Time +} diff --git a/virtcontainers/types/pci.go b/virtcontainers/pkg/types/pci.go similarity index 100% rename from virtcontainers/types/pci.go rename to virtcontainers/pkg/types/pci.go diff --git a/virtcontainers/types/pci_test.go b/virtcontainers/pkg/types/pci_test.go similarity index 100% rename from virtcontainers/types/pci_test.go rename to virtcontainers/pkg/types/pci_test.go diff --git a/virtcontainers/types/sandbox.go b/virtcontainers/pkg/types/sandbox.go similarity index 100% rename from virtcontainers/types/sandbox.go rename to virtcontainers/pkg/types/sandbox.go diff --git a/virtcontainers/pkg/vcmock/container.go b/virtcontainers/pkg/vcmock/container.go index d93c271811..7f02d04617 100644 --- a/virtcontainers/pkg/vcmock/container.go +++ b/virtcontainers/pkg/vcmock/container.go @@ -7,6 +7,7 @@ package vcmock import ( vc "github.com/kata-containers/runtime/virtcontainers" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) // ID implements the VCContainer function of the same name. @@ -20,7 +21,7 @@ func (c *Container) Sandbox() vc.VCSandbox { } // Process implements the VCContainer function of the same name. -func (c *Container) Process() vc.Process { +func (c *Container) Process() types.Process { // always return a mockprocess with a non-zero Pid if c.MockProcess.Pid == 0 { c.MockProcess.Pid = 1000 diff --git a/virtcontainers/pkg/vcmock/mock.go b/virtcontainers/pkg/vcmock/mock.go index b2455850fb..3d813a0edc 100644 --- a/virtcontainers/pkg/vcmock/mock.go +++ b/virtcontainers/pkg/vcmock/mock.go @@ -23,8 +23,7 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" "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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" ) @@ -174,7 +173,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 types.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, *types.Process, error) { if m.EnterContainerFunc != nil { return m.EnterContainerFunc(ctx, sandboxID, containerID, cmd) } @@ -255,7 +254,7 @@ func (m *VCMock) AddDevice(ctx context.Context, sandboxID string, info config.De } // AddInterface implements the VC function of the same name. -func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { if m.AddInterfaceFunc != nil { return m.AddInterfaceFunc(ctx, sandboxID, inf) } @@ -264,7 +263,7 @@ func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *vcType } // RemoveInterface implements the VC function of the same name. -func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) { if m.RemoveInterfaceFunc != nil { return m.RemoveInterfaceFunc(ctx, sandboxID, inf) } @@ -273,7 +272,7 @@ func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *vcT } // ListInterfaces implements the VC function of the same name. -func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) { +func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*types.Interface, error) { if m.ListInterfacesFunc != nil { return m.ListInterfacesFunc(ctx, sandboxID) } @@ -282,7 +281,7 @@ func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTyp } // UpdateRoutes implements the VC function of the same name. -func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*types.Route) ([]*types.Route, error) { if m.UpdateRoutesFunc != nil { return m.UpdateRoutesFunc(ctx, sandboxID, routes) } @@ -291,7 +290,7 @@ func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*v } // ListRoutes implements the VC function of the same name. -func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) { +func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*types.Route, error) { if m.ListRoutesFunc != nil { return m.ListRoutesFunc(ctx, sandboxID) } diff --git a/virtcontainers/pkg/vcmock/mock_test.go b/virtcontainers/pkg/vcmock/mock_test.go index d369e6574a..4dd1eada0f 100644 --- a/virtcontainers/pkg/vcmock/mock_test.go +++ b/virtcontainers/pkg/vcmock/mock_test.go @@ -13,8 +13,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/kata-containers/runtime/virtcontainers/pkg/types" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) @@ -427,15 +426,15 @@ func TestVCMockEnterContainer(t *testing.T) { assert.Error(err) assert.True(IsMockError(err)) - 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 + m.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *types.Process, error) { + return &Sandbox{}, &Container{}, &types.Process{}, nil } sandbox, container, process, err := m.EnterContainer(ctx, testSandboxID, testContainerID, cmd) assert.NoError(err) assert.Equal(sandbox, &Sandbox{}) assert.Equal(container, &Container{}) - assert.Equal(process, &vc.Process{}) + assert.Equal(process, &types.Process{}) // reset m.EnterContainerFunc = nil @@ -749,7 +748,7 @@ func TestVCMockAddInterface(t *testing.T) { assert.Error(err) assert.True(IsMockError(err)) - m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { + m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *types.Interface) (*types.Interface, error) { return nil, nil } @@ -776,7 +775,7 @@ func TestVCMockRemoveInterface(t *testing.T) { assert.Error(err) assert.True(IsMockError(err)) - m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { + m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *types.Interface) (*types.Interface, error) { return nil, nil } @@ -803,7 +802,7 @@ func TestVCMockListInterfaces(t *testing.T) { assert.Error(err) assert.True(IsMockError(err)) - m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*vcTypes.Interface, error) { + m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*types.Interface, error) { return nil, nil } @@ -830,7 +829,7 @@ func TestVCMockUpdateRoutes(t *testing.T) { assert.Error(err) assert.True(IsMockError(err)) - m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { + m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*types.Route) ([]*types.Route, error) { return nil, nil } @@ -857,7 +856,7 @@ func TestVCMockListRoutes(t *testing.T) { assert.Error(err) assert.True(IsMockError(err)) - m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*vcTypes.Route, error) { + m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*types.Route, error) { return nil, nil } diff --git a/virtcontainers/pkg/vcmock/sandbox.go b/virtcontainers/pkg/vcmock/sandbox.go index 2c00d23f82..cabdd73559 100644 --- a/virtcontainers/pkg/vcmock/sandbox.go +++ b/virtcontainers/pkg/vcmock/sandbox.go @@ -12,8 +12,7 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" "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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" ) @@ -144,8 +143,8 @@ func (s *Sandbox) Status() vc.SandboxStatus { } // EnterContainer implements the VCSandbox function of the same name. -func (s *Sandbox) EnterContainer(containerID string, cmd types.Cmd) (vc.VCContainer, *vc.Process, error) { - return &Container{}, &vc.Process{}, nil +func (s *Sandbox) EnterContainer(containerID string, cmd types.Cmd) (vc.VCContainer, *types.Process, error) { + return &Container{}, &types.Process{}, nil } // Monitor implements the VCSandbox function of the same name. @@ -189,26 +188,26 @@ func (s *Sandbox) AddDevice(info config.DeviceInfo) (api.Device, error) { } // AddInterface implements the VCSandbox function of the same name. -func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (s *Sandbox) AddInterface(inf *types.Interface) (*types.Interface, error) { return nil, nil } // RemoveInterface implements the VCSandbox function of the same name. -func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (s *Sandbox) RemoveInterface(inf *types.Interface) (*types.Interface, error) { return nil, nil } // ListInterfaces implements the VCSandbox function of the same name. -func (s *Sandbox) ListInterfaces() ([]*vcTypes.Interface, error) { +func (s *Sandbox) ListInterfaces() ([]*types.Interface, error) { return nil, nil } // UpdateRoutes implements the VCSandbox function of the same name. -func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func (s *Sandbox) UpdateRoutes(routes []*types.Route) ([]*types.Route, error) { return nil, nil } // ListRoutes implements the VCSandbox function of the same name. -func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) { +func (s *Sandbox) ListRoutes() ([]*types.Route, error) { return nil, nil } diff --git a/virtcontainers/pkg/vcmock/types.go b/virtcontainers/pkg/vcmock/types.go index 6f7df5a3d8..9f942d3e9c 100644 --- a/virtcontainers/pkg/vcmock/types.go +++ b/virtcontainers/pkg/vcmock/types.go @@ -12,8 +12,7 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" "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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" ) @@ -32,7 +31,7 @@ type Container struct { MockID string MockURL string MockToken string - MockProcess vc.Process + MockProcess types.Process MockPid int MockSandbox *Sandbox MockAnnotations map[string]string @@ -58,7 +57,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 types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) + EnterContainerFunc func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *types.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) @@ -70,9 +69,9 @@ type VCMock struct { AddDeviceFunc func(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error) - AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) - RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) - ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) - UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) - ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) + AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) + RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) + ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*types.Interface, error) + UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*types.Route) ([]*types.Route, error) + ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*types.Route, error) } diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 65419a83ed..d12b09a002 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -22,7 +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/pkg/types" "github.com/kata-containers/runtime/virtcontainers/utils" "golang.org/x/sys/unix" ) diff --git a/virtcontainers/qemu_amd64.go b/virtcontainers/qemu_amd64.go index 65d9838e44..529698007e 100644 --- a/virtcontainers/qemu_amd64.go +++ b/virtcontainers/qemu_amd64.go @@ -8,7 +8,7 @@ package virtcontainers import ( "os" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" govmmQemu "github.com/intel/govmm/qemu" ) diff --git a/virtcontainers/qemu_amd64_test.go b/virtcontainers/qemu_amd64_test.go index 31e42341ad..198e5c9efd 100644 --- a/virtcontainers/qemu_amd64_test.go +++ b/virtcontainers/qemu_amd64_test.go @@ -12,7 +12,7 @@ import ( "testing" govmmQemu "github.com/intel/govmm/qemu" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" ) diff --git a/virtcontainers/qemu_arch_base.go b/virtcontainers/qemu_arch_base.go index 5e68bfd292..070eeb91c0 100644 --- a/virtcontainers/qemu_arch_base.go +++ b/virtcontainers/qemu_arch_base.go @@ -14,7 +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/pkg/types" "github.com/kata-containers/runtime/virtcontainers/utils" ) diff --git a/virtcontainers/qemu_arch_base_test.go b/virtcontainers/qemu_arch_base_test.go index 7dac7dc59f..297904736e 100644 --- a/virtcontainers/qemu_arch_base_test.go +++ b/virtcontainers/qemu_arch_base_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/kata-containers/runtime/virtcontainers/device/config" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) const ( diff --git a/virtcontainers/qemu_ppc64le.go b/virtcontainers/qemu_ppc64le.go index e9be4b485d..3ed9e5022a 100644 --- a/virtcontainers/qemu_ppc64le.go +++ b/virtcontainers/qemu_ppc64le.go @@ -11,7 +11,7 @@ import ( govmmQemu "github.com/intel/govmm/qemu" deviceConfig "github.com/kata-containers/runtime/virtcontainers/device/config" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/kata-containers/runtime/virtcontainers/utils" "github.com/sirupsen/logrus" ) diff --git a/virtcontainers/qemu_test.go b/virtcontainers/qemu_test.go index 1a01868167..5fb1d1463d 100644 --- a/virtcontainers/qemu_test.go +++ b/virtcontainers/qemu_test.go @@ -15,7 +15,7 @@ import ( "testing" govmmQemu "github.com/intel/govmm/qemu" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/stretchr/testify/assert" ) diff --git a/virtcontainers/resource_storage.go b/virtcontainers/resource_storage.go index 91cbf27a56..dff937e65c 100644 --- a/virtcontainers/resource_storage.go +++ b/virtcontainers/resource_storage.go @@ -10,7 +10,7 @@ import ( "encoding/json" "github.com/kata-containers/runtime/virtcontainers/device/api" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" ) // TypedDevice is used as an intermediate representation for marshalling @@ -59,8 +59,8 @@ type resourceStorage interface { deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error) fetchContainerState(sandboxID, containerID string) (types.State, error) - fetchContainerProcess(sandboxID, containerID string) (Process, error) - storeContainerProcess(sandboxID, containerID string, process Process) error + fetchContainerProcess(sandboxID, containerID string) (types.Process, error) + storeContainerProcess(sandboxID, containerID string, process types.Process) error fetchContainerMounts(sandboxID, containerID string) ([]Mount, error) storeContainerMounts(sandboxID, containerID string, mounts []Mount) error fetchContainerDevices(sandboxID, containerID string) ([]ContainerDevice, error) diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index a3794ab90f..f2df53c67a 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -25,8 +25,8 @@ import ( "github.com/kata-containers/runtime/virtcontainers/device/config" "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/pkg/types" + vshim "github.com/kata-containers/runtime/virtcontainers/shim" "github.com/kata-containers/runtime/virtcontainers/utils" "github.com/vishvananda/netlink" ) @@ -67,7 +67,7 @@ type SandboxConfig struct { ProxyType ProxyType ProxyConfig ProxyConfig - ShimType ShimType + ShimType vshim.Type ShimConfig interface{} NetworkModel NetworkModel @@ -826,7 +826,7 @@ func (s *Sandbox) removeNetwork() error { return s.network.remove(s, s.factory != nil) } -func (s *Sandbox) generateNetInfo(inf *vcTypes.Interface) (NetworkInfo, error) { +func (s *Sandbox) generateNetInfo(inf *types.Interface) (NetworkInfo, error) { hw, err := net.ParseMAC(inf.HwAddr) if err != nil { return NetworkInfo{}, err @@ -857,7 +857,7 @@ func (s *Sandbox) generateNetInfo(inf *vcTypes.Interface) (NetworkInfo, error) { } // AddInterface adds new nic to the sandbox. -func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (s *Sandbox) AddInterface(inf *types.Interface) (*types.Interface, error) { netInfo, err := s.generateNetInfo(inf) if err != nil { return nil, err @@ -888,7 +888,7 @@ func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, erro } // RemoveInterface removes a nic of the sandbox. -func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { +func (s *Sandbox) RemoveInterface(inf *types.Interface) (*types.Interface, error) { for i, endpoint := range s.networkNS.Endpoints { if endpoint.HardwareAddr() == inf.HwAddr { s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint") @@ -906,17 +906,17 @@ func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, e } // ListInterfaces lists all nics and their configurations in the sandbox. -func (s *Sandbox) ListInterfaces() ([]*vcTypes.Interface, error) { +func (s *Sandbox) ListInterfaces() ([]*types.Interface, error) { return s.agent.listInterfaces() } // UpdateRoutes updates the sandbox route table (e.g. for portmapping support). -func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { +func (s *Sandbox) UpdateRoutes(routes []*types.Route) ([]*types.Route, error) { return s.agent.updateRoutes(routes) } // ListRoutes lists all routes and their configurations in the sandbox. -func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) { +func (s *Sandbox) ListRoutes() ([]*types.Route, error) { return s.agent.listRoutes() } @@ -1192,7 +1192,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 types.Cmd) (VCContainer, *Process, error) { +func (s *Sandbox) EnterContainer(containerID string, cmd types.Cmd) (VCContainer, *types.Process, error) { // Fetch the container. c, err := s.findContainer(containerID) if err != nil { diff --git a/virtcontainers/sandbox_test.go b/virtcontainers/sandbox_test.go index 4951c7dff2..63cfba2845 100644 --- a/virtcontainers/sandbox_test.go +++ b/virtcontainers/sandbox_test.go @@ -24,7 +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" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "golang.org/x/sys/unix" ) diff --git a/virtcontainers/cc_shim.go b/virtcontainers/shim/cc_shim.go similarity index 71% rename from virtcontainers/cc_shim.go rename to virtcontainers/shim/cc_shim.go index 6f16b4e81a..5ad588c5ef 100644 --- a/virtcontainers/cc_shim.go +++ b/virtcontainers/shim/cc_shim.go @@ -3,23 +3,21 @@ // SPDX-License-Identifier: Apache-2.0 // -package virtcontainers +package shim import ( "fmt" ) -type ccShim struct{} +//CcShim is the structure type of cc-shim +type CcShim struct{} -// start is the ccShim start implementation. +// Start is the CcShim start implementation. // It starts the cc-shim binary with URL and token flags provided by // the proxy. -func (s *ccShim) start(sandbox *Sandbox, params ShimParams) (int, error) { - if sandbox.config == nil { - return -1, fmt.Errorf("Sandbox config cannot be nil") - } +func (s *CcShim) Start(shimType Type, shimConfig interface{}, params Params) (int, error) { - config, ok := newShimConfig(*(sandbox.config)).(ShimConfig) + config, ok := NewShimConfig(shimType, shimConfig).(Config) if !ok { return -1, fmt.Errorf("Wrong shim config type, should be CCShimConfig type") } diff --git a/virtcontainers/shim/kata_builtin_shim.go b/virtcontainers/shim/kata_builtin_shim.go new file mode 100644 index 0000000000..c28d02654f --- /dev/null +++ b/virtcontainers/shim/kata_builtin_shim.go @@ -0,0 +1,16 @@ +// Copyright (c) 2018 HyperHQ Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// + +package shim + +// KataBuiltInShim is the structure type of kata builtin shim +type KataBuiltInShim struct{} + +// Start is the KataBuiltInShim start implementation for kata builtin shim. +// It does nothing. The shim functionality is provided by the virtcontainers +// library. +func (s *KataBuiltInShim) Start(shimType Type, shimConfig interface{}, params Params) (int, error) { + return -1, nil +} diff --git a/virtcontainers/kata_shim.go b/virtcontainers/shim/kata_shim.go similarity index 72% rename from virtcontainers/kata_shim.go rename to virtcontainers/shim/kata_shim.go index cb1cd8e2d1..761bb05826 100644 --- a/virtcontainers/kata_shim.go +++ b/virtcontainers/shim/kata_shim.go @@ -3,13 +3,14 @@ // SPDX-License-Identifier: Apache-2.0 // -package virtcontainers +package shim import ( "fmt" ) -type kataShim struct{} +// KataShim is the structure type of kata shim +type KataShim struct{} // KataShimConfig is the structure providing specific configuration // for kataShim implementation. @@ -18,15 +19,11 @@ type KataShimConfig struct { Debug bool } -// start is the ccShim start implementation. -// It starts the cc-shim binary with URL and token flags provided by +// Start is the KataBuiltInShim start implementation for kata shim. +// It starts the kata shim binary with URL and token flags provided by // the proxy. -func (s *kataShim) start(sandbox *Sandbox, params ShimParams) (int, error) { - if sandbox.config == nil { - return -1, fmt.Errorf("Sandbox config cannot be nil") - } - - config, ok := newShimConfig(*(sandbox.config)).(ShimConfig) +func (s *KataShim) Start(shimType Type, shimConfig interface{}, params Params) (int, error) { + config, ok := NewShimConfig(shimType, shimConfig).(Config) if !ok { return -1, fmt.Errorf("Wrong shim config type, should be KataShimConfig type") } diff --git a/virtcontainers/shim/noop_shim.go b/virtcontainers/shim/noop_shim.go new file mode 100644 index 0000000000..07ceccca22 --- /dev/null +++ b/virtcontainers/shim/noop_shim.go @@ -0,0 +1,15 @@ +// Copyright (c) 2017 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +package shim + +// NoopShim is the structure type of test shim +type NoopShim struct{} + +// Start is the noopShim start implementation for testing purpose. +// It does nothing. +func (s *NoopShim) Start(shimType Type, shimConfig interface{}, params Params) (int, error) { + return 0, nil +} diff --git a/virtcontainers/shim.go b/virtcontainers/shim/shim.go similarity index 64% rename from virtcontainers/shim.go rename to virtcontainers/shim/shim.go index 77ef44b170..efe5e25896 100644 --- a/virtcontainers/shim.go +++ b/virtcontainers/shim/shim.go @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -package virtcontainers +package shim import ( "fmt" @@ -13,34 +13,35 @@ import ( "time" ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter" - "github.com/kata-containers/runtime/virtcontainers/types" + "github.com/kata-containers/runtime/virtcontainers/pkg/types" "github.com/mitchellh/mapstructure" "github.com/sirupsen/logrus" ) -// ShimType describes a shim type. -type ShimType string +// Type describes a shim type. +type Type string const ( // CCShimType is the ccShim. - CCShimType ShimType = "ccShim" + CCShimType Type = "ccShim" // NoopShimType is the noopShim. - NoopShimType ShimType = "noopShim" + NoopShimType Type = "noopShim" // KataShimType is the Kata Containers shim type. - KataShimType ShimType = "kataShim" + KataShimType Type = "kataShim" // KataBuiltInShimType is the Kata Containers builtin shim type. - KataBuiltInShimType ShimType = "kataBuiltInShim" + KataBuiltInShimType Type = "kataBuiltInShim" ) var waitForShimTimeout = 10.0 var consoleFileMode = os.FileMode(0660) +var virtLog = logrus.WithField("source", "shim") -// ShimParams is the structure providing specific parameters needed +// Params is the structure providing specific parameters needed // for the execution of the shim binary. -type ShimParams struct { +type Params struct { Container string Token string URL string @@ -52,16 +53,16 @@ type ShimParams struct { EnterNS []ns.Namespace } -// ShimConfig is the structure providing specific configuration +// Config is the structure providing specific configuration // for shim implementations. -type ShimConfig struct { +type Config struct { Path string Debug bool Trace bool } // Set sets a shim type based on the input string. -func (pType *ShimType) Set(value string) error { +func (pType *Type) Set(value string) error { switch value { case "noopShim": *pType = NoopShimType @@ -78,7 +79,7 @@ func (pType *ShimType) Set(value string) error { } // String converts a shim type to a string. -func (pType *ShimType) String() string { +func (pType *Type) String() string { switch *pType { case NoopShimType: return string(NoopShimType) @@ -93,30 +94,30 @@ func (pType *ShimType) String() string { } } -// newShim returns a shim from a shim type. -func newShim(pType ShimType) (shim, error) { +// NewShim returns a shim from a shim type. +func NewShim(pType Type) (Shim, error) { switch pType { case NoopShimType: - return &noopShim{}, nil + return &NoopShim{}, nil case CCShimType: - return &ccShim{}, nil + return &CcShim{}, nil case KataShimType: - return &kataShim{}, nil + return &KataShim{}, nil case KataBuiltInShimType: - return &kataBuiltInShim{}, nil + return &KataBuiltInShim{}, nil default: - return &noopShim{}, nil + return &NoopShim{}, nil } } -// newShimConfig returns a shim config from a generic SandboxConfig interface. -func newShimConfig(config SandboxConfig) interface{} { - switch config.ShimType { +// NewShimConfig returns a shim config from a generic SandboxConfig interface. +func NewShimConfig(shimType Type, sandboxShimConfig interface{}) interface{} { + switch shimType { case NoopShimType, KataBuiltInShimType: return nil case CCShimType, KataShimType: - var shimConfig ShimConfig - err := mapstructure.Decode(config.ShimConfig, &shimConfig) + var shimConfig Config + err := mapstructure.Decode(sandboxShimConfig, &shimConfig) if err != nil { return err } @@ -130,7 +131,8 @@ func shimLogger() *logrus.Entry { return virtLog.WithField("subsystem", "shim") } -func signalShim(pid int, sig syscall.Signal) error { +// SignalShim use syscall to kill pid's shim +func SignalShim(pid int, sig syscall.Signal) error { if pid <= 0 { return nil } @@ -144,26 +146,28 @@ func signalShim(pid int, sig syscall.Signal) error { return syscall.Kill(pid, sig) } -func stopShim(pid int) error { +// StopShim stop pid's shim +func StopShim(pid int) error { if pid <= 0 { return nil } - if err := signalShim(pid, syscall.SIGKILL); err != nil && err != syscall.ESRCH { + if err := SignalShim(pid, syscall.SIGKILL); err != nil && err != syscall.ESRCH { return err } return nil } -func prepareAndStartShim(sandbox *Sandbox, shim shim, cid, token, url string, cmd types.Cmd, - createNSList []ns.NSType, enterNSList []ns.Namespace) (*Process, error) { - process := &Process{ +// PrepareAndStartShim return a process from configuration information +func PrepareAndStartShim(shimType Type, shimConfig interface{}, shim Shim, cid, token, url string, cmd types.Cmd, + createNSList []ns.NSType, enterNSList []ns.Namespace) (*types.Process, error) { + process := &types.Process{ Token: token, StartTime: time.Now().UTC(), } - shimParams := ShimParams{ + shimParams := Params{ Container: cid, Token: token, URL: url, @@ -174,7 +178,7 @@ func prepareAndStartShim(sandbox *Sandbox, shim shim, cid, token, url string, cm EnterNS: enterNSList, } - pid, err := shim.start(sandbox, shimParams) + pid, err := shim.Start(shimType, shimConfig, shimParams) if err != nil { return nil, err } @@ -184,7 +188,7 @@ func prepareAndStartShim(sandbox *Sandbox, shim shim, cid, token, url string, cm return process, nil } -func startShim(args []string, params ShimParams) (int, error) { +func startShim(args []string, params Params) (int, error) { cmd := exec.Command(args[0], args[1:]...) if !params.Detach { @@ -234,7 +238,8 @@ func startShim(args []string, params ShimParams) (int, error) { return cmd.Process.Pid, nil } -func isShimRunning(pid int) (bool, error) { +// IsShimRunning return whether shim is running +func IsShimRunning(pid int) (bool, error) { if pid <= 0 { return false, nil } @@ -251,16 +256,21 @@ func isShimRunning(pid int) (bool, error) { return true, nil } -// waitForShim waits for the end of the shim unless it reaches the timeout +// SetWaitForShimTimeout set waitForShimTimeout value +func SetWaitForShimTimeout(wft float64) { + waitForShimTimeout = wft +} + +// WaitForShim waits for the end of the shim unless it reaches the timeout // first, returning an error in that case. -func waitForShim(pid int) error { +func WaitForShim(pid int) error { if pid <= 0 { return nil } tInit := time.Now() for { - running, err := isShimRunning(pid) + running, err := IsShimRunning(pid) if err != nil { return err } @@ -280,9 +290,9 @@ func waitForShim(pid int) error { return nil } -// shim is the virtcontainers shim interface. -type shim interface { - // start starts the shim relying on its configuration and on +// Shim is the virtcontainers shim interface. +type Shim interface { + // Start starts the shim relying on its configuration and on // parameters provided. - start(sandbox *Sandbox, params ShimParams) (int, error) + Start(shimType Type, shimConfig interface{}, params Params) (int, error) } diff --git a/virtcontainers/shim_test.go b/virtcontainers/shim_test.go index 22d5cc49ba..95cc87db01 100644 --- a/virtcontainers/shim_test.go +++ b/virtcontainers/shim_test.go @@ -10,14 +10,16 @@ import ( "reflect" "syscall" "testing" + + vshim "github.com/kata-containers/runtime/virtcontainers/shim" ) const ( testRunningProcess = "sleep" ) -func testSetShimType(t *testing.T, value string, expected ShimType) { - var shimType ShimType +func testSetShimType(t *testing.T, value string, expected vshim.Type) { + var shimType vshim.Type err := (&shimType).Set(value) if err != nil { @@ -30,19 +32,19 @@ func testSetShimType(t *testing.T, value string, expected ShimType) { } func TestSetCCShimType(t *testing.T) { - testSetShimType(t, "ccShim", CCShimType) + testSetShimType(t, "ccShim", vshim.CCShimType) } func TestSetKataShimType(t *testing.T) { - testSetShimType(t, "kataShim", KataShimType) + testSetShimType(t, "kataShim", vshim.KataShimType) } func TestSetNoopShimType(t *testing.T) { - testSetShimType(t, "noopShim", NoopShimType) + testSetShimType(t, "noopShim", vshim.NoopShimType) } func TestSetUnknownShimType(t *testing.T) { - var shimType ShimType + var shimType vshim.Type unknownType := "unknown" @@ -51,12 +53,12 @@ func TestSetUnknownShimType(t *testing.T) { t.Fatalf("Should fail because %s type used", unknownType) } - if shimType == CCShimType || shimType == NoopShimType { + if shimType == vshim.CCShimType || shimType == vshim.NoopShimType { t.Fatalf("%s shim type was not expected", shimType) } } -func testStringFromShimType(t *testing.T, shimType ShimType, expected string) { +func testStringFromShimType(t *testing.T, shimType vshim.Type, expected string) { shimTypeStr := (&shimType).String() if shimTypeStr != expected { t.Fatalf("Got %s\nExpecting %s", shimTypeStr, expected) @@ -64,32 +66,32 @@ func testStringFromShimType(t *testing.T, shimType ShimType, expected string) { } func TestStringFromCCShimType(t *testing.T) { - shimType := CCShimType + shimType := vshim.CCShimType testStringFromShimType(t, shimType, "ccShim") } func TestStringFromKataShimType(t *testing.T) { - shimType := KataShimType + shimType := vshim.KataShimType testStringFromShimType(t, shimType, "kataShim") } func TestStringFromNoopShimType(t *testing.T) { - shimType := NoopShimType + shimType := vshim.NoopShimType testStringFromShimType(t, shimType, "noopShim") } func TestStringFromKataBuiltInShimType(t *testing.T) { - shimType := KataBuiltInShimType + shimType := vshim.KataBuiltInShimType testStringFromShimType(t, shimType, "kataBuiltInShim") } func TestStringFromUnknownShimType(t *testing.T) { - var shimType ShimType + var shimType vshim.Type testStringFromShimType(t, shimType, "") } -func testNewShimFromShimType(t *testing.T, shimType ShimType, expected shim) { - result, err := newShim(shimType) +func testNewShimFromShimType(t *testing.T, shimType vshim.Type, expected vshim.Shim) { + result, err := vshim.NewShim(shimType) if err != nil { t.Fatal(err) } @@ -100,40 +102,40 @@ func testNewShimFromShimType(t *testing.T, shimType ShimType, expected shim) { } func TestNewShimFromCCShimType(t *testing.T) { - shimType := CCShimType - expectedShim := &ccShim{} + shimType := vshim.CCShimType + expectedShim := &vshim.CcShim{} testNewShimFromShimType(t, shimType, expectedShim) } func TestNewShimFromKataShimType(t *testing.T) { - shimType := KataShimType - expectedShim := &kataShim{} + shimType := vshim.KataShimType + expectedShim := &vshim.KataShim{} testNewShimFromShimType(t, shimType, expectedShim) } func TestNewShimFromNoopShimType(t *testing.T) { - shimType := NoopShimType - expectedShim := &noopShim{} + shimType := vshim.NoopShimType + expectedShim := &vshim.NoopShim{} testNewShimFromShimType(t, shimType, expectedShim) } func TestNewShimFromKataBuiltInShimType(t *testing.T) { - shimType := KataBuiltInShimType - expectedShim := &kataBuiltInShim{} + shimType := vshim.KataBuiltInShimType + expectedShim := &vshim.KataBuiltInShim{} testNewShimFromShimType(t, shimType, expectedShim) } func TestNewShimFromUnknownShimType(t *testing.T) { - var shimType ShimType + var shimType vshim.Type - _, err := newShim(shimType) + _, err := vshim.NewShim(shimType) if err != nil { t.Fatal(err) } } func testNewShimConfigFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfig, expected interface{}) { - result := newShimConfig(sandboxConfig) + result := vshim.NewShimConfig(sandboxConfig.ShimType, sandboxConfig.ShimConfig) if reflect.DeepEqual(result, expected) == false { t.Fatalf("Got %+v\nExpecting %+v", result, expected) @@ -141,10 +143,10 @@ func testNewShimConfigFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfi } func TestNewShimConfigFromCCShimSandboxConfig(t *testing.T) { - shimConfig := ShimConfig{} + shimConfig := vshim.Config{} sandboxConfig := SandboxConfig{ - ShimType: CCShimType, + ShimType: vshim.CCShimType, ShimConfig: shimConfig, } @@ -152,10 +154,10 @@ func TestNewShimConfigFromCCShimSandboxConfig(t *testing.T) { } func TestNewShimConfigFromKataShimSandboxConfig(t *testing.T) { - shimConfig := ShimConfig{} + shimConfig := vshim.Config{} sandboxConfig := SandboxConfig{ - ShimType: KataShimType, + ShimType: vshim.KataShimType, ShimConfig: shimConfig, } @@ -164,7 +166,7 @@ func TestNewShimConfigFromKataShimSandboxConfig(t *testing.T) { func TestNewShimConfigFromNoopShimSandboxConfig(t *testing.T) { sandboxConfig := SandboxConfig{ - ShimType: NoopShimType, + ShimType: vshim.NoopShimType, } testNewShimConfigFromSandboxConfig(t, sandboxConfig, nil) @@ -172,14 +174,14 @@ func TestNewShimConfigFromNoopShimSandboxConfig(t *testing.T) { func TestNewShimConfigFromKataBuiltInShimSandboxConfig(t *testing.T) { sandboxConfig := SandboxConfig{ - ShimType: KataBuiltInShimType, + ShimType: vshim.KataBuiltInShimType, } testNewShimConfigFromSandboxConfig(t, sandboxConfig, nil) } func TestNewShimConfigFromUnknownShimSandboxConfig(t *testing.T) { - var shimType ShimType + var shimType vshim.Type sandboxConfig := SandboxConfig{ ShimType: shimType, @@ -225,7 +227,7 @@ func testRunSleep999AndGetCmd(t *testing.T) *exec.Cmd { func TestStopShimSuccessfulProcessNotRunning(t *testing.T) { pid := testRunSleep0AndGetPid(t) - if err := stopShim(pid); err != nil { + if err := vshim.StopShim(pid); err != nil { t.Fatal(err) } } @@ -233,13 +235,13 @@ func TestStopShimSuccessfulProcessNotRunning(t *testing.T) { func TestStopShimSuccessfulProcessRunning(t *testing.T) { cmd := testRunSleep999AndGetCmd(t) - if err := stopShim(cmd.Process.Pid); err != nil { + if err := vshim.StopShim(cmd.Process.Pid); err != nil { t.Fatal(err) } } func testIsShimRunning(t *testing.T, pid int, expected bool) { - running, err := isShimRunning(pid) + running, err := vshim.IsShimRunning(pid) if err != nil { t.Fatal(err) } @@ -269,7 +271,7 @@ func TestWaitForShimInvalidPidSuccessful(t *testing.T) { wrongValuesList := []int{0, -1, -100} for _, val := range wrongValuesList { - if err := waitForShim(val); err != nil { + if err := vshim.WaitForShim(val); err != nil { t.Fatal(err) } } @@ -278,7 +280,7 @@ func TestWaitForShimInvalidPidSuccessful(t *testing.T) { func TestWaitForShimNotRunningSuccessful(t *testing.T) { pid := testRunSleep0AndGetPid(t) - if err := waitForShim(pid); err != nil { + if err := vshim.WaitForShim(pid); err != nil { t.Fatal(err) } } @@ -286,8 +288,8 @@ func TestWaitForShimNotRunningSuccessful(t *testing.T) { func TestWaitForShimRunningForTooLongFailure(t *testing.T) { cmd := testRunSleep999AndGetCmd(t) - waitForShimTimeout = 0.1 - if err := waitForShim(cmd.Process.Pid); err == nil { + vshim.SetWaitForShimTimeout(0.1) + if err := vshim.WaitForShim(cmd.Process.Pid); err == nil { t.Fatal(err) }