Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
runtime: Convert to the new internal types package
Browse files Browse the repository at this point in the history
We can now remove all the sandbox shared types and convert the rest of
the code to using the new internal types package.

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

Fixes: #1095

Signed-off-by: Samuel Ortiz <[email protected]>
  • Loading branch information
Samuel Ortiz committed Jan 8, 2019
1 parent 701afe9 commit b05dbe3
Show file tree
Hide file tree
Showing 52 changed files with 430 additions and 645 deletions.
25 changes: 13 additions & 12 deletions cli/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -163,7 +164,7 @@ func TestDeleteSandbox(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "ready",
},
}, nil
Expand All @@ -180,8 +181,8 @@ func TestDeleteSandbox(t *testing.T) {
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
return vc.SandboxStatus{
ID: sandbox.ID(),
State: vc.State{
State: vc.StateReady,
State: types.State{
State: types.StateReady,
},
}, nil
}
Expand Down Expand Up @@ -241,7 +242,7 @@ func TestDeleteInvalidContainerType(t *testing.T) {
vcAnnotations.ContainerTypeKey: "InvalidType",
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "created",
},
}, nil
Expand Down Expand Up @@ -280,7 +281,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "running",
},
}, nil
Expand All @@ -298,8 +299,8 @@ func TestDeleteSandboxRunning(t *testing.T) {
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
return vc.SandboxStatus{
ID: sandbox.ID(),
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}
Expand Down Expand Up @@ -360,7 +361,7 @@ func TestDeleteRunningContainer(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "running",
},
}, nil
Expand Down Expand Up @@ -443,7 +444,7 @@ func TestDeleteContainer(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "ready",
},
}, nil
Expand Down Expand Up @@ -543,7 +544,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
},
State: vc.State{
State: types.State{
State: "ready",
},
}, nil
Expand All @@ -552,8 +553,8 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
return vc.SandboxStatus{
ID: sandbox.ID(),
State: vc.State{
State: vc.StateReady,
State: types.State{
State: types.StateReady,
},
}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion cli/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/types"

"github.com/kata-containers/runtime/pkg/katautils"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -175,7 +176,7 @@ information is displayed once every 5 seconds.`,
span.SetTag("container", containerID)
span.SetTag("sandbox", sandboxID)

if status.State.State == vc.StateStopped {
if status.State.State == types.StateStopped {
return fmt.Errorf("container with id %s is not running", status.ID)
}

Expand Down
5 changes: 3 additions & 2 deletions cli/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -111,8 +112,8 @@ func TestEventsCLISuccessful(t *testing.T) {
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
},
State: vc.State{
State: vc.StateRunning,
State: types.State{
State: types.StateRunning,
},
}, nil
}
Expand Down
9 changes: 5 additions & 4 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
"syscall"

"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/types"

specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -226,8 +227,8 @@ func execute(ctx context.Context, context *cli.Context) error {
span.SetTag("container", containerID)

// container MUST be ready or running.
if status.State.State != vc.StateReady &&
status.State.State != vc.StateRunning {
if status.State.State != types.StateReady &&
status.State.State != types.StateRunning {
return fmt.Errorf("Container %s is not ready or running",
params.cID)
}
Expand All @@ -248,7 +249,7 @@ func execute(ctx context.Context, context *cli.Context) error {
user = params.ociProcess.User.Username
}

cmd := vc.Cmd{
cmd := types.Cmd{
Args: params.ociProcess.Args,
Envs: envVars,
WorkDir: params.ociProcess.Cwd,
Expand Down
51 changes: 26 additions & 25 deletions cli/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestExecuteErrors(t *testing.T) {
}

testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, vc.State{}, annotations), nil
return newSingleContainerStatus(testContainerID, types.State{}, annotations), nil
}

defer func() {
Expand All @@ -99,7 +100,7 @@ func TestExecuteErrors(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

containerState := vc.State{}
containerState := types.State{}
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
}
Expand All @@ -109,8 +110,8 @@ func TestExecuteErrors(t *testing.T) {
assert.False(vcmock.IsMockError(err))

// Container paused
containerState = vc.State{
State: vc.StatePaused,
containerState = types.State{
State: types.StatePaused,
}
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
Expand All @@ -121,8 +122,8 @@ func TestExecuteErrors(t *testing.T) {
assert.False(vcmock.IsMockError(err))

// Container stopped
containerState = vc.State{
State: vc.StateStopped,
containerState = types.State{
State: types.StateStopped,
}
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
Expand Down Expand Up @@ -158,8 +159,8 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}

path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
Expand Down Expand Up @@ -207,8 +208,8 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}

path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
Expand Down Expand Up @@ -274,8 +275,8 @@ func TestExecuteWithFlags(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}

path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
Expand All @@ -299,7 +300,7 @@ func TestExecuteWithFlags(t *testing.T) {

assert.True(vcmock.IsMockError(err))

testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
return &vcmock.Sandbox{}, &vcmock.Container{}, &vc.Process{}, nil
}

Expand All @@ -316,7 +317,7 @@ func TestExecuteWithFlags(t *testing.T) {
os.Remove(pidFilePath)

// Process ran and exited successfully
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
workload := []string{"cat", "/dev/null"}
command := exec.Command(workload[0], workload[1:]...)
Expand Down Expand Up @@ -364,8 +365,8 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}

path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
Expand All @@ -380,7 +381,7 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
testingImpl.StatusContainerFunc = nil
}()

testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
workload := []string{"cat", "/dev/null"}
command := exec.Command(workload[0], workload[1:]...)
Expand Down Expand Up @@ -443,8 +444,8 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}

path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
Expand Down Expand Up @@ -495,8 +496,8 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}

path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
Expand Down Expand Up @@ -542,7 +543,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) {

workload := []string{"cat", "/dev/null"}

testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
command := exec.Command(workload[0], workload[1:]...)
err := command.Start()
Expand Down Expand Up @@ -596,8 +597,8 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
vcAnnotations.ConfigJSONKey: configJSON,
}

state := vc.State{
State: vc.StateRunning,
state := types.State{
State: types.StateRunning,
}

path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
Expand Down Expand Up @@ -644,7 +645,7 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {

workload := []string{"cat", "/dev/null"}

testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
// create a fake container process
command := exec.Command(workload[0], workload[1:]...)
err := command.Start()
Expand Down
3 changes: 2 additions & 1 deletion cli/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -132,7 +133,7 @@ func kill(ctx context.Context, containerID, signal string, all bool) error {
kataLog.WithField("signal", signal).WithField("container state", status.State.State).Info("kill")

// container MUST be created, running or paused
if status.State.State == vc.StateReady || status.State.State == vc.StateRunning || status.State.State == vc.StatePaused {
if status.State.State == types.StateReady || status.State.State == types.StateRunning || status.State.State == types.StatePaused {
if err := vci.KillContainer(ctx, sandboxID, containerID, signum, all); err != nil {
return err
}
Expand Down
Loading

0 comments on commit b05dbe3

Please sign in to comment.