diff --git a/cli/config/configuration.toml.in b/cli/config/configuration.toml.in index 307d841f3..b8ea01d8b 100644 --- a/cli/config/configuration.toml.in +++ b/cli/config/configuration.toml.in @@ -33,7 +33,7 @@ firmware = "@FIRMWAREPATH@" # For example, `machine_accelerators = "nosmm,nosmbus,nosata,nopit,static-prt,nofw"` machine_accelerators="@MACHINEACCELERATORS@" -# Default number of vCPUs per POD/VM: +# Default number of vCPUs per SB/VM: # unspecified or 0 --> will be set to @DEFVCPUS@ # < 0 --> will be set to the actual number of physical cores # > 0 <= number of physical cores --> will be set to the specified number @@ -47,13 +47,13 @@ default_vcpus = 1 # * Until 30 devices per bridge can be hot plugged. # * Until 5 PCI bridges can be cold plugged per VM. # This limitation could be a bug in qemu or in the kernel -# Default number of bridges per POD/VM: +# Default number of bridges per SB/VM: # unspecified or 0 --> will be set to @DEFBRIDGES@ # > 1 <= 5 --> will be set to the specified number # > 5 --> will be set to 5 default_bridges = @DEFBRIDGES@ -# Default memory size in MiB for POD/VM. +# Default memory size in MiB for SB/VM. # If unspecified then it will be set @DEFMEMSZ@ MiB. #default_memory = @DEFMEMSZ@ diff --git a/cli/create.go b/cli/create.go index 437e05e4b..0c16b27c2 100644 --- a/cli/create.go +++ b/cli/create.go @@ -115,7 +115,7 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool, switch containerType { case vc.PodSandbox: - process, err = createPod(ociSpec, runtimeConfig, containerID, bundlePath, console, disableOutput) + process, err = createSandbox(ociSpec, runtimeConfig, containerID, bundlePath, console, disableOutput) if err != nil { return err } @@ -131,7 +131,7 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool, // is shim's in our case. This is mandatory to make sure there is no one // else (like Docker) trying to create those files on our behalf. We want to // know those files location so that we can remove them when delete is called. - cgroupsPathList, err := processCgroupsPath(ociSpec, containerType.IsPod()) + cgroupsPathList, err := processCgroupsPath(ociSpec, containerType.IsSandbox()) if err != nil { return err } @@ -225,7 +225,7 @@ func setKernelParams(containerID string, runtimeConfig *oci.RuntimeConfig) error return nil } -func createPod(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig, +func createSandbox(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig, containerID, bundlePath, console string, disableOutput bool) (vc.Process, error) { err := setKernelParams(containerID, &runtimeConfig) @@ -233,19 +233,19 @@ func createPod(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig, return vc.Process{}, err } - podConfig, err := oci.PodConfig(ociSpec, runtimeConfig, bundlePath, containerID, console, disableOutput) + sandboxConfig, err := oci.SandboxConfig(ociSpec, runtimeConfig, bundlePath, containerID, console, disableOutput) if err != nil { return vc.Process{}, err } - pod, err := vci.CreatePod(podConfig) + sandbox, err := vci.CreateSandbox(sandboxConfig) if err != nil { return vc.Process{}, err } - containers := pod.GetAllContainers() + containers := sandbox.GetAllContainers() if len(containers) != 1 { - return vc.Process{}, fmt.Errorf("BUG: Container list from pod is wrong, expecting only one container, found %d containers", len(containers)) + return vc.Process{}, fmt.Errorf("BUG: Container list from sandbox is wrong, expecting only one container, found %d containers", len(containers)) } return containers[0].Process(), nil @@ -259,12 +259,12 @@ func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath, return vc.Process{}, err } - podID, err := ociSpec.PodID() + sandboxID, err := ociSpec.SandboxID() if err != nil { return vc.Process{}, err } - _, c, err := vci.CreateContainer(podID, contConfig) + _, c, err := vci.CreateContainer(sandboxID, contConfig) if err != nil { return vc.Process{}, err } diff --git a/cli/create_test.go b/cli/create_test.go index 60e3f4ba1..cda229334 100644 --- a/cli/create_test.go +++ b/cli/create_test.go @@ -37,7 +37,7 @@ const ( testConsole = "/dev/pts/999" testContainerTypeAnnotation = "io.kubernetes.cri-o.ContainerType" testSandboxIDAnnotation = "io.kubernetes.cri-o.SandboxID" - testContainerTypePod = "sandbox" + testContainerTypeSandbox = "sandbox" testContainerTypeContainer = "container" ) @@ -301,8 +301,8 @@ func TestCreateCLIFunctionCreateFail(t *testing.T) { func TestCreateInvalidArgs(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, MockContainers: []*vcmock.Container{ {MockID: testContainerID}, {MockID: testContainerID}, @@ -310,18 +310,18 @@ func TestCreateInvalidArgs(t *testing.T) { }, } - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return pod, nil + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return sandbox, nil } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.CreatePodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -364,13 +364,13 @@ func TestCreateInvalidArgs(t *testing.T) { func TestCreateInvalidConfigJSON(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -408,13 +408,13 @@ func TestCreateInvalidConfigJSON(t *testing.T) { func TestCreateInvalidContainerType(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -455,13 +455,13 @@ func TestCreateInvalidContainerType(t *testing.T) { func TestCreateContainerInvalid(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -503,25 +503,25 @@ func TestCreateContainerInvalid(t *testing.T) { func TestCreateProcessCgroupsPathSuccessful(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, MockContainers: []*vcmock.Container{ {MockID: testContainerID}, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return pod, nil + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.ListPodFunc = nil - testingImpl.CreatePodFunc = nil + testingImpl.ListSandboxFunc = nil + testingImpl.CreateSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -544,9 +544,9 @@ func TestCreateProcessCgroupsPathSuccessful(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - // Force pod-type container + // Force sandbox-type container spec.Annotations = make(map[string]string) - spec.Annotations[testContainerTypeAnnotation] = testContainerTypePod + spec.Annotations[testContainerTypeAnnotation] = testContainerTypeSandbox // Set a limit to ensure processCgroupsPath() considers the // cgroup part of the spec @@ -598,25 +598,25 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, MockContainers: []*vcmock.Container{ {MockID: testContainerID}, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return pod, nil + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.ListPodFunc = nil - testingImpl.CreatePodFunc = nil + testingImpl.ListSandboxFunc = nil + testingImpl.CreateSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -639,9 +639,9 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - // Force pod-type container + // Force sandbox-type container spec.Annotations = make(map[string]string) - spec.Annotations[testContainerTypeAnnotation] = testContainerTypePod + spec.Annotations[testContainerTypeAnnotation] = testContainerTypeSandbox // Set a limit to ensure processCgroupsPath() considers the // cgroup part of the spec @@ -683,25 +683,25 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, MockContainers: []*vcmock.Container{ {MockID: testContainerID}, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return pod, nil + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.ListPodFunc = nil - testingImpl.CreatePodFunc = nil + testingImpl.ListSandboxFunc = nil + testingImpl.CreateSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -725,9 +725,9 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - // Force pod-type container + // Force sandbox-type container spec.Annotations = make(map[string]string) - spec.Annotations[testContainerTypeAnnotation] = testContainerTypePod + spec.Annotations[testContainerTypeAnnotation] = testContainerTypeSandbox // Set a limit to ensure processCgroupsPath() considers the // cgroup part of the spec @@ -754,25 +754,25 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) { func TestCreate(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, MockContainers: []*vcmock.Container{ {MockID: testContainerID}, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return pod, nil + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.ListPodFunc = nil - testingImpl.CreatePodFunc = nil + testingImpl.ListSandboxFunc = nil + testingImpl.CreateSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -795,9 +795,9 @@ func TestCreate(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - // Force pod-type container + // Force sandbox-type container spec.Annotations = make(map[string]string) - spec.Annotations[testContainerTypeAnnotation] = testContainerTypePod + spec.Annotations[testContainerTypeAnnotation] = testContainerTypeSandbox // Set a limit to ensure processCgroupsPath() considers the // cgroup part of the spec @@ -819,13 +819,13 @@ func TestCreate(t *testing.T) { func TestCreateInvalidKernelParams(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -848,9 +848,9 @@ func TestCreateInvalidKernelParams(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - // Force createPod() to be called. + // Force createSandbox() to be called. spec.Annotations = make(map[string]string) - spec.Annotations[testContainerTypeAnnotation] = testContainerTypePod + spec.Annotations[testContainerTypeAnnotation] = testContainerTypeSandbox // rewrite the file err = writeOCIConfigFile(spec, ociConfigFile) @@ -877,16 +877,16 @@ func TestCreateInvalidKernelParams(t *testing.T) { } } -func TestCreateCreatePodPodConfigFail(t *testing.T) { +func TestCreateSandboxConfigFail(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -919,21 +919,21 @@ func TestCreateCreatePodPodConfigFail(t *testing.T) { Quota: "a, } - _, err = createPod(spec, runtimeConfig, testContainerID, bundlePath, testConsole, true) + _, err = createSandbox(spec, runtimeConfig, testContainerID, bundlePath, testConsole, true) assert.Error(err) assert.False(vcmock.IsMockError(err)) } -func TestCreateCreatePodFail(t *testing.T) { +func TestCreateCreateSandboxFail(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -954,7 +954,7 @@ func TestCreateCreatePodFail(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - _, err = createPod(spec, runtimeConfig, testContainerID, bundlePath, testConsole, true) + _, err = createSandbox(spec, runtimeConfig, testContainerID, bundlePath, testConsole, true) assert.Error(err) assert.True(vcmock.IsMockError(err)) } @@ -962,13 +962,13 @@ func TestCreateCreatePodFail(t *testing.T) { func TestCreateCreateContainerContainerConfigFail(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -1006,13 +1006,13 @@ func TestCreateCreateContainerContainerConfigFail(t *testing.T) { func TestCreateCreateContainerFail(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir("", "") @@ -1030,10 +1030,10 @@ func TestCreateCreateContainerFail(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - // set expected container type and podID + // set expected container type and sandboxID spec.Annotations = make(map[string]string) spec.Annotations[testContainerTypeAnnotation] = testContainerTypeContainer - spec.Annotations[testSandboxIDAnnotation] = testPodID + spec.Annotations[testSandboxIDAnnotation] = testSandboxID // rewrite file err = writeOCIConfigFile(spec, ociConfigFile) @@ -1049,17 +1049,17 @@ func TestCreateCreateContainerFail(t *testing.T) { func TestCreateCreateContainer(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } - testingImpl.CreateContainerFunc = func(podID string, containerConfig vc.ContainerConfig) (vc.VCPod, vc.VCContainer, error) { - return &vcmock.Pod{}, &vcmock.Container{}, nil + testingImpl.CreateContainerFunc = func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) { + return &vcmock.Sandbox{}, &vcmock.Container{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil testingImpl.CreateContainerFunc = nil }() @@ -1078,10 +1078,10 @@ func TestCreateCreateContainer(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - // set expected container type and podID + // set expected container type and sandboxID spec.Annotations = make(map[string]string) spec.Annotations[testContainerTypeAnnotation] = testContainerTypeContainer - spec.Annotations[testSandboxIDAnnotation] = testPodID + spec.Annotations[testSandboxIDAnnotation] = testSandboxID // rewrite file err = writeOCIConfigFile(spec, ociConfigFile) diff --git a/cli/delete.go b/cli/delete.go index 53fb97dda..451f4a30e 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -62,7 +62,7 @@ EXAMPLE: func delete(containerID string, force bool) error { // Checks the MUST and MUST NOT from OCI runtime specification - status, podID, err := getExistingContainerInfo(containerID) + status, sandboxID, err := getExistingContainerInfo(containerID) if err != nil { return err } @@ -91,11 +91,11 @@ func delete(containerID string, force bool) error { switch containerType { case vc.PodSandbox: - if err := deletePod(podID); err != nil { + if err := deleteSandbox(sandboxID); err != nil { return err } case vc.PodContainer: - if err := deleteContainer(podID, containerID, forceStop); err != nil { + if err := deleteContainer(sandboxID, containerID, forceStop); err != nil { return err } default: @@ -105,7 +105,7 @@ func delete(containerID string, force bool) error { // In order to prevent any file descriptor leak related to cgroups files // that have been previously created, we have to remove them before this // function returns. - cgroupsPathList, err := processCgroupsPath(ociSpec, containerType.IsPod()) + cgroupsPathList, err := processCgroupsPath(ociSpec, containerType.IsSandbox()) if err != nil { return err } @@ -113,26 +113,26 @@ func delete(containerID string, force bool) error { return removeCgroupsPath(containerID, cgroupsPathList) } -func deletePod(podID string) error { - if _, err := vci.StopPod(podID); err != nil { +func deleteSandbox(sandboxID string) error { + if _, err := vci.StopSandbox(sandboxID); err != nil { return err } - if _, err := vci.DeletePod(podID); err != nil { + if _, err := vci.DeleteSandbox(sandboxID); err != nil { return err } return nil } -func deleteContainer(podID, containerID string, forceStop bool) error { +func deleteContainer(sandboxID, containerID string, forceStop bool) error { if forceStop { - if _, err := vci.StopContainer(podID, containerID); err != nil { + if _, err := vci.StopContainer(sandboxID, containerID); err != nil { return err } } - if _, err := vci.DeleteContainer(podID, containerID); err != nil { + if _, err := vci.DeleteContainer(sandboxID, containerID); err != nil { return err } diff --git a/cli/delete_test.go b/cli/delete_test.go index a36375c23..00ecf98de 100644 --- a/cli/delete_test.go +++ b/cli/delete_test.go @@ -63,20 +63,20 @@ func TestDeleteInvalidContainer(t *testing.T) { assert.Error(err) assert.False(vcmock.IsMockError(err)) - // Mock Listpod error + // Mock Listsandbox error err = delete(testContainerID, false) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - // Container missing in ListPod + // Container missing in ListSandbox err = delete(testContainerID, false) assert.Error(err) assert.False(vcmock.IsMockError(err)) @@ -85,17 +85,17 @@ func TestDeleteInvalidContainer(t *testing.T) { func TestDeleteMissingContainerTypeAnnotation(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{}, }, }, @@ -104,10 +104,10 @@ func TestDeleteMissingContainerTypeAnnotation(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - err := delete(pod.ID(), false) + err := delete(sandbox.ID(), false) assert.Error(err) assert.False(vcmock.IsMockError(err)) } @@ -115,17 +115,17 @@ func TestDeleteMissingContainerTypeAnnotation(t *testing.T) { func TestDeleteInvalidConfig(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), }, @@ -136,10 +136,10 @@ func TestDeleteInvalidConfig(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - err := delete(pod.ID(), false) + err := delete(sandbox.ID(), false) assert.Error(err) assert.False(vcmock.IsMockError(err)) } @@ -162,24 +162,24 @@ func testConfigSetup(t *testing.T) string { return configPath } -func TestDeletePod(t *testing.T) { +func TestDeleteSandbox(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } configPath := testConfigSetup(t) configJSON, err := readOCIConfigJSON(configPath) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), vcAnnotations.ConfigJSONKey: configJSON, @@ -194,55 +194,55 @@ func TestDeletePod(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - err = delete(pod.ID(), false) + err = delete(sandbox.ID(), false) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.StopPodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.StopPodFunc = nil + testingImpl.StopSandboxFunc = nil }() - err = delete(pod.ID(), false) + err = delete(sandbox.ID(), false) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.DeletePodFunc = nil + testingImpl.DeleteSandboxFunc = nil }() - err = delete(pod.ID(), false) + err = delete(sandbox.ID(), false) assert.Nil(err) } func TestDeleteInvalidContainerType(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } configPath := testConfigSetup(t) configJSON, err := readOCIConfigJSON(configPath) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: "InvalidType", vcAnnotations.ConfigJSONKey: configJSON, @@ -257,33 +257,33 @@ func TestDeleteInvalidContainerType(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() // Delete an invalid container type - err = delete(pod.ID(), false) + err = delete(sandbox.ID(), false) assert.Error(err) assert.False(vcmock.IsMockError(err)) } -func TestDeletePodRunning(t *testing.T) { +func TestDeleteSandboxRunning(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } configPath := testConfigSetup(t) configJSON, err := readOCIConfigJSON(configPath) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), vcAnnotations.ConfigJSONKey: configJSON, @@ -298,50 +298,50 @@ func TestDeletePodRunning(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - // Delete on a running pod should fail - err = delete(pod.ID(), false) + // Delete on a running sandbox should fail + err = delete(sandbox.ID(), false) assert.Error(err) assert.False(vcmock.IsMockError(err)) - testingImpl.StopPodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.StopPodFunc = nil + testingImpl.StopSandboxFunc = nil }() - // Force delete a running pod - err = delete(pod.ID(), true) + // Force delete a running sandbox + err = delete(sandbox.ID(), true) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.DeletePodFunc = nil + testingImpl.DeleteSandboxFunc = nil }() - err = delete(pod.ID(), true) + err = delete(sandbox.ID(), true) assert.Nil(err) } func TestDeleteRunningContainer(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: testContainerID, - MockPod: pod, + MockID: testContainerID, + MockSandbox: sandbox, }, } @@ -349,13 +349,13 @@ func TestDeleteRunningContainer(t *testing.T) { configJSON, err := readOCIConfigJSON(configPath) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.MockContainers[0].ID(), + ID: sandbox.MockContainers[0].ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), vcAnnotations.ConfigJSONKey: configJSON, @@ -370,16 +370,16 @@ func TestDeleteRunningContainer(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() // Delete on a running container should fail. - err = delete(pod.MockContainers[0].ID(), false) + err = delete(sandbox.MockContainers[0].ID(), false) assert.Error(err) assert.False(vcmock.IsMockError(err)) // force delete - err = delete(pod.MockContainers[0].ID(), true) + err = delete(sandbox.MockContainers[0].ID(), true) assert.Error(err) assert.True(vcmock.IsMockError(err)) @@ -388,11 +388,11 @@ func TestDeleteRunningContainer(t *testing.T) { testingImpl.StopContainerFunc = nil }() - err = delete(pod.MockContainers[0].ID(), true) + err = delete(sandbox.MockContainers[0].ID(), true) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { return &vcmock.Container{}, nil } @@ -400,21 +400,21 @@ func TestDeleteRunningContainer(t *testing.T) { testingImpl.DeleteContainerFunc = nil }() - err = delete(pod.MockContainers[0].ID(), true) + err = delete(sandbox.MockContainers[0].ID(), true) assert.Nil(err) } func TestDeleteContainer(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: testContainerID, - MockPod: pod, + MockID: testContainerID, + MockSandbox: sandbox, }, } @@ -422,13 +422,13 @@ func TestDeleteContainer(t *testing.T) { configJSON, err := readOCIConfigJSON(configPath) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.MockContainers[0].ID(), + ID: sandbox.MockContainers[0].ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), vcAnnotations.ConfigJSONKey: configJSON, @@ -443,10 +443,10 @@ func TestDeleteContainer(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - err = delete(pod.MockContainers[0].ID(), false) + err = delete(sandbox.MockContainers[0].ID(), false) assert.Error(err) assert.True(vcmock.IsMockError(err)) @@ -455,11 +455,11 @@ func TestDeleteContainer(t *testing.T) { testingImpl.StopContainerFunc = nil }() - err = delete(pod.MockContainers[0].ID(), false) + err = delete(sandbox.MockContainers[0].ID(), false) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { return &vcmock.Container{}, nil } @@ -467,7 +467,7 @@ func TestDeleteContainer(t *testing.T) { testingImpl.DeleteContainerFunc = nil }() - err = delete(pod.MockContainers[0].ID(), false) + err = delete(sandbox.MockContainers[0].ID(), false) assert.Nil(err) } @@ -499,14 +499,14 @@ func TestDeleteCLIFunction(t *testing.T) { func TestDeleteCLIFunctionSuccess(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: testContainerID, - MockPod: pod, + MockID: testContainerID, + MockSandbox: sandbox, }, } @@ -514,13 +514,13 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) { configJSON, err := readOCIConfigJSON(configPath) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), vcAnnotations.ConfigJSONKey: configJSON, @@ -534,18 +534,18 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) { }, nil } - testingImpl.StopPodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } - testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.ListPodFunc = nil - testingImpl.StopPodFunc = nil - testingImpl.DeletePodFunc = nil + testingImpl.ListSandboxFunc = nil + testingImpl.StopSandboxFunc = nil + testingImpl.DeleteSandboxFunc = nil }() flagSet := &flag.FlagSet{} @@ -561,7 +561,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) { assert.False(vcmock.IsMockError(err)) flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError) - flagSet.Parse([]string{pod.ID()}) + flagSet.Parse([]string{sandbox.ID()}) ctx = cli.NewContext(app, flagSet, nil) assert.NotNil(ctx) diff --git a/cli/exec.go b/cli/exec.go index d5be5fba9..24ea436de 100644 --- a/cli/exec.go +++ b/cli/exec.go @@ -192,7 +192,7 @@ func generateExecParams(context *cli.Context, specProcess *oci.CompatOCIProcess) func execute(context *cli.Context) error { containerID := context.Args().First() - status, podID, err := getExistingContainerInfo(containerID) + status, sandboxID, err := getExistingContainerInfo(containerID) if err != nil { return err } @@ -243,7 +243,7 @@ func execute(context *cli.Context) error { Detach: noNeedForOutput(params.detach, params.ociProcess.Terminal), } - _, _, process, err := vci.EnterContainer(podID, params.cID, cmd) + _, _, process, err := vci.EnterContainer(sandboxID, params.cID, cmd) if err != nil { return err } diff --git a/cli/exec_test.go b/cli/exec_test.go index 64ac26ed7..b20f93228 100644 --- a/cli/exec_test.go +++ b/cli/exec_test.go @@ -66,7 +66,7 @@ func TestExecuteErrors(t *testing.T) { assert.Error(err) assert.False(vcmock.IsMockError(err)) - // ListPod error + // ListSandbox error flagSet.Parse([]string{testContainerID}) err = execute(ctx) assert.Error(err) @@ -77,12 +77,12 @@ func TestExecuteErrors(t *testing.T) { vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, vc.State{}, vc.State{}, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, vc.State{}, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() err = execute(ctx) @@ -100,8 +100,8 @@ func TestExecuteErrors(t *testing.T) { } containerState := vc.State{} - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, vc.State{}, containerState, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, containerState, annotations), nil } err = execute(ctx) @@ -112,8 +112,8 @@ func TestExecuteErrors(t *testing.T) { containerState = vc.State{ State: vc.StatePaused, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, vc.State{}, containerState, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, containerState, annotations), nil } err = execute(ctx) @@ -124,8 +124,8 @@ func TestExecuteErrors(t *testing.T) { containerState = vc.State{ State: vc.StateStopped, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, vc.State{}, containerState, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, containerState, annotations), nil } err = execute(ctx) @@ -161,12 +161,12 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() // Note: flags can only be tested with the CLI command function @@ -205,12 +205,12 @@ func TestExecuteErrorOpeningConsole(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() // Note: flags can only be tested with the CLI command function @@ -267,12 +267,12 @@ func TestExecuteWithFlags(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() fn, ok := execCLICommand.Action.(func(context *cli.Context) error) @@ -283,8 +283,8 @@ func TestExecuteWithFlags(t *testing.T) { assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.EnterContainerFunc = func(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) { - return &vcmock.Pod{}, &vcmock.Container{}, &vc.Process{}, nil + testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { + return &vcmock.Sandbox{}, &vcmock.Container{}, &vc.Process{}, nil } defer func() { @@ -300,7 +300,7 @@ func TestExecuteWithFlags(t *testing.T) { os.Remove(pidFilePath) // Process ran and exited successfully - testingImpl.EnterContainerFunc = func(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) { + testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.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:]...) @@ -309,7 +309,7 @@ func TestExecuteWithFlags(t *testing.T) { vcProcess := vc.Process{} vcProcess.Pid = command.Process.Pid - return &vcmock.Pod{}, &vcmock.Container{}, &vcProcess, nil + return &vcmock.Sandbox{}, &vcmock.Container{}, &vcProcess, nil } defer func() { @@ -351,15 +351,15 @@ func TestExecuteWithFlagsDetached(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - testingImpl.EnterContainerFunc = func(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) { + testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.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:]...) @@ -368,7 +368,7 @@ func TestExecuteWithFlagsDetached(t *testing.T) { vcProcess := vc.Process{} vcProcess.Pid = command.Process.Pid - return &vcmock.Pod{}, &vcmock.Container{}, &vcProcess, nil + return &vcmock.Sandbox{}, &vcmock.Container{}, &vcProcess, nil } defer func() { @@ -425,12 +425,12 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() fn, ok := execCLICommand.Action.(func(context *cli.Context) error) @@ -472,12 +472,12 @@ func TestExecuteWithValidProcessJson(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() processJSON := `{ @@ -511,7 +511,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) { workload := []string{"cat", "/dev/null"} - testingImpl.EnterContainerFunc = func(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) { + testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { // create a fake container process command := exec.Command(workload[0], workload[1:]...) err := command.Start() @@ -520,7 +520,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) { vcProcess := vc.Process{} vcProcess.Pid = command.Process.Pid - return &vcmock.Pod{}, &vcmock.Container{}, &vcProcess, nil + return &vcmock.Sandbox{}, &vcmock.Container{}, &vcProcess, nil } defer func() { @@ -564,12 +564,12 @@ func TestExecuteWithInvalidEnvironment(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, annotations), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() processJSON := `{ diff --git a/cli/kill.go b/cli/kill.go index fc274b429..33c4ec048 100644 --- a/cli/kill.go +++ b/cli/kill.go @@ -99,7 +99,7 @@ var signals = map[string]syscall.Signal{ func kill(containerID, signal string, all bool) error { // Checks the MUST and MUST NOT from OCI runtime specification - status, podID, err := getExistingContainerInfo(containerID) + status, sandboxID, err := getExistingContainerInfo(containerID) if err != nil { return err } @@ -116,7 +116,7 @@ func kill(containerID, signal string, all bool) error { return fmt.Errorf("Container %s not ready or running, cannot send a signal", containerID) } - if err := vci.KillContainer(podID, containerID, signum, all); err != nil { + if err := vci.KillContainer(sandboxID, containerID, signum, all); err != nil { return err } @@ -124,7 +124,7 @@ func kill(containerID, signal string, all bool) error { return nil } - _, err = vci.StopContainer(podID, containerID) + _, err = vci.StopContainer(sandboxID, containerID) return err } diff --git a/cli/kill_test.go b/cli/kill_test.go index f208319ae..0305ae370 100644 --- a/cli/kill_test.go +++ b/cli/kill_test.go @@ -26,11 +26,11 @@ import ( ) var ( - testKillContainerFuncReturnNil = func(podID, containerID string, signal syscall.Signal, all bool) error { + testKillContainerFuncReturnNil = func(sandboxID, containerID string, signal syscall.Signal, all bool) error { return nil } - testStopContainerFuncReturnNil = func(podID, containerID string) (vc.VCContainer, error) { + testStopContainerFuncReturnNil = func(sandboxID, containerID string) (vc.VCContainer, error) { return &vcmock.Container{}, nil } ) @@ -72,12 +72,12 @@ func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) { testingImpl.KillContainerFunc = testKillContainerFuncReturnNil testingImpl.StopContainerFunc = testStopContainerFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -102,12 +102,12 @@ func TestKillCLIFunctionNotTerminationSignalSuccessful(t *testing.T) { } testingImpl.KillContainerFunc = testKillContainerFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -124,12 +124,12 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) { } testingImpl.KillContainerFunc = testKillContainerFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -145,19 +145,19 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) { State: vc.StateRunning, } - testingImpl.KillContainerFunc = func(podID, containerID string, signal syscall.Signal, all bool) error { + testingImpl.KillContainerFunc = func(sandboxID, containerID string, signal syscall.Signal, all bool) error { if !all { return fmt.Errorf("Expecting -all flag = true, Got false") } return nil } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -179,12 +179,12 @@ func TestKillCLIFunctionContainerNotExistFailure(t *testing.T) { assert := assert.New(t) testingImpl.KillContainerFunc = testKillContainerFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -201,12 +201,12 @@ func TestKillCLIFunctionInvalidSignalFailure(t *testing.T) { } testingImpl.KillContainerFunc = testKillContainerFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -223,12 +223,12 @@ func TestKillCLIFunctionInvalidStatePausedFailure(t *testing.T) { } testingImpl.KillContainerFunc = testKillContainerFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -245,12 +245,12 @@ func TestKillCLIFunctionInvalidStateStoppedFailure(t *testing.T) { } testingImpl.KillContainerFunc = testKillContainerFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { testingImpl.KillContainerFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -266,11 +266,11 @@ func TestKillCLIFunctionKillContainerFailure(t *testing.T) { State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) diff --git a/cli/list.go b/cli/list.go index 831bb3d06..a3f928b60 100644 --- a/cli/list.go +++ b/cli/list.go @@ -309,22 +309,22 @@ func getContainers(context *cli.Context) ([]fullContainerState, error) { latestHypervisorDetails := getHypervisorDetails(&runtimeConfig.HypervisorConfig) - podList, err := vci.ListPod() + sandboxList, err := vci.ListSandbox() if err != nil { return nil, err } var s []fullContainerState - for _, pod := range podList { - if len(pod.ContainersStatus) == 0 { - // ignore empty pods + for _, sandbox := range sandboxList { + if len(sandbox.ContainersStatus) == 0 { + // ignore empty sandboxes continue } - currentHypervisorDetails := getHypervisorDetails(&pod.HypervisorConfig) + currentHypervisorDetails := getHypervisorDetails(&sandbox.HypervisorConfig) - for _, container := range pod.ContainersStatus { + for _, container := range sandbox.ContainersStatus { ociState := oci.StatusToOCIState(container) staleAssets := getStaleAssets(currentHypervisorDetails, latestHypervisorDetails) diff --git a/cli/list_test.go b/cli/list_test.go index 48b8e2038..49ea4ca90 100644 --- a/cli/list_test.go +++ b/cli/list_test.go @@ -375,7 +375,7 @@ func TestListCLIFunctionNoContainers(t *testing.T) { assert.Error(t, err) } -func TestListGetContainersListPodFail(t *testing.T) { +func TestListGetContainersListSandboxFail(t *testing.T) { assert := assert.New(t) tmpdir, err := ioutil.TempDir(testDir, "") @@ -401,13 +401,13 @@ func TestListGetContainersListPodFail(t *testing.T) { func TestListGetContainers(t *testing.T) { assert := assert.New(t) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // No pre-existing pods - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // No pre-existing sandboxes + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir(testDir, "") @@ -430,24 +430,24 @@ func TestListGetContainers(t *testing.T) { assert.Equal(state, []fullContainerState(nil)) } -func TestListGetContainersPodWithoutContainers(t *testing.T) { +func TestListGetContainersSandboxWithoutContainers(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus(nil), }, }, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() tmpdir, err := ioutil.TempDir(testDir, "") @@ -470,28 +470,28 @@ func TestListGetContainersPodWithoutContainers(t *testing.T) { assert.Equal(state, []fullContainerState(nil)) } -func TestListGetContainersPodWithContainer(t *testing.T) { +func TestListGetContainersSandboxWithContainer(t *testing.T) { assert := assert.New(t) tmpdir, err := ioutil.TempDir(testDir, "") assert.NoError(err) defer os.RemoveAll(tmpdir) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } rootfs := filepath.Join(tmpdir, "rootfs") err = os.MkdirAll(rootfs, testDirMode) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{}, RootFs: rootfs, }, @@ -501,7 +501,7 @@ func TestListGetContainersPodWithContainer(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() app := cli.NewApp() @@ -550,19 +550,19 @@ func TestListCLIFunctionFormatFail(t *testing.T) { {"invalid", invalidFlags}, } - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } rootfs := filepath.Join(tmpdir, "rootfs") - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), }, @@ -574,7 +574,7 @@ func TestListCLIFunctionFormatFail(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() savedOutputFile := defaultOutputFile @@ -651,21 +651,21 @@ func TestListCLIFunctionQuiet(t *testing.T) { runtimeConfig, err := newTestRuntimeConfig(tmpdir, testConsole, true) assert.NoError(err) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } rootfs := filepath.Join(tmpdir, "rootfs") err = os.MkdirAll(rootfs, testDirMode) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), }, @@ -677,7 +677,7 @@ func TestListCLIFunctionQuiet(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("test", 0) @@ -713,7 +713,7 @@ func TestListCLIFunctionQuiet(t *testing.T) { assert.NoError(err) trimmed := strings.TrimSpace(text) - assert.Equal(testPodID, trimmed) + assert.Equal(testSandboxID, trimmed) } func TestListGetDirOwner(t *testing.T) { diff --git a/cli/main_test.go b/cli/main_test.go index 407be9420..f84b921ca 100644 --- a/cli/main_test.go +++ b/cli/main_test.go @@ -50,7 +50,7 @@ const ( // small docker image used to create root filesystems from testDockerImage = "busybox" - testPodID = "99999999-9999-9999-99999999999999999" + testSandboxID = "99999999-9999-9999-99999999999999999" testContainerID = "1" testBundle = "bundle" ) @@ -449,11 +449,11 @@ func writeOCIConfigFile(spec oci.CompatOCISpec, configPath string) error { return ioutil.WriteFile(configPath, bytes, testFileMode) } -func newSingleContainerPodStatusList(podID, containerID string, podState, containerState vc.State, annotations map[string]string) []vc.PodStatus { - return []vc.PodStatus{ +func newSingleContainerSandboxStatusList(sandboxID, containerID string, sandboxState, containerState vc.State, annotations map[string]string) []vc.SandboxStatus { + return []vc.SandboxStatus{ { - ID: podID, - State: podState, + ID: sandboxID, + State: sandboxState, ContainersStatus: []vc.ContainerStatus{ { ID: containerID, diff --git a/cli/oci.go b/cli/oci.go index 5b7b6f2e7..41403d262 100644 --- a/cli/oci.go +++ b/cli/oci.go @@ -49,22 +49,22 @@ var cgroupsDirPath string var procMountInfo = "/proc/self/mountinfo" -// getContainerInfo returns the container status and its pod ID. +// getContainerInfo returns the container status and its sandbox ID. func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) { // container ID MUST be provided. if containerID == "" { return vc.ContainerStatus{}, "", fmt.Errorf("Missing container ID") } - podStatusList, err := vci.ListPod() + sandboxStatusList, err := vci.ListSandbox() if err != nil { return vc.ContainerStatus{}, "", err } - for _, podStatus := range podStatusList { - for _, containerStatus := range podStatus.ContainersStatus { + for _, sandboxStatus := range sandboxStatusList { + for _, containerStatus := range sandboxStatus.ContainersStatus { if containerStatus.ID == containerID { - return containerStatus, podStatus.ID, nil + return containerStatus, sandboxStatus.ID, nil } } } @@ -76,7 +76,7 @@ func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) { } func getExistingContainerInfo(containerID string) (vc.ContainerStatus, string, error) { - cStatus, podID, err := getContainerInfo(containerID) + cStatus, sandboxID, err := getContainerInfo(containerID) if err != nil { return vc.ContainerStatus{}, "", err } @@ -86,7 +86,7 @@ func getExistingContainerInfo(containerID string) (vc.ContainerStatus, string, e return vc.ContainerStatus{}, "", fmt.Errorf("Container ID (%v) does not exist", containerID) } - return cStatus, podID, nil + return cStatus, sandboxID, nil } func validCreateParams(containerID, bundlePath string) (string, error) { @@ -130,7 +130,7 @@ func validCreateParams(containerID, bundlePath string) (string, error) { // processCgroupsPath process the cgroups path as expected from the // OCI runtime specification. It returns a list of complete paths // that should be created and used for every specified resource. -func processCgroupsPath(ociSpec oci.CompatOCISpec, isPod bool) ([]string, error) { +func processCgroupsPath(ociSpec oci.CompatOCISpec, isSandbox bool) ([]string, error) { var cgroupsPathList []string if ociSpec.Linux.CgroupsPath == "" { @@ -142,7 +142,7 @@ func processCgroupsPath(ociSpec oci.CompatOCISpec, isPod bool) ([]string, error) } if ociSpec.Linux.Resources.Memory != nil { - memCgroupsPath, err := processCgroupsPathForResource(ociSpec, "memory", isPod) + memCgroupsPath, err := processCgroupsPathForResource(ociSpec, "memory", isSandbox) if err != nil { return []string{}, err } @@ -153,7 +153,7 @@ func processCgroupsPath(ociSpec oci.CompatOCISpec, isPod bool) ([]string, error) } if ociSpec.Linux.Resources.CPU != nil { - cpuCgroupsPath, err := processCgroupsPathForResource(ociSpec, "cpu", isPod) + cpuCgroupsPath, err := processCgroupsPathForResource(ociSpec, "cpu", isSandbox) if err != nil { return []string{}, err } @@ -164,7 +164,7 @@ func processCgroupsPath(ociSpec oci.CompatOCISpec, isPod bool) ([]string, error) } if ociSpec.Linux.Resources.Pids != nil { - pidsCgroupsPath, err := processCgroupsPathForResource(ociSpec, "pids", isPod) + pidsCgroupsPath, err := processCgroupsPathForResource(ociSpec, "pids", isSandbox) if err != nil { return []string{}, err } @@ -175,7 +175,7 @@ func processCgroupsPath(ociSpec oci.CompatOCISpec, isPod bool) ([]string, error) } if ociSpec.Linux.Resources.BlockIO != nil { - blkIOCgroupsPath, err := processCgroupsPathForResource(ociSpec, "blkio", isPod) + blkIOCgroupsPath, err := processCgroupsPathForResource(ociSpec, "blkio", isSandbox) if err != nil { return []string{}, err } @@ -188,7 +188,7 @@ func processCgroupsPath(ociSpec oci.CompatOCISpec, isPod bool) ([]string, error) return cgroupsPathList, nil } -func processCgroupsPathForResource(ociSpec oci.CompatOCISpec, resource string, isPod bool) (string, error) { +func processCgroupsPathForResource(ociSpec oci.CompatOCISpec, resource string, isSandbox bool) (string, error) { if resource == "" { return "", errNeedLinuxResource } diff --git a/cli/oci_test.go b/cli/oci_test.go index c96922d78..d30d46cd5 100644 --- a/cli/oci_test.go +++ b/cli/oci_test.go @@ -83,8 +83,8 @@ func TestGetContainerInfoContainerIDEmptyFailure(t *testing.T) { func TestGetContainerInfo(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } containerID := testContainerID @@ -96,30 +96,30 @@ func TestGetContainerInfo(t *testing.T) { }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{containerStatus}, }, }, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - status, podID, err := getContainerInfo(testContainerID) + status, sandboxID, err := getContainerInfo(testContainerID) assert.NoError(err) - assert.Equal(podID, pod.ID()) + assert.Equal(sandboxID, sandbox.ID()) assert.Equal(status, containerStatus) } func TestGetContainerInfoMismatch(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } containerID := testContainerID + testContainerID @@ -131,22 +131,22 @@ func TestGetContainerInfoMismatch(t *testing.T) { }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{containerStatus}, }, }, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - _, podID, err := getContainerInfo(testContainerID) + _, sandboxID, err := getContainerInfo(testContainerID) assert.NoError(err) - assert.Equal(podID, "") + assert.Equal(sandboxID, "") } func TestValidCreateParamsContainerIDEmptyFailure(t *testing.T) { @@ -170,14 +170,14 @@ func TestValidCreateParamsContainerIDNotUnique(t *testing.T) { containerID := testContainerID + testContainerID - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ // 2 containers with same ID { @@ -198,7 +198,7 @@ func TestValidCreateParamsContainerIDNotUnique(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() _, err := validCreateParams(testContainerID, "") @@ -212,14 +212,14 @@ func TestValidCreateParamsContainerIDNotUnique2(t *testing.T) { containerID := testContainerID + testContainerID - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { ID: containerID, @@ -233,7 +233,7 @@ func TestValidCreateParamsContainerIDNotUnique2(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() _, err := validCreateParams(testContainerID, "") @@ -250,12 +250,12 @@ func TestValidCreateParamsInvalidBundle(t *testing.T) { bundlePath := filepath.Join(tmpdir, "bundle") - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() _, err = validCreateParams(testContainerID, bundlePath) @@ -275,12 +275,12 @@ func TestValidCreateParamsBundleIsAFile(t *testing.T) { err = createEmptyFile(bundlePath) assert.NoError(err) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() _, err = validCreateParams(testContainerID, bundlePath) @@ -376,8 +376,8 @@ func TestProcessCgroupsPathAbsoluteNoCgroupMountDestinationFailure(t *testing.T) for _, d := range cgroupTestData { ociSpec.Linux.Resources = d.linuxSpec - for _, isPod := range []bool{true, false} { - _, err := processCgroupsPath(ociSpec, isPod) + for _, isSandbox := range []bool{true, false} { + _, err := processCgroupsPath(ociSpec, isSandbox) assert.Error(err, "This test should fail because no cgroup mount destination provided") } } @@ -562,8 +562,8 @@ func TestProcessCgroupsPathForResource(t *testing.T) { spec, err := readOCIConfigFile(ociConfigFile) assert.NoError(err) - for _, isPod := range []bool{true, false} { - _, err := processCgroupsPathForResource(spec, "", isPod) + for _, isSandbox := range []bool{true, false} { + _, err := processCgroupsPathForResource(spec, "", isSandbox) assert.Error(err) assert.False(vcmock.IsMockError(err)) } diff --git a/cli/pause.go b/cli/pause.go index 807943f76..912c43706 100644 --- a/cli/pause.go +++ b/cli/pause.go @@ -51,15 +51,15 @@ Where "" is the container name to be resumed.`, func toggleContainerPause(containerID string, pause bool) (err error) { // Checks the MUST and MUST NOT from OCI runtime specification - _, podID, err := getExistingContainerInfo(containerID) + _, sandboxID, err := getExistingContainerInfo(containerID) if err != nil { return err } if pause { - _, err = vci.PausePod(podID) + _, err = vci.PauseSandbox(sandboxID) } else { - _, err = vci.ResumePod(podID) + _, err = vci.ResumeSandbox(sandboxID) } return err diff --git a/cli/pause_test.go b/cli/pause_test.go index 08fd5055f..78fc3381a 100644 --- a/cli/pause_test.go +++ b/cli/pause_test.go @@ -24,12 +24,12 @@ import ( ) var ( - testPausePodFuncReturnNil = func(podID string) (vc.VCPod, error) { - return &vcmock.Pod{}, nil + testPauseSandboxFuncReturnNil = func(sandboxID string) (vc.VCSandbox, error) { + return &vcmock.Sandbox{}, nil } - testResumePodFuncReturnNil = func(podID string) (vc.VCPod, error) { - return &vcmock.Pod{}, nil + testResumeSandboxFuncReturnNil = func(sandboxID string) (vc.VCSandbox, error) { + return &vcmock.Sandbox{}, nil } ) @@ -40,13 +40,13 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) { State: vc.StateRunning, } - testingImpl.PausePodFunc = testPausePodFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { - testingImpl.PausePodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.PauseSandboxFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -58,13 +58,13 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) { func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) { assert := assert.New(t) - testingImpl.PausePodFunc = testPausePodFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.PausePodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.PauseSandboxFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -73,18 +73,18 @@ func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) { execCLICommandFunc(assert, pauseCLICommand, set, true) } -func TestPauseCLIFunctionPausePodFailure(t *testing.T) { +func TestPauseCLIFunctionPauseSandboxFailure(t *testing.T) { assert := assert.New(t) state := vc.State{ State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -100,13 +100,13 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) { State: vc.StateRunning, } - testingImpl.ResumePodFunc = testResumePodFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { - testingImpl.ResumePodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ResumeSandboxFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -118,13 +118,13 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) { func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) { assert := assert.New(t) - testingImpl.ResumePodFunc = testResumePodFuncReturnNil - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ResumePodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.ResumeSandboxFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) @@ -133,18 +133,18 @@ func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) { execCLICommandFunc(assert, resumeCLICommand, set, true) } -func TestResumeCLIFunctionPausePodFailure(t *testing.T) { +func TestResumeCLIFunctionPauseSandboxFailure(t *testing.T) { assert := assert.New(t) state := vc.State{ State: vc.StateRunning, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return newSingleContainerPodStatusList(testPodID, testContainerID, state, state, map[string]string{}), nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() set := flag.NewFlagSet("", 0) diff --git a/cli/ps.go b/cli/ps.go index 280f605c7..0e87a9439 100644 --- a/cli/ps.go +++ b/cli/ps.go @@ -57,7 +57,7 @@ func ps(containerID, format string, args []string) error { } // Checks the MUST and MUST NOT from OCI runtime specification - status, podID, err := getExistingContainerInfo(containerID) + status, sandboxID, err := getExistingContainerInfo(containerID) if err != nil { return err } @@ -78,7 +78,7 @@ func ps(containerID, format string, args []string) error { options.Format = format - msg, err := vci.ProcessListContainer(containerID, podID, options) + msg, err := vci.ProcessListContainer(containerID, sandboxID, options) if err != nil { return err } diff --git a/cli/ps_test.go b/cli/ps_test.go index a5b3d9da4..c9aad8245 100644 --- a/cli/ps_test.go +++ b/cli/ps_test.go @@ -45,25 +45,25 @@ func TestPSCLIAction(t *testing.T) { func TestPSFailure(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ + sandbox := &vcmock.Sandbox{ MockID: testContainerID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: pod.ID(), - MockPod: pod, + MockID: sandbox.ID(), + MockSandbox: sandbox, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // return a podStatus with the container status - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), }, @@ -74,7 +74,7 @@ func TestPSFailure(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() // inexistent container @@ -82,35 +82,35 @@ func TestPSFailure(t *testing.T) { assert.Error(err) // container is not running - err = ps(pod.ID(), "json", []string{"-ef"}) + err = ps(sandbox.ID(), "json", []string{"-ef"}) assert.Error(err) } func TestPSSuccessful(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ + sandbox := &vcmock.Sandbox{ MockID: testContainerID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: pod.ID(), - MockPod: pod, + MockID: sandbox.ID(), + MockSandbox: sandbox, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // return a podStatus with the container status - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { State: vc.State{ State: vc.StateRunning, }, - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), }, @@ -120,15 +120,15 @@ func TestPSSuccessful(t *testing.T) { }, nil } - testingImpl.ProcessListContainerFunc = func(podID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) { + testingImpl.ProcessListContainerFunc = func(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) { return []byte("echo,sleep,grep"), nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil testingImpl.ProcessListContainerFunc = nil }() - err := ps(pod.ID(), "json", []string{}) + err := ps(sandbox.ID(), "json", []string{}) assert.NoError(err) } diff --git a/cli/run.go b/cli/run.go index 979250813..294002aa1 100644 --- a/cli/run.go +++ b/cli/run.go @@ -90,7 +90,7 @@ func run(containerID, bundle, console, consoleSocket, pidFile string, detach boo return err } - pod, err := start(containerID) + sandbox, err := start(containerID) if err != nil { return err } @@ -99,9 +99,9 @@ func run(containerID, bundle, console, consoleSocket, pidFile string, detach boo return nil } - containers := pod.GetAllContainers() + containers := sandbox.GetAllContainers() if len(containers) == 0 { - return fmt.Errorf("There are no containers running in the pod: %s", pod.ID()) + return fmt.Errorf("There are no containers running in the sandbox: %s", sandbox.ID()) } p, err := os.FindProcess(containers[0].GetPid()) @@ -115,7 +115,7 @@ func run(containerID, bundle, console, consoleSocket, pidFile string, detach boo } // delete container's resources - if err := delete(pod.ID(), true); err != nil { + if err := delete(sandbox.ID(), true); err != nil { return err } diff --git a/cli/run_test.go b/cli/run_test.go index 165aecb85..5c43540e2 100644 --- a/cli/run_test.go +++ b/cli/run_test.go @@ -67,30 +67,30 @@ func TestRunCliAction(t *testing.T) { func TestRunInvalidArgs(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, MockContainers: []*vcmock.Container{ {MockID: testContainerID}, }, } // fake functions used to run containers - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return pod, nil + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return sandbox, nil } - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.CreatePodFunc = nil - testingImpl.StartPodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.StartSandboxFunc = nil + testingImpl.ListSandboxFunc = nil }() // temporal dir to place container files @@ -161,7 +161,7 @@ type runContainerData struct { consolePath string bundlePath string configJSON string - pod *vcmock.Pod + sandbox *vcmock.Sandbox runtimeConfig oci.RuntimeConfig process *os.Process tmpDir string @@ -195,16 +195,16 @@ func testRunContainerSetup(t *testing.T) runContainerData { // config json path configPath := filepath.Join(bundlePath, specConfig) - // pod id and container id must be the same otherwise delete will not works - pod := &vcmock.Pod{ + // sandbox id and container id must be the same otherwise delete will not works + sandbox := &vcmock.Sandbox{ MockID: testContainerID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: testContainerID, - MockPid: cmd.Process.Pid, - MockPod: pod, + MockID: testContainerID, + MockPid: cmd.Process.Pid, + MockSandbox: sandbox, }, } @@ -220,7 +220,7 @@ func testRunContainerSetup(t *testing.T) runContainerData { consolePath: consolePath, bundlePath: bundlePath, configJSON: configJSON, - pod: pod, + sandbox: sandbox, runtimeConfig: runtimeConfig, process: cmd.Process, tmpDir: tmpdir, @@ -233,32 +233,32 @@ func TestRunContainerSuccessful(t *testing.T) { d := testRunContainerSetup(t) defer os.RemoveAll(d.tmpDir) - // this flags is used to detect if createPodFunc was called + // this flags is used to detect if createSandboxFunc was called flagCreate := false // fake functions used to run containers - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { flagCreate = true - return d.pod, nil + return d.sandbox, nil } - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { - return d.pod, nil + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return d.sandbox, nil } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { // return an empty list on create if !flagCreate { - return []vc.PodStatus{}, nil + return []vc.SandboxStatus{}, nil } - // return a podStatus with the container status - return []vc.PodStatus{ + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), vcAnnotations.ConfigJSONKey: d.configJSON, @@ -269,32 +269,32 @@ func TestRunContainerSuccessful(t *testing.T) { }, nil } - testingImpl.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { // now we can kill the fake container workload err := d.process.Kill() assert.NoError(err) - return d.pod.MockContainers[0], nil + return d.sandbox.MockContainers[0], nil } - testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) { - return d.pod, nil + testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return d.sandbox, nil } - testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { - return d.pod.MockContainers[0], nil + testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { + return d.sandbox.MockContainers[0], nil } defer func() { - testingImpl.CreatePodFunc = nil - testingImpl.StartPodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.StartSandboxFunc = nil + testingImpl.ListSandboxFunc = nil testingImpl.StartContainerFunc = nil - testingImpl.DeletePodFunc = nil + testingImpl.DeleteSandboxFunc = nil testingImpl.DeleteContainerFunc = nil }() - err := run(d.pod.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) + err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) // should return ExitError with the message and exit code e, ok := err.(*cli.ExitError) @@ -309,32 +309,32 @@ func TestRunContainerDetachSuccessful(t *testing.T) { d := testRunContainerSetup(t) defer os.RemoveAll(d.tmpDir) - // this flags is used to detect if createPodFunc was called + // this flags is used to detect if createSandboxFunc was called flagCreate := false // fake functions used to run containers - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { flagCreate = true - return d.pod, nil + return d.sandbox, nil } - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { - return d.pod, nil + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return d.sandbox, nil } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { // return an empty list on create if !flagCreate { - return []vc.PodStatus{}, nil + return []vc.SandboxStatus{}, nil } - // return a podStatus with the container status - return []vc.PodStatus{ + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), vcAnnotations.ConfigJSONKey: d.configJSON, @@ -345,32 +345,32 @@ func TestRunContainerDetachSuccessful(t *testing.T) { }, nil } - testingImpl.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { // now we can kill the fake container workload err := d.process.Kill() assert.NoError(err) - return d.pod.MockContainers[0], nil + return d.sandbox.MockContainers[0], nil } - testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) { - return d.pod, nil + testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return d.sandbox, nil } - testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { - return d.pod.MockContainers[0], nil + testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { + return d.sandbox.MockContainers[0], nil } defer func() { - testingImpl.CreatePodFunc = nil - testingImpl.StartPodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.StartSandboxFunc = nil + testingImpl.ListSandboxFunc = nil testingImpl.StartContainerFunc = nil - testingImpl.DeletePodFunc = nil + testingImpl.DeleteSandboxFunc = nil testingImpl.DeleteContainerFunc = nil }() - err := run(d.pod.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, true, d.runtimeConfig) + err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, true, d.runtimeConfig) // should not return ExitError assert.NoError(err) @@ -382,32 +382,32 @@ func TestRunContainerDeleteFail(t *testing.T) { d := testRunContainerSetup(t) defer os.RemoveAll(d.tmpDir) - // this flags is used to detect if createPodFunc was called + // this flags is used to detect if createSandboxFunc was called flagCreate := false // fake functions used to run containers - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { flagCreate = true - return d.pod, nil + return d.sandbox, nil } - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { - return d.pod, nil + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return d.sandbox, nil } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { // return an empty list on create if !flagCreate { - return []vc.PodStatus{}, nil + return []vc.SandboxStatus{}, nil } - // return a podStatus with the container status - return []vc.PodStatus{ + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), vcAnnotations.ConfigJSONKey: d.configJSON, @@ -418,34 +418,34 @@ func TestRunContainerDeleteFail(t *testing.T) { }, nil } - testingImpl.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { // now we can kill the fake container workload err := d.process.Kill() assert.NoError(err) - return d.pod.MockContainers[0], nil + return d.sandbox.MockContainers[0], nil } - testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) { + testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { // return an error to provoke a failure in delete - return nil, fmt.Errorf("DeletePodFunc") + return nil, fmt.Errorf("DeleteSandboxFunc") } - testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { // return an error to provoke a failure in delete - return d.pod.MockContainers[0], fmt.Errorf("DeleteContainerFunc") + return d.sandbox.MockContainers[0], fmt.Errorf("DeleteContainerFunc") } defer func() { - testingImpl.CreatePodFunc = nil - testingImpl.StartPodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.StartSandboxFunc = nil + testingImpl.ListSandboxFunc = nil testingImpl.StartContainerFunc = nil - testingImpl.DeletePodFunc = nil + testingImpl.DeleteSandboxFunc = nil testingImpl.DeleteContainerFunc = nil }() - err := run(d.pod.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) + err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) // should not return ExitError err, ok := err.(*cli.ExitError) @@ -458,32 +458,32 @@ func TestRunContainerWaitFail(t *testing.T) { d := testRunContainerSetup(t) defer os.RemoveAll(d.tmpDir) - // this flags is used to detect if createPodFunc was called + // this flags is used to detect if createSandboxFunc was called flagCreate := false // fake functions used to run containers - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { flagCreate = true - return d.pod, nil + return d.sandbox, nil } - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { - return d.pod, nil + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return d.sandbox, nil } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { // return an empty list on create if !flagCreate { - return []vc.PodStatus{}, nil + return []vc.SandboxStatus{}, nil } - // return a podStatus with the container status - return []vc.PodStatus{ + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), vcAnnotations.ConfigJSONKey: d.configJSON, @@ -494,37 +494,37 @@ func TestRunContainerWaitFail(t *testing.T) { }, nil } - testingImpl.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { // now we can kill the fake container workload err := d.process.Kill() assert.NoError(err) // change PID to provoke a failure in Wait - d.pod.MockContainers[0].MockPid = -1 + d.sandbox.MockContainers[0].MockPid = -1 - return d.pod.MockContainers[0], nil + return d.sandbox.MockContainers[0], nil } - testingImpl.DeletePodFunc = func(podID string) (vc.VCPod, error) { + testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { // return an error to provoke a failure in delete - return nil, fmt.Errorf("DeletePodFunc") + return nil, fmt.Errorf("DeleteSandboxFunc") } - testingImpl.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { // return an error to provoke a failure in delete - return d.pod.MockContainers[0], fmt.Errorf("DeleteContainerFunc") + return d.sandbox.MockContainers[0], fmt.Errorf("DeleteContainerFunc") } defer func() { - testingImpl.CreatePodFunc = nil - testingImpl.StartPodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.StartSandboxFunc = nil + testingImpl.ListSandboxFunc = nil testingImpl.StartContainerFunc = nil - testingImpl.DeletePodFunc = nil + testingImpl.DeleteSandboxFunc = nil testingImpl.DeleteContainerFunc = nil }() - err := run(d.pod.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) + err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) // should not return ExitError err, ok := err.(*cli.ExitError) @@ -541,33 +541,33 @@ func TestRunContainerStartFail(t *testing.T) { err := d.process.Kill() assert.NoError(err) - // this flags is used to detect if createPodFunc was called + // this flags is used to detect if createSandboxFunc was called flagCreate := false // fake functions used to run containers - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { flagCreate = true - return d.pod, nil + return d.sandbox, nil } - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { // start fails - return nil, fmt.Errorf("StartPod") + return nil, fmt.Errorf("StartSandbox") } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { // return an empty list on create if !flagCreate { - return []vc.PodStatus{}, nil + return []vc.SandboxStatus{}, nil } - // return a podStatus with the container status - return []vc.PodStatus{ + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: d.pod.ID(), + ID: d.sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), vcAnnotations.ConfigJSONKey: d.configJSON, @@ -579,12 +579,12 @@ func TestRunContainerStartFail(t *testing.T) { } defer func() { - testingImpl.CreatePodFunc = nil - testingImpl.StartPodFunc = nil - testingImpl.ListPodFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.StartSandboxFunc = nil + testingImpl.ListSandboxFunc = nil }() - err = run(d.pod.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) + err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) // should not return ExitError err, ok := err.(*cli.ExitError) @@ -599,27 +599,27 @@ func TestRunContainerStartFailNoContainers(t *testing.T) { d := testRunContainerSetup(t) defer os.RemoveAll(d.tmpDir) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: testContainerID, - MockPod: pod, + MockID: testContainerID, + MockSandbox: sandbox, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { listCallCount++ if listCallCount == 1 { - return []vc.PodStatus{}, nil + return []vc.SandboxStatus{}, nil } - return []vc.PodStatus{ + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { ID: testContainerID, @@ -632,24 +632,24 @@ func TestRunContainerStartFailNoContainers(t *testing.T) { }, nil } - testingImpl.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return pod, nil + testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return sandbox, nil } - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { // force no containers - pod.MockContainers = nil + sandbox.MockContainers = nil - return pod, nil + return sandbox, nil } defer func() { - testingImpl.ListPodFunc = nil - testingImpl.CreatePodFunc = nil - testingImpl.StartPodFunc = nil + testingImpl.ListSandboxFunc = nil + testingImpl.CreateSandboxFunc = nil + testingImpl.StartSandboxFunc = nil }() - err := run(d.pod.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) + err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig) assert.Error(err) assert.False(vcmock.IsMockError(err)) } diff --git a/cli/start.go b/cli/start.go index a80096107..afa7ecf9a 100644 --- a/cli/start.go +++ b/cli/start.go @@ -48,9 +48,9 @@ var startCLICommand = cli.Command{ }, } -func start(containerID string) (vc.VCPod, error) { +func start(containerID string) (vc.VCSandbox, error) { // Checks the MUST and MUST NOT from OCI runtime specification - status, podID, err := getExistingContainerInfo(containerID) + status, sandboxID, err := getExistingContainerInfo(containerID) if err != nil { return nil, err } @@ -62,14 +62,14 @@ func start(containerID string) (vc.VCPod, error) { return nil, err } - if containerType.IsPod() { - return vci.StartPod(podID) + if containerType.IsSandbox() { + return vci.StartSandbox(sandboxID) } - c, err := vci.StartContainer(podID, containerID) + c, err := vci.StartContainer(sandboxID, containerID) if err != nil { return nil, err } - return c.Pod(), nil + return c.Sandbox(), nil } diff --git a/cli/start_test.go b/cli/start_test.go index 2bbb6e4c0..0016c10ac 100644 --- a/cli/start_test.go +++ b/cli/start_test.go @@ -33,39 +33,39 @@ func TestStartInvalidArgs(t *testing.T) { assert.Error(err) assert.False(vcmock.IsMockError(err)) - // Mock Listpod error + // Mock Listsandbox error _, err = start(testContainerID) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - // Container missing in ListPod + // Container missing in ListSandbox _, err = start(testContainerID) assert.Error(err) assert.False(vcmock.IsMockError(err)) } -func TestStartPod(t *testing.T) { +func TestStartSandbox(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodSandbox), }, @@ -76,39 +76,39 @@ func TestStartPod(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - _, err := start(pod.ID()) + _, err := start(sandbox.ID()) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.StartPodFunc = func(podID string) (vc.VCPod, error) { - return pod, nil + testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return sandbox, nil } defer func() { - testingImpl.StartPodFunc = nil + testingImpl.StartSandboxFunc = nil }() - _, err = start(pod.ID()) + _, err = start(sandbox.ID()) assert.Nil(err) } func TestStartMissingAnnotation(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{}, }, }, @@ -117,10 +117,10 @@ func TestStartMissingAnnotation(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() - _, err := start(pod.ID()) + _, err := start(sandbox.ID()) assert.Error(err) assert.False(vcmock.IsMockError(err)) } @@ -128,21 +128,21 @@ func TestStartMissingAnnotation(t *testing.T) { func TestStartContainerSucessFailure(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: testContainerID, - MockPod: pod, + MockID: testContainerID, + MockSandbox: sandbox, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { ID: testContainerID, @@ -156,15 +156,15 @@ func TestStartContainerSucessFailure(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() _, err := start(testContainerID) assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { - return pod.MockContainers[0], nil + testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { + return sandbox.MockContainers[0], nil } defer func() { @@ -203,21 +203,21 @@ func TestStartCLIFunction(t *testing.T) { func TestStartCLIFunctionSuccess(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ - MockID: testPodID, + sandbox := &vcmock.Sandbox{ + MockID: testSandboxID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: testContainerID, - MockPod: pod, + MockID: testContainerID, + MockSandbox: sandbox, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { ID: testContainerID, @@ -230,12 +230,12 @@ func TestStartCLIFunctionSuccess(t *testing.T) { }, nil } - testingImpl.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { - return pod.MockContainers[0], nil + testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { + return sandbox.MockContainers[0], nil } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil testingImpl.StartContainerFunc = nil }() diff --git a/cli/state_test.go b/cli/state_test.go index a33f3d199..8e066aff0 100644 --- a/cli/state_test.go +++ b/cli/state_test.go @@ -49,25 +49,25 @@ func TestStateCliAction(t *testing.T) { func TestStateSuccessful(t *testing.T) { assert := assert.New(t) - pod := &vcmock.Pod{ + sandbox := &vcmock.Sandbox{ MockID: testContainerID, } - pod.MockContainers = []*vcmock.Container{ + sandbox.MockContainers = []*vcmock.Container{ { - MockID: pod.ID(), - MockPod: pod, + MockID: sandbox.ID(), + MockSandbox: sandbox, }, } - testingImpl.ListPodFunc = func() ([]vc.PodStatus, error) { - // return a podStatus with the container status - return []vc.PodStatus{ + testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + // return a sandboxStatus with the container status + return []vc.SandboxStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), ContainersStatus: []vc.ContainerStatus{ { - ID: pod.ID(), + ID: sandbox.ID(), Annotations: map[string]string{ vcAnnotations.ContainerTypeKey: string(vc.PodContainer), }, @@ -78,13 +78,13 @@ func TestStateSuccessful(t *testing.T) { } defer func() { - testingImpl.ListPodFunc = nil + testingImpl.ListSandboxFunc = nil }() // trying with an inexistent id err := state("123456789") assert.Error(err) - err = state(pod.ID()) + err = state(sandbox.ID()) assert.NoError(err) } diff --git a/virtcontainers/README.md b/virtcontainers/README.md index 284c2e957..846afa853 100644 --- a/virtcontainers/README.md +++ b/virtcontainers/README.md @@ -14,13 +14,13 @@ Table of Contents * [Out of scope](#out-of-scope) * [virtcontainers and Kubernetes CRI](#virtcontainers-and-kubernetes-cri) * [Design](#design) - * [Pods](#pods) + * [Sandboxes](#sandboxes) * [Hypervisors](#hypervisors) * [Agents](#agents) * [Shim](#shim) * [Proxy](#proxy) * [API](#api) - * [Pod API](#pod-api) + * [Sandbox API](#sandbox-api) * [Container API](#container-api) * [Networking](#networking) * [CNM](#cnm) @@ -64,7 +64,7 @@ testing purposes. ## virtcontainers and Kubernetes CRI `virtcontainers`'s API is loosely inspired by the Kubernetes [CRI][cri] because -we believe it provides the right level of abstractions for containerized pods. +we believe it provides the right level of abstractions for containerized sandboxes. However, despite the API similarities between the two projects, the goal of `virtcontainers` is _not_ to build a CRI implementation, but instead to provide a generic, runtime-specification agnostic, hardware-virtualized containers @@ -72,19 +72,19 @@ library that other projects could leverage to implement CRI themselves. # Design -## Pods +## Sandboxes -The `virtcontainers` execution unit is a _pod_, i.e. `virtcontainers` users start pods where +The `virtcontainers` execution unit is a _sandbox_, i.e. `virtcontainers` users start sandboxes where containers will be running. -`virtcontainers` creates a pod by starting a virtual machine and setting the pod -up within that environment. Starting a pod means launching all containers with -the VM pod runtime environment. +`virtcontainers` creates a sandbox by starting a virtual machine and setting the sandbox +up within that environment. Starting a sandbox means launching all containers with +the VM sandbox runtime environment. ## Hypervisors The `virtcontainers` package relies on hypervisors to start and stop virtual machine where -pods will be running. An hypervisor is defined by an Hypervisor interface implementation, +sandboxes will be running. An hypervisor is defined by an Hypervisor interface implementation, and the default implementation is the QEMU one. ## Agents @@ -115,50 +115,50 @@ runtime instances are talking to the same container. The high level `virtcontainers` API is the following one: -## Pod API +## Sandbox API -* `CreatePod(podConfig PodConfig)` creates a Pod. -The virtual machine is started and the Pod is prepared. +* `CreateSandbox(sandboxConfig SandboxConfig)` creates a Sandbox. +The virtual machine is started and the Sandbox is prepared. -* `DeletePod(podID string)` deletes a Pod. -The virtual machine is shut down and all information related to the Pod are removed. -The function will fail if the Pod is running. In that case `StopPod()` has to be called first. +* `DeleteSandbox(sandboxID string)` deletes a Sandbox. +The virtual machine is shut down and all information related to the Sandbox are removed. +The function will fail if the Sandbox is running. In that case `StopSandbox()` has to be called first. -* `StartPod(podID string)` starts an already created Pod. -The Pod and all its containers are started. +* `StartSandbox(sandboxID string)` starts an already created Sandbox. +The Sandbox and all its containers are started. -* `RunPod(podConfig PodConfig)` creates and starts a Pod. -This performs `CreatePod()` + `StartPod()`. +* `RunSandbox(sandboxConfig SandboxConfig)` creates and starts a Sandbox. +This performs `CreateSandbox()` + `StartSandbox()`. -* `StopPod(podID string)` stops an already running Pod. -The Pod and all its containers are stopped. +* `StopSandbox(sandboxID string)` stops an already running Sandbox. +The Sandbox and all its containers are stopped. -* `PausePod(podID string)` pauses an existing Pod. +* `PauseSandbox(sandboxID string)` pauses an existing Sandbox. -* `ResumePod(podID string)` resume a paused Pod. +* `ResumeSandbox(sandboxID string)` resume a paused Sandbox. -* `StatusPod(podID string)` returns a detailed Pod status. +* `StatusSandbox(sandboxID string)` returns a detailed Sandbox status. -* `ListPod()` lists all Pods on the host. -It returns a detailed status for every Pod. +* `ListSandbox()` lists all Sandboxes on the host. +It returns a detailed status for every Sandbox. ## Container API -* `CreateContainer(podID string, containerConfig ContainerConfig)` creates a Container on an existing Pod. +* `CreateContainer(sandboxID string, containerConfig ContainerConfig)` creates a Container on an existing Sandbox. -* `DeleteContainer(podID, containerID string)` deletes a Container from a Pod. +* `DeleteContainer(sandboxID, containerID string)` deletes a Container from a Sandbox. If the Container is running it has to be stopped first. -* `StartContainer(podID, containerID string)` starts an already created Container. -The Pod has to be running. +* `StartContainer(sandboxID, containerID string)` starts an already created Container. +The Sandbox has to be running. -* `StopContainer(podID, containerID string)` stops an already running Container. +* `StopContainer(sandboxID, containerID string)` stops an already running Container. -* `EnterContainer(podID, containerID string, cmd Cmd)` enters an already running Container and runs a given command. +* `EnterContainer(sandboxID, containerID string, cmd Cmd)` enters an already running Container and runs a given command. -* `StatusContainer(podID, containerID string)` returns a detailed Container status. +* `StatusContainer(sandboxID, containerID string)` returns a detailed Container status. -* `KillContainer(podID, containerID string, signal syscall.Signal, all bool)` sends a signal to all or one container inside a Pod. +* `KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool)` sends a signal to all or one container inside a Sandbox. An example tool using the `virtcontainers` API is provided in the `hack/virtc` package. @@ -168,7 +168,7 @@ An example tool using the `virtcontainers` API is provided in the `hack/virtc` p Typically the former is the Docker default networking model while the later is used on Kubernetes deployments. -`virtcontainers` callers can select one or the other, on a per pod basis, by setting their `PodConfig`'s `NetworkModel` field properly. +`virtcontainers` callers can select one or the other, on a per sandbox basis, by setting their `SandboxConfig`'s `NetworkModel` field properly. [cnm]: https://github.com/docker/libnetwork/blob/master/docs/design.md [cni]: https://github.com/containernetworking/cni/ @@ -224,7 +224,7 @@ __Drawbacks of CNM__ There are three drawbacks about using CNM instead of CNI: * The way we call into it is not very explicit: Have to re-exec dockerd binary so that it can accept parameters and execute the prestart hook related to network setup. * Implicit way to designate the network namespace: Instead of explicitely giving the netns to dockerd, we give it the PID of our runtime so that it can find the netns from this PID. This means we have to make sure being in the right netns while calling the hook, otherwise the veth pair will be created with the wrong netns. -* No results are back from the hook: We have to scan the network interfaces to discover which one has been created inside the netns. This introduces more latency in the code because it forces us to scan the network in the CreatePod path, which is critical for starting the VM as quick as possible. +* No results are back from the hook: We have to scan the network interfaces to discover which one has been created inside the netns. This introduces more latency in the code because it forces us to scan the network in the CreateSandbox path, which is critical for starting the VM as quick as possible. ## CNI diff --git a/virtcontainers/agent.go b/virtcontainers/agent.go index a25e4d484..52e19dfba 100644 --- a/virtcontainers/agent.go +++ b/virtcontainers/agent.go @@ -23,7 +23,7 @@ import ( "github.com/mitchellh/mapstructure" ) -// AgentType describes the type of guest agent a Pod should run. +// AgentType describes the type of guest agent a Sandbox should run. type AgentType string // ProcessListOptions contains the options used to list running @@ -105,8 +105,8 @@ func newAgent(agentType AgentType) agent { } } -// newAgentConfig returns an agent config from a generic PodConfig interface. -func newAgentConfig(config PodConfig) interface{} { +// newAgentConfig returns an agent config from a generic SandboxConfig interface. +func newAgentConfig(config SandboxConfig) interface{} { switch config.AgentType { case NoopAgentType: return nil @@ -138,42 +138,42 @@ type agent interface { // init(). // After init() is called, agent implementations should be initialized and ready // to handle all other Agent interface methods. - init(pod *Pod, config interface{}) error + init(sandbox *Sandbox, config interface{}) error // capabilities should return a structure that specifies the capabilities // supported by the agent. capabilities() capabilities - // createPod will tell the agent to perform necessary setup for a Pod. - createPod(pod *Pod) error + // createSandbox will tell the agent to perform necessary setup for a Sandbox. + createSandbox(sandbox *Sandbox) error // exec will tell the agent to run a command in an already running container. - exec(pod *Pod, c Container, cmd Cmd) (*Process, error) + exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) - // startPod will tell the agent to start all containers related to the Pod. - startPod(pod Pod) error + // startSandbox will tell the agent to start all containers related to the Sandbox. + startSandbox(sandbox Sandbox) error - // stopPod will tell the agent to stop all containers related to the Pod. - stopPod(pod Pod) error + // stopSandbox will tell the agent to stop all containers related to the Sandbox. + stopSandbox(sandbox Sandbox) error - // createContainer will tell the agent to create a container related to a Pod. - createContainer(pod *Pod, c *Container) (*Process, error) + // createContainer will tell the agent to create a container related to a Sandbox. + createContainer(sandbox *Sandbox, c *Container) (*Process, error) - // startContainer will tell the agent to start a container related to a Pod. - startContainer(pod Pod, c *Container) error + // startContainer will tell the agent to start a container related to a Sandbox. + startContainer(sandbox Sandbox, c *Container) error - // stopContainer will tell the agent to stop a container related to a Pod. - stopContainer(pod Pod, c Container) error + // stopContainer will tell the agent to stop a container related to a Sandbox. + stopContainer(sandbox Sandbox, c Container) error // killContainer will tell the agent to send a signal to a - // container related to a Pod. If all is true, all processes in + // container related to a Sandbox. If all is true, all processes in // the container will be sent the signal. - killContainer(pod Pod, c Container, signal syscall.Signal, all bool) error + killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error // processListContainer will list the processes running inside the container - processListContainer(pod Pod, c Container, options ProcessListOptions) (ProcessList, error) + processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) - // onlineCPUMem will online CPUs and Memory inside the Pod. + // onlineCPUMem will online CPUs and Memory inside the Sandbox. // This function should be called after hot adding vCPUs or Memory. onlineCPUMem() error } diff --git a/virtcontainers/agent_test.go b/virtcontainers/agent_test.go index 2b8815c22..b65e06fdc 100644 --- a/virtcontainers/agent_test.go +++ b/virtcontainers/agent_test.go @@ -109,7 +109,7 @@ func TestNewAgentFromUnknownAgentType(t *testing.T) { testNewAgentFromAgentType(t, agentType, &noopAgent{}) } -func testNewAgentConfig(t *testing.T, config PodConfig, expected interface{}) { +func testNewAgentConfig(t *testing.T, config SandboxConfig, expected interface{}) { agentConfig := newAgentConfig(config) if reflect.DeepEqual(agentConfig, expected) == false { t.Fatal() @@ -119,38 +119,38 @@ func testNewAgentConfig(t *testing.T, config PodConfig, expected interface{}) { func TestNewAgentConfigFromNoopAgentType(t *testing.T) { var agentConfig interface{} - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ AgentType: NoopAgentType, AgentConfig: agentConfig, } - testNewAgentConfig(t, podConfig, agentConfig) + testNewAgentConfig(t, sandboxConfig, agentConfig) } func TestNewAgentConfigFromHyperstartAgentType(t *testing.T) { agentConfig := HyperConfig{} - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ AgentType: HyperstartAgent, AgentConfig: agentConfig, } - testNewAgentConfig(t, podConfig, agentConfig) + testNewAgentConfig(t, sandboxConfig, agentConfig) } func TestNewAgentConfigFromKataAgentType(t *testing.T) { agentConfig := KataAgentConfig{} - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ AgentType: KataContainersAgent, AgentConfig: agentConfig, } - testNewAgentConfig(t, podConfig, agentConfig) + testNewAgentConfig(t, sandboxConfig, agentConfig) } func TestNewAgentConfigFromUnknownAgentType(t *testing.T) { var agentConfig interface{} - testNewAgentConfig(t, PodConfig{}, agentConfig) + testNewAgentConfig(t, SandboxConfig{}, agentConfig) } diff --git a/virtcontainers/api.go b/virtcontainers/api.go index 4dfebe24d..8f73e4ec6 100644 --- a/virtcontainers/api.go +++ b/virtcontainers/api.go @@ -40,20 +40,20 @@ func SetLogger(logger logrus.FieldLogger) { virtLog = logger.WithFields(fields) } -// CreatePod is the virtcontainers pod creation entry point. -// CreatePod creates a pod and its containers. It does not start them. -func CreatePod(podConfig PodConfig) (VCPod, error) { - return createPodFromConfig(podConfig) +// CreateSandbox is the virtcontainers sandbox creation entry point. +// CreateSandbox creates a sandbox and its containers. It does not start them. +func CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) { + return createSandboxFromConfig(sandboxConfig) } -func createPodFromConfig(podConfig PodConfig) (*Pod, error) { - // Create the pod. - p, err := createPod(podConfig) +func createSandboxFromConfig(sandboxConfig SandboxConfig) (*Sandbox, error) { + // Create the sandbox. + p, err := createSandbox(sandboxConfig) if err != nil { return nil, err } - // Create the pod network + // Create the sandbox network if err := p.createNetwork(); err != nil { return nil, err } @@ -68,29 +68,29 @@ func createPodFromConfig(podConfig PodConfig) (*Pod, error) { return nil, err } - // The pod is completely created now, we can store it. - if err := p.storePod(); err != nil { + // The sandbox is completely created now, we can store it. + if err := p.storeSandbox(); err != nil { return nil, err } return p, nil } -// DeletePod is the virtcontainers pod deletion entry point. -// DeletePod will stop an already running container and then delete it. -func DeletePod(podID string) (VCPod, error) { - if podID == "" { - return nil, errNeedPodID +// DeleteSandbox is the virtcontainers sandbox deletion entry point. +// DeleteSandbox will stop an already running container and then delete it. +func DeleteSandbox(sandboxID string) (VCSandbox, error) { + if sandboxID == "" { + return nil, errNeedSandboxID } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - // Fetch the pod from storage and create it. - p, err := fetchPod(podID) + // Fetch the sandbox from storage and create it. + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } @@ -103,31 +103,31 @@ func DeletePod(podID string) (VCPod, error) { return p, nil } -// StartPod is the virtcontainers pod starting entry point. -// StartPod will talk to the given hypervisor to start an existing -// pod and all its containers. -// It returns the pod ID. -func StartPod(podID string) (VCPod, error) { - if podID == "" { - return nil, errNeedPodID +// StartSandbox is the virtcontainers sandbox starting entry point. +// StartSandbox will talk to the given hypervisor to start an existing +// sandbox and all its containers. +// It returns the sandbox ID. +func StartSandbox(sandboxID string) (VCSandbox, error) { + if sandboxID == "" { + return nil, errNeedSandboxID } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - // Fetch the pod from storage and create it. - p, err := fetchPod(podID) + // Fetch the sandbox from storage and create it. + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } - return startPod(p) + return startSandbox(p) } -func startPod(p *Pod) (*Pod, error) { +func startSandbox(p *Sandbox) (*Sandbox, error) { // Start it err := p.start() if err != nil { @@ -142,21 +142,21 @@ func startPod(p *Pod) (*Pod, error) { return p, nil } -// StopPod is the virtcontainers pod stopping entry point. -// StopPod will talk to the given agent to stop an existing pod and destroy all containers within that pod. -func StopPod(podID string) (VCPod, error) { - if podID == "" { - return nil, errNeedPod +// StopSandbox is the virtcontainers sandbox stopping entry point. +// StopSandbox will talk to the given agent to stop an existing sandbox and destroy all containers within that sandbox. +func StopSandbox(sandboxID string) (VCSandbox, error) { + if sandboxID == "" { + return nil, errNeedSandbox } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - // Fetch the pod from storage and create it. - p, err := fetchPod(podID) + // Fetch the sandbox from storage and create it. + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } @@ -180,70 +180,70 @@ func StopPod(podID string) (VCPod, error) { return p, nil } -// RunPod is the virtcontainers pod running entry point. -// RunPod creates a pod and its containers and then it starts them. -func RunPod(podConfig PodConfig) (VCPod, error) { - p, err := createPodFromConfig(podConfig) +// RunSandbox is the virtcontainers sandbox running entry point. +// RunSandbox creates a sandbox and its containers and then it starts them. +func RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) { + p, err := createSandboxFromConfig(sandboxConfig) if err != nil { return nil, err } - lockFile, err := rwLockPod(p.id) + lockFile, err := rwLockSandbox(p.id) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - return startPod(p) + return startSandbox(p) } -// ListPod is the virtcontainers pod listing entry point. -func ListPod() ([]PodStatus, error) { +// ListSandbox is the virtcontainers sandbox listing entry point. +func ListSandbox() ([]SandboxStatus, error) { dir, err := os.Open(configStoragePath) if err != nil { if os.IsNotExist(err) { - // No pod directory is not an error - return []PodStatus{}, nil + // No sandbox directory is not an error + return []SandboxStatus{}, nil } - return []PodStatus{}, err + return []SandboxStatus{}, err } defer dir.Close() - podsID, err := dir.Readdirnames(0) + sandboxesID, err := dir.Readdirnames(0) if err != nil { - return []PodStatus{}, err + return []SandboxStatus{}, err } - var podStatusList []PodStatus + var sandboxStatusList []SandboxStatus - for _, podID := range podsID { - podStatus, err := StatusPod(podID) + for _, sandboxID := range sandboxesID { + sandboxStatus, err := StatusSandbox(sandboxID) if err != nil { continue } - podStatusList = append(podStatusList, podStatus) + sandboxStatusList = append(sandboxStatusList, sandboxStatus) } - return podStatusList, nil + return sandboxStatusList, nil } -// StatusPod is the virtcontainers pod status entry point. -func StatusPod(podID string) (PodStatus, error) { - if podID == "" { - return PodStatus{}, errNeedPodID +// StatusSandbox is the virtcontainers sandbox status entry point. +func StatusSandbox(sandboxID string) (SandboxStatus, error) { + if sandboxID == "" { + return SandboxStatus{}, errNeedSandboxID } - lockFile, err := rLockPod(podID) + lockFile, err := rLockSandbox(sandboxID) if err != nil { - return PodStatus{}, err + return SandboxStatus{}, err } - pod, err := fetchPod(podID) + sandbox, err := fetchSandbox(sandboxID) if err != nil { - unlockPod(lockFile) - return PodStatus{}, err + unlockSandbox(lockFile) + return SandboxStatus{}, err } // We need to potentially wait for a separate container.stop() routine @@ -253,46 +253,46 @@ func StatusPod(podID string) (PodStatus, error) { // will need to lock an exclusive lock, meaning that all other locks have // to be released to let this happen. This call ensures this will be the // last operation executed by this function. - defer pod.wg.Wait() - defer unlockPod(lockFile) + defer sandbox.wg.Wait() + defer unlockSandbox(lockFile) var contStatusList []ContainerStatus - for _, container := range pod.containers { - contStatus, err := statusContainer(pod, container.id) + for _, container := range sandbox.containers { + contStatus, err := statusContainer(sandbox, container.id) if err != nil { - return PodStatus{}, err + return SandboxStatus{}, err } contStatusList = append(contStatusList, contStatus) } - podStatus := PodStatus{ - ID: pod.id, - State: pod.state, - Hypervisor: pod.config.HypervisorType, - HypervisorConfig: pod.config.HypervisorConfig, - Agent: pod.config.AgentType, + sandboxStatus := SandboxStatus{ + ID: sandbox.id, + State: sandbox.state, + Hypervisor: sandbox.config.HypervisorType, + HypervisorConfig: sandbox.config.HypervisorConfig, + Agent: sandbox.config.AgentType, ContainersStatus: contStatusList, - Annotations: pod.config.Annotations, + Annotations: sandbox.config.Annotations, } - return podStatus, nil + return sandboxStatus, nil } // CreateContainer is the virtcontainers container creation entry point. -// CreateContainer creates a container on a given pod. -func CreateContainer(podID string, containerConfig ContainerConfig) (VCPod, VCContainer, error) { - if podID == "" { - return nil, nil, errNeedPodID +// CreateContainer creates a container on a given sandbox. +func CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) { + if sandboxID == "" { + return nil, nil, errNeedSandboxID } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - p, err := fetchPod(podID) + p, err := fetchSandbox(sandboxID) if err != nil { return nil, nil, err } @@ -303,7 +303,7 @@ func CreateContainer(podID string, containerConfig ContainerConfig) (VCPod, VCCo return nil, nil, err } - // Add the container to the containers list in the pod. + // Add the container to the containers list in the sandbox. if err := p.addContainer(c); err != nil { return nil, nil, err } @@ -314,9 +314,9 @@ func CreateContainer(podID string, containerConfig ContainerConfig) (VCPod, VCCo return nil, nil, err } - // Update pod config. + // Update sandbox config. p.config.Containers = append(p.config.Containers, containerConfig) - err = p.storage.storePodResource(podID, configFileType, *(p.config)) + err = p.storage.storeSandboxResource(sandboxID, configFileType, *(p.config)) if err != nil { return nil, nil, err } @@ -325,24 +325,24 @@ func CreateContainer(podID string, containerConfig ContainerConfig) (VCPod, VCCo } // DeleteContainer is the virtcontainers container deletion entry point. -// DeleteContainer deletes a Container from a Pod. If the container is running, +// DeleteContainer deletes a Container from a Sandbox. If the container is running, // it needs to be stopped first. -func DeleteContainer(podID, containerID string) (VCContainer, error) { - if podID == "" { - return nil, errNeedPodID +func DeleteContainer(sandboxID, containerID string) (VCContainer, error) { + if sandboxID == "" { + return nil, errNeedSandboxID } if containerID == "" { return nil, errNeedContainerID } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - p, err := fetchPod(podID) + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } @@ -359,14 +359,14 @@ func DeleteContainer(podID, containerID string) (VCContainer, error) { return nil, err } - // Update pod config + // Update sandbox config for idx, contConfig := range p.config.Containers { if contConfig.ID == containerID { p.config.Containers = append(p.config.Containers[:idx], p.config.Containers[idx+1:]...) break } } - err = p.storage.storePodResource(podID, configFileType, *(p.config)) + err = p.storage.storeSandboxResource(sandboxID, configFileType, *(p.config)) if err != nil { return nil, err } @@ -376,22 +376,22 @@ func DeleteContainer(podID, containerID string) (VCContainer, error) { // StartContainer is the virtcontainers container starting entry point. // StartContainer starts an already created container. -func StartContainer(podID, containerID string) (VCContainer, error) { - if podID == "" { - return nil, errNeedPodID +func StartContainer(sandboxID, containerID string) (VCContainer, error) { + if sandboxID == "" { + return nil, errNeedSandboxID } if containerID == "" { return nil, errNeedContainerID } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - p, err := fetchPod(podID) + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } @@ -413,22 +413,22 @@ func StartContainer(podID, containerID string) (VCContainer, error) { // StopContainer is the virtcontainers container stopping entry point. // StopContainer stops an already running container. -func StopContainer(podID, containerID string) (VCContainer, error) { - if podID == "" { - return nil, errNeedPodID +func StopContainer(sandboxID, containerID string) (VCContainer, error) { + if sandboxID == "" { + return nil, errNeedSandboxID } if containerID == "" { return nil, errNeedContainerID } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - p, err := fetchPod(podID) + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } @@ -450,22 +450,22 @@ func StopContainer(podID, containerID string) (VCContainer, error) { // EnterContainer is the virtcontainers container command execution entry point. // EnterContainer enters an already running container and runs a given command. -func EnterContainer(podID, containerID string, cmd Cmd) (VCPod, VCContainer, *Process, error) { - if podID == "" { - return nil, nil, nil, errNeedPodID +func EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) { + if sandboxID == "" { + return nil, nil, nil, errNeedSandboxID } if containerID == "" { return nil, nil, nil, errNeedContainerID } - lockFile, err := rLockPod(podID) + lockFile, err := rLockSandbox(sandboxID) if err != nil { return nil, nil, nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - p, err := fetchPod(podID) + p, err := fetchSandbox(sandboxID) if err != nil { return nil, nil, nil, err } @@ -487,23 +487,23 @@ func EnterContainer(podID, containerID string, cmd Cmd) (VCPod, VCContainer, *Pr // StatusContainer is the virtcontainers container status entry point. // StatusContainer returns a detailed container status. -func StatusContainer(podID, containerID string) (ContainerStatus, error) { - if podID == "" { - return ContainerStatus{}, errNeedPodID +func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) { + if sandboxID == "" { + return ContainerStatus{}, errNeedSandboxID } if containerID == "" { return ContainerStatus{}, errNeedContainerID } - lockFile, err := rLockPod(podID) + lockFile, err := rLockSandbox(sandboxID) if err != nil { return ContainerStatus{}, err } - pod, err := fetchPod(podID) + sandbox, err := fetchSandbox(sandboxID) if err != nil { - unlockPod(lockFile) + unlockSandbox(lockFile) return ContainerStatus{}, err } @@ -514,16 +514,16 @@ func StatusContainer(podID, containerID string) (ContainerStatus, error) { // will need to lock an exclusive lock, meaning that all other locks have // to be released to let this happen. This call ensures this will be the // last operation executed by this function. - defer pod.wg.Wait() - defer unlockPod(lockFile) + defer sandbox.wg.Wait() + defer unlockSandbox(lockFile) - return statusContainer(pod, containerID) + return statusContainer(sandbox, containerID) } // This function is going to spawn a goroutine and it needs to be waited for // by the caller. -func statusContainer(pod *Pod, containerID string) (ContainerStatus, error) { - for _, container := range pod.containers { +func statusContainer(sandbox *Sandbox, containerID string) (ContainerStatus, error) { + for _, container := range sandbox.containers { if container.id == containerID { // We have to check for the process state to make sure // we update the status in case the process is supposed @@ -539,14 +539,14 @@ func statusContainer(pod *Pod, containerID string) (ContainerStatus, error) { } if !running { - pod.wg.Add(1) + sandbox.wg.Add(1) go func() { - defer pod.wg.Done() - lockFile, err := rwLockPod(pod.id) + defer sandbox.wg.Done() + lockFile, err := rwLockSandbox(sandbox.id) if err != nil { return } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) if err := container.stop(); err != nil { return @@ -566,29 +566,29 @@ func statusContainer(pod *Pod, containerID string) (ContainerStatus, error) { } } - // No matching containers in the pod + // No matching containers in the sandbox return ContainerStatus{}, nil } // KillContainer is the virtcontainers entry point to send a signal -// to a container running inside a pod. If all is true, all processes in +// to a container running inside a sandbox. If all is true, all processes in // the container will be sent the signal. -func KillContainer(podID, containerID string, signal syscall.Signal, all bool) error { - if podID == "" { - return errNeedPodID +func KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error { + if sandboxID == "" { + return errNeedSandboxID } if containerID == "" { return errNeedContainerID } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - p, err := fetchPod(podID) + p, err := fetchSandbox(sandboxID) if err != nil { return err } @@ -608,36 +608,36 @@ func KillContainer(podID, containerID string, signal syscall.Signal, all bool) e return nil } -// PausePod is the virtcontainers pausing entry point which pauses an -// already running pod. -func PausePod(podID string) (VCPod, error) { - return togglePausePod(podID, true) +// PauseSandbox is the virtcontainers pausing entry point which pauses an +// already running sandbox. +func PauseSandbox(sandboxID string) (VCSandbox, error) { + return togglePauseSandbox(sandboxID, true) } -// ResumePod is the virtcontainers resuming entry point which resumes -// (or unpauses) and already paused pod. -func ResumePod(podID string) (VCPod, error) { - return togglePausePod(podID, false) +// ResumeSandbox is the virtcontainers resuming entry point which resumes +// (or unpauses) and already paused sandbox. +func ResumeSandbox(sandboxID string) (VCSandbox, error) { + return togglePauseSandbox(sandboxID, false) } // ProcessListContainer is the virtcontainers entry point to list // processes running inside a container -func ProcessListContainer(podID, containerID string, options ProcessListOptions) (ProcessList, error) { - if podID == "" { - return nil, errNeedPodID +func ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) { + if sandboxID == "" { + return nil, errNeedSandboxID } if containerID == "" { return nil, errNeedContainerID } - lockFile, err := rLockPod(podID) + lockFile, err := rLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - p, err := fetchPod(podID) + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } diff --git a/virtcontainers/api_test.go b/virtcontainers/api_test.go index cf5b96838..788a74cd9 100644 --- a/virtcontainers/api_test.go +++ b/virtcontainers/api_test.go @@ -35,9 +35,9 @@ const ( containerID = "1" ) -var podAnnotations = map[string]string{ - "pod.foo": "pod.bar", - "pod.hello": "pod.world", +var sandboxAnnotations = map[string]string{ + "sandbox.foo": "sandbox.bar", + "sandbox.hello": "sandbox.world", } var containerAnnotations = map[string]string{ @@ -62,7 +62,7 @@ func newBasicTestCmd() Cmd { return cmd } -func newTestPodConfigNoop() PodConfig { +func newTestSandboxConfigNoop() SandboxConfig { // Define the container command and bundle. container := ContainerConfig{ ID: containerID, @@ -78,8 +78,8 @@ func newTestPodConfigNoop() PodConfig { HypervisorPath: filepath.Join(testDir, testHypervisor), } - podConfig := PodConfig{ - ID: testPodID, + sandboxConfig := SandboxConfig{ + ID: testSandboxID, HypervisorType: MockHypervisor, HypervisorConfig: hypervisorConfig, @@ -87,13 +87,13 @@ func newTestPodConfigNoop() PodConfig { Containers: []ContainerConfig{container}, - Annotations: podAnnotations, + Annotations: sandboxAnnotations, } - return podConfig + return sandboxConfig } -func newTestPodConfigHyperstartAgent() PodConfig { +func newTestSandboxConfigHyperstartAgent() SandboxConfig { // Define the container command and bundle. container := ContainerConfig{ ID: containerID, @@ -114,8 +114,8 @@ func newTestPodConfigHyperstartAgent() PodConfig { SockTtyName: testHyperstartTtySocket, } - podConfig := PodConfig{ - ID: testPodID, + sandboxConfig := SandboxConfig{ + ID: testSandboxID, HypervisorType: MockHypervisor, HypervisorConfig: hypervisorConfig, @@ -123,13 +123,13 @@ func newTestPodConfigHyperstartAgent() PodConfig { AgentConfig: agentConfig, Containers: []ContainerConfig{container}, - Annotations: podAnnotations, + Annotations: sandboxAnnotations, } - return podConfig + return sandboxConfig } -func newTestPodConfigHyperstartAgentCNINetwork() PodConfig { +func newTestSandboxConfigHyperstartAgentCNINetwork() SandboxConfig { // Define the container command and bundle. container := ContainerConfig{ ID: containerID, @@ -154,8 +154,8 @@ func newTestPodConfigHyperstartAgentCNINetwork() PodConfig { NumInterfaces: 1, } - podConfig := PodConfig{ - ID: testPodID, + sandboxConfig := SandboxConfig{ + ID: testSandboxID, HypervisorType: MockHypervisor, HypervisorConfig: hypervisorConfig, @@ -166,13 +166,13 @@ func newTestPodConfigHyperstartAgentCNINetwork() PodConfig { NetworkConfig: netConfig, Containers: []ContainerConfig{container}, - Annotations: podAnnotations, + Annotations: sandboxAnnotations, } - return podConfig + return sandboxConfig } -func newTestPodConfigHyperstartAgentCNMNetwork() PodConfig { +func newTestSandboxConfigHyperstartAgentCNMNetwork() SandboxConfig { // Define the container command and bundle. container := ContainerConfig{ ID: containerID, @@ -208,8 +208,8 @@ func newTestPodConfigHyperstartAgentCNMNetwork() PodConfig { NumInterfaces: len(hooks.PreStartHooks), } - podConfig := PodConfig{ - ID: testPodID, + sandboxConfig := SandboxConfig{ + ID: testSandboxID, Hooks: hooks, HypervisorType: MockHypervisor, @@ -222,13 +222,13 @@ func newTestPodConfigHyperstartAgentCNMNetwork() PodConfig { NetworkConfig: netConfig, Containers: []ContainerConfig{container}, - Annotations: podAnnotations, + Annotations: sandboxAnnotations, } - return podConfig + return sandboxConfig } -func newTestPodConfigKataAgent() PodConfig { +func newTestSandboxConfigKataAgent() SandboxConfig { // Sets the hypervisor configuration. hypervisorConfig := HypervisorConfig{ KernelPath: filepath.Join(testDir, testKernel), @@ -236,31 +236,31 @@ func newTestPodConfigKataAgent() PodConfig { HypervisorPath: filepath.Join(testDir, testHypervisor), } - podConfig := PodConfig{ - ID: testPodID, + sandboxConfig := SandboxConfig{ + ID: testSandboxID, HypervisorType: MockHypervisor, HypervisorConfig: hypervisorConfig, AgentType: KataContainersAgent, - Annotations: podAnnotations, + Annotations: sandboxAnnotations, } - return podConfig + return sandboxConfig } -func TestCreatePodNoopAgentSuccessful(t *testing.T) { +func TestCreateSandboxNoopAgentSuccessful(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -278,14 +278,14 @@ func testGenerateCCProxySockDir() (string, error) { return dir, nil } -func TestCreatePodHyperstartAgentSuccessful(t *testing.T) { +func TestCreateSandboxHyperstartAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigHyperstartAgent() + config := newTestSandboxConfigHyperstartAgent() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -299,26 +299,26 @@ func TestCreatePodHyperstartAgentSuccessful(t *testing.T) { proxy.Start() defer proxy.Stop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } } -func TestCreatePodKataAgentSuccessful(t *testing.T) { +func TestCreateSandboxKataAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigKataAgent() + config := newTestSandboxConfigKataAgent() sockDir, err := testGenerateKataProxySockDir() if err != nil { @@ -340,64 +340,64 @@ func TestCreatePodKataAgentSuccessful(t *testing.T) { } defer kataProxyMock.Stop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } } -func TestCreatePodFailing(t *testing.T) { +func TestCreateSandboxFailing(t *testing.T) { cleanUp() - config := PodConfig{} + config := SandboxConfig{} - p, err := CreatePod(config) - if p.(*Pod) != nil || err == nil { + p, err := CreateSandbox(config) + if p.(*Sandbox) != nil || err == nil { t.Fatal() } } -func TestDeletePodNoopAgentSuccessful(t *testing.T) { +func TestDeleteSandboxNoopAgentSuccessful(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } - p, err = DeletePod(p.ID()) + p, err = DeleteSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - _, err = os.Stat(podDir) + _, err = os.Stat(sandboxDir) if err == nil { t.Fatal() } } -func TestDeletePodHyperstartAgentSuccessful(t *testing.T) { +func TestDeleteSandboxHyperstartAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigHyperstartAgent() + config := newTestSandboxConfigHyperstartAgent() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -411,36 +411,36 @@ func TestDeletePodHyperstartAgentSuccessful(t *testing.T) { proxy.Start() defer proxy.Stop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } - p, err = DeletePod(p.ID()) + p, err = DeleteSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - _, err = os.Stat(podDir) + _, err = os.Stat(sandboxDir) if err == nil { t.Fatal(err) } } -func TestDeletePodKataAgentSuccessful(t *testing.T) { +func TestDeleteSandboxKataAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigKataAgent() + config := newTestSandboxConfigKataAgent() sockDir, err := testGenerateKataProxySockDir() if err != nil { @@ -462,59 +462,59 @@ func TestDeletePodKataAgentSuccessful(t *testing.T) { } defer kataProxyMock.Stop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } - p, err = DeletePod(p.ID()) + p, err = DeleteSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - _, err = os.Stat(podDir) + _, err = os.Stat(sandboxDir) if err == nil { t.Fatal(err) } } -func TestDeletePodFailing(t *testing.T) { +func TestDeleteSandboxFailing(t *testing.T) { cleanUp() - podDir := filepath.Join(configStoragePath, testPodID) - os.Remove(podDir) + sandboxDir := filepath.Join(configStoragePath, testSandboxID) + os.Remove(sandboxDir) - p, err := DeletePod(testPodID) + p, err := DeleteSandbox(testSandboxID) if p != nil || err == nil { t.Fatal() } } -func TestStartPodNoopAgentSuccessful(t *testing.T) { +func TestStartSandboxNoopAgentSuccessful(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } } -func TestStartPodHyperstartAgentSuccessful(t *testing.T) { +func TestStartSandboxHyperstartAgentSuccessful(t *testing.T) { cleanUp() if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } - config := newTestPodConfigHyperstartAgent() + config := newTestSandboxConfigHyperstartAgent() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -531,25 +531,25 @@ func TestStartPodHyperstartAgentSuccessful(t *testing.T) { hyperConfig := config.AgentConfig.(HyperConfig) config.AgentConfig = hyperConfig - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) bindUnmountAllRootfs(defaultSharedDir, *pImpl) } -func TestStartPodKataAgentSuccessful(t *testing.T) { +func TestStartSandboxKataAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigKataAgent() + config := newTestSandboxConfigKataAgent() sockDir, err := testGenerateKataProxySockDir() if err != nil { @@ -571,51 +571,51 @@ func TestStartPodKataAgentSuccessful(t *testing.T) { } defer kataProxyMock.Stop() - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) bindUnmountAllRootfs(defaultSharedDir, *pImpl) } -func TestStartPodFailing(t *testing.T) { +func TestStartSandboxFailing(t *testing.T) { cleanUp() - podDir := filepath.Join(configStoragePath, testPodID) - os.Remove(podDir) + sandboxDir := filepath.Join(configStoragePath, testSandboxID) + os.Remove(sandboxDir) - p, err := StartPod(testPodID) + p, err := StartSandbox(testSandboxID) if p != nil || err == nil { t.Fatal() } } -func TestStopPodNoopAgentSuccessful(t *testing.T) { +func TestStopSandboxNoopAgentSuccessful(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } - vp, err := StopPod(p.ID()) + vp, err := StopSandbox(p.ID()) if vp == nil || err != nil { t.Fatal(err) } } -func TestPauseThenResumePodNoopAgentSuccessful(t *testing.T) { +func TestPauseThenResumeSandboxNoopAgentSuccessful(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -628,17 +628,17 @@ func TestPauseThenResumePodNoopAgentSuccessful(t *testing.T) { t.Fatal(err) } - p, err = PausePod(p.ID()) + p, err = PauseSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) expectedState := StatePaused - assert.Equal(t, pImpl.state.State, expectedState, "unexpected paused pod state") + assert.Equal(t, pImpl.state.State, expectedState, "unexpected paused sandbox state") for i, c := range p.GetAllContainers() { cImpl, ok := c.(*Container) @@ -648,17 +648,17 @@ func TestPauseThenResumePodNoopAgentSuccessful(t *testing.T) { fmt.Sprintf("paused container %d has unexpected state", i)) } - p, err = ResumePod(p.ID()) + p, err = ResumeSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - pImpl, ok = p.(*Pod) + pImpl, ok = p.(*Sandbox) assert.True(t, ok) expectedState = StateRunning - assert.Equal(t, pImpl.state.State, expectedState, "unexpected resumed pod state") + assert.Equal(t, pImpl.state.State, expectedState, "unexpected resumed sandbox state") for i, c := range p.GetAllContainers() { cImpl, ok := c.(*Container) @@ -669,14 +669,14 @@ func TestPauseThenResumePodNoopAgentSuccessful(t *testing.T) { } } -func TestStopPodHyperstartAgentSuccessful(t *testing.T) { +func TestStopSandboxHyperstartAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigHyperstartAgent() + config := newTestSandboxConfigHyperstartAgent() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -693,25 +693,25 @@ func TestStopPodHyperstartAgentSuccessful(t *testing.T) { hyperConfig := config.AgentConfig.(HyperConfig) config.AgentConfig = hyperConfig - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } - p, err = StopPod(p.ID()) + p, err = StopSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } } -func TestStopPodKataAgentSuccessful(t *testing.T) { +func TestStopSandboxKataAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigKataAgent() + config := newTestSandboxConfigKataAgent() sockDir, err := testGenerateKataProxySockDir() if err != nil { @@ -733,54 +733,54 @@ func TestStopPodKataAgentSuccessful(t *testing.T) { } defer kataProxyMock.Stop() - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } - p, err = StopPod(p.ID()) + p, err = StopSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } } -func TestStopPodFailing(t *testing.T) { +func TestStopSandboxFailing(t *testing.T) { cleanUp() - podDir := filepath.Join(configStoragePath, testPodID) - os.Remove(podDir) + sandboxDir := filepath.Join(configStoragePath, testSandboxID) + os.Remove(sandboxDir) - p, err := StopPod(testPodID) + p, err := StopSandbox(testSandboxID) if p != nil || err == nil { t.Fatal() } } -func TestRunPodNoopAgentSuccessful(t *testing.T) { +func TestRunSandboxNoopAgentSuccessful(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := RunPod(config) + p, err := RunSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } } -func TestRunPodHyperstartAgentSuccessful(t *testing.T) { +func TestRunSandboxHyperstartAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigHyperstartAgent() + config := newTestSandboxConfigHyperstartAgent() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -797,31 +797,31 @@ func TestRunPodHyperstartAgentSuccessful(t *testing.T) { hyperConfig := config.AgentConfig.(HyperConfig) config.AgentConfig = hyperConfig - p, err := RunPod(config) + p, err := RunSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) bindUnmountAllRootfs(defaultSharedDir, *pImpl) } -func TestRunPodKataAgentSuccessful(t *testing.T) { +func TestRunSandboxKataAgentSuccessful(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigKataAgent() + config := newTestSandboxConfigKataAgent() sockDir, err := testGenerateKataProxySockDir() if err != nil { @@ -843,67 +843,67 @@ func TestRunPodKataAgentSuccessful(t *testing.T) { } defer kataProxyMock.Stop() - p, err := RunPod(config) + p, err := RunSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) bindUnmountAllRootfs(defaultSharedDir, *pImpl) } -func TestRunPodFailing(t *testing.T) { +func TestRunSandboxFailing(t *testing.T) { cleanUp() - config := PodConfig{} + config := SandboxConfig{} - p, err := RunPod(config) + p, err := RunSandbox(config) if p != nil || err == nil { t.Fatal() } } -func TestListPodSuccessful(t *testing.T) { +func TestListSandboxSuccessful(t *testing.T) { cleanUp() os.RemoveAll(configStoragePath) - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - _, err = ListPod() + _, err = ListSandbox() if err != nil { t.Fatal(err) } } -func TestListPodNoPodDirectory(t *testing.T) { +func TestListSandboxNoSandboxDirectory(t *testing.T) { cleanUp() os.RemoveAll(configStoragePath) - _, err := ListPod() + _, err := ListSandbox() if err != nil { - t.Fatal(fmt.Sprintf("unexpected ListPod error from non-existent pod directory: %v", err)) + t.Fatal(fmt.Sprintf("unexpected ListSandbox error from non-existent sandbox directory: %v", err)) } } -func TestStatusPodSuccessfulStateReady(t *testing.T) { +func TestStatusSandboxSuccessfulStateReady(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() hypervisorConfig := HypervisorConfig{ KernelPath: filepath.Join(testDir, testKernel), ImagePath: filepath.Join(testDir, testImage), @@ -915,15 +915,15 @@ func TestStatusPodSuccessfulStateReady(t *testing.T) { DefaultMaxVCPUs: defaultMaxQemuVCPUs, } - expectedStatus := PodStatus{ - ID: testPodID, + expectedStatus := SandboxStatus{ + ID: testSandboxID, State: State{ State: StateReady, }, Hypervisor: MockHypervisor, HypervisorConfig: hypervisorConfig, Agent: NoopAgentType, - Annotations: podAnnotations, + Annotations: sandboxAnnotations, ContainersStatus: []ContainerStatus{ { ID: containerID, @@ -937,12 +937,12 @@ func TestStatusPodSuccessfulStateReady(t *testing.T) { }, } - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - status, err := StatusPod(p.ID()) + status, err := StatusSandbox(p.ID()) if err != nil { t.Fatal(err) } @@ -952,14 +952,14 @@ func TestStatusPodSuccessfulStateReady(t *testing.T) { expectedStatus.ContainersStatus[0].StartTime = status.ContainersStatus[0].StartTime if reflect.DeepEqual(status, expectedStatus) == false { - t.Fatalf("Got pod status %v\n expecting %v", status, expectedStatus) + t.Fatalf("Got sandbox status %v\n expecting %v", status, expectedStatus) } } -func TestStatusPodSuccessfulStateRunning(t *testing.T) { +func TestStatusSandboxSuccessfulStateRunning(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() hypervisorConfig := HypervisorConfig{ KernelPath: filepath.Join(testDir, testKernel), ImagePath: filepath.Join(testDir, testImage), @@ -971,15 +971,15 @@ func TestStatusPodSuccessfulStateRunning(t *testing.T) { DefaultMaxVCPUs: defaultMaxQemuVCPUs, } - expectedStatus := PodStatus{ - ID: testPodID, + expectedStatus := SandboxStatus{ + ID: testSandboxID, State: State{ State: StateRunning, }, Hypervisor: MockHypervisor, HypervisorConfig: hypervisorConfig, Agent: NoopAgentType, - Annotations: podAnnotations, + Annotations: sandboxAnnotations, ContainersStatus: []ContainerStatus{ { ID: containerID, @@ -993,17 +993,17 @@ func TestStatusPodSuccessfulStateRunning(t *testing.T) { }, } - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - p, err = StartPod(p.ID()) + p, err = StartSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - status, err := StatusPod(p.ID()) + status, err := StatusSandbox(p.ID()) if err != nil { t.Fatal(err) } @@ -1013,47 +1013,47 @@ func TestStatusPodSuccessfulStateRunning(t *testing.T) { expectedStatus.ContainersStatus[0].StartTime = status.ContainersStatus[0].StartTime if reflect.DeepEqual(status, expectedStatus) == false { - t.Fatalf("Got pod status %v\n expecting %v", status, expectedStatus) + t.Fatalf("Got sandbox status %v\n expecting %v", status, expectedStatus) } } -func TestStatusPodFailingFetchPodConfig(t *testing.T) { +func TestStatusSandboxFailingFetchSandboxConfig(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } path := filepath.Join(configStoragePath, p.ID()) os.RemoveAll(path) - globalPodList.removePod(p.ID()) + globalSandboxList.removeSandbox(p.ID()) - _, err = StatusPod(p.ID()) + _, err = StatusSandbox(p.ID()) if err == nil { t.Fatal() } } -func TestStatusPodPodFailingFetchPodState(t *testing.T) { +func TestStatusPodSandboxFailingFetchSandboxState(t *testing.T) { cleanUp() - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) os.RemoveAll(pImpl.configPath) - globalPodList.removePod(p.ID()) + globalSandboxList.removeSandbox(p.ID()) - _, err = StatusPod(p.ID()) + _, err = StatusSandbox(p.ID()) if err == nil { t.Fatal() } @@ -1075,15 +1075,15 @@ func TestCreateContainerSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1095,31 +1095,31 @@ func TestCreateContainerSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) } } -func TestCreateContainerFailingNoPod(t *testing.T) { +func TestCreateContainerFailingNoSandbox(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - p, err = DeletePod(p.ID()) + p, err = DeleteSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err == nil { t.Fatal() } @@ -1136,15 +1136,15 @@ func TestDeleteContainerSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1156,7 +1156,7 @@ func TestDeleteContainerSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1173,14 +1173,14 @@ func TestDeleteContainerSuccessful(t *testing.T) { } } -func TestDeleteContainerFailingNoPod(t *testing.T) { +func TestDeleteContainerFailingNoSandbox(t *testing.T) { cleanUp() - podDir := filepath.Join(configStoragePath, testPodID) + sandboxDir := filepath.Join(configStoragePath, testSandboxID) contID := "100" - os.RemoveAll(podDir) + os.RemoveAll(sandboxDir) - c, err := DeleteContainer(testPodID, contID) + c, err := DeleteContainer(testSandboxID, contID) if c != nil || err == nil { t.Fatal() } @@ -1190,15 +1190,15 @@ func TestDeleteContainerFailingNoContainer(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1213,9 +1213,9 @@ func TestStartContainerNoopAgentSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, podDir, err := createAndStartPod(config) + p, sandboxDir, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -1226,7 +1226,7 @@ func TestStartContainerNoopAgentSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1238,14 +1238,14 @@ func TestStartContainerNoopAgentSuccessful(t *testing.T) { } } -func TestStartContainerFailingNoPod(t *testing.T) { +func TestStartContainerFailingNoSandbox(t *testing.T) { cleanUp() - podDir := filepath.Join(configStoragePath, testPodID) + sandboxDir := filepath.Join(configStoragePath, testSandboxID) contID := "100" - os.RemoveAll(podDir) + os.RemoveAll(sandboxDir) - c, err := StartContainer(testPodID, contID) + c, err := StartContainer(testSandboxID, contID) if c != nil || err == nil { t.Fatal() } @@ -1255,15 +1255,15 @@ func TestStartContainerFailingNoContainer(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1274,19 +1274,19 @@ func TestStartContainerFailingNoContainer(t *testing.T) { } } -func TestStartContainerFailingPodNotStarted(t *testing.T) { +func TestStartContainerFailingSandboxNotStarted(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1298,7 +1298,7 @@ func TestStartContainerFailingPodNotStarted(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1314,9 +1314,9 @@ func TestStopContainerNoopAgentSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, podDir, err := createAndStartPod(config) + p, sandboxDir, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -1328,7 +1328,7 @@ func TestStopContainerNoopAgentSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1353,7 +1353,7 @@ func TestStartStopContainerHyperstartAgentSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigHyperstartAgent() + config := newTestSandboxConfigHyperstartAgent() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -1370,7 +1370,7 @@ func TestStartStopContainerHyperstartAgentSuccessful(t *testing.T) { hyperConfig := config.AgentConfig.(HyperConfig) config.AgentConfig = hyperConfig - p, podDir, err := createAndStartPod(config) + p, sandboxDir, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -1382,7 +1382,7 @@ func TestStartStopContainerHyperstartAgentSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1398,20 +1398,20 @@ func TestStartStopContainerHyperstartAgentSuccessful(t *testing.T) { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) bindUnmountAllRootfs(defaultSharedDir, *pImpl) } -func TestStartStopPodHyperstartAgentSuccessfulWithCNINetwork(t *testing.T) { +func TestStartStopSandboxHyperstartAgentSuccessfulWithCNINetwork(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } cleanUp() - config := newTestPodConfigHyperstartAgentCNINetwork() + config := newTestSandboxConfigHyperstartAgentCNINetwork() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -1428,28 +1428,28 @@ func TestStartStopPodHyperstartAgentSuccessfulWithCNINetwork(t *testing.T) { hyperConfig := config.AgentConfig.(HyperConfig) config.AgentConfig = hyperConfig - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } - p, err = StopPod(p.ID()) + p, err = StopSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - p, err = DeletePod(p.ID()) + p, err = DeleteSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } } -func TestStartStopPodHyperstartAgentSuccessfulWithCNMNetwork(t *testing.T) { +func TestStartStopSandboxHyperstartAgentSuccessfulWithCNMNetwork(t *testing.T) { if os.Geteuid() != 0 { t.Skip(testDisabledAsNonRoot) } - config := newTestPodConfigHyperstartAgentCNMNetwork() + config := newTestSandboxConfigHyperstartAgentCNMNetwork() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -1466,30 +1466,30 @@ func TestStartStopPodHyperstartAgentSuccessfulWithCNMNetwork(t *testing.T) { hyperConfig := config.AgentConfig.(HyperConfig) config.AgentConfig = hyperConfig - p, _, err := createAndStartPod(config) + p, _, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } - v, err := StopPod(p.ID()) + v, err := StopSandbox(p.ID()) if v == nil || err != nil { t.Fatal(err) } - v, err = DeletePod(p.ID()) + v, err = DeleteSandbox(p.ID()) if v == nil || err != nil { t.Fatal(err) } } -func TestStopContainerFailingNoPod(t *testing.T) { +func TestStopContainerFailingNoSandbox(t *testing.T) { cleanUp() - podDir := filepath.Join(configStoragePath, testPodID) + sandboxDir := filepath.Join(configStoragePath, testSandboxID) contID := "100" - os.RemoveAll(podDir) + os.RemoveAll(sandboxDir) - c, err := StopContainer(testPodID, contID) + c, err := StopContainer(testSandboxID, contID) if c != nil || err == nil { t.Fatal() } @@ -1499,15 +1499,15 @@ func TestStopContainerFailingNoContainer(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1522,9 +1522,9 @@ func testKillContainerFromContReadySuccessful(t *testing.T, signal syscall.Signa cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, podDir, err := createAndStartPod(config) + p, sandboxDir, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -1536,7 +1536,7 @@ func testKillContainerFromContReadySuccessful(t *testing.T, signal syscall.Signa t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1562,9 +1562,9 @@ func TestEnterContainerNoopAgentSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, podDir, err := createAndStartPod(config) + p, sandboxDir, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -1576,7 +1576,7 @@ func TestEnterContainerNoopAgentSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1603,7 +1603,7 @@ func TestEnterContainerHyperstartAgentSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigHyperstartAgent() + config := newTestSandboxConfigHyperstartAgent() sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -1620,7 +1620,7 @@ func TestEnterContainerHyperstartAgentSuccessful(t *testing.T) { hyperConfig := config.AgentConfig.(HyperConfig) config.AgentConfig = hyperConfig - p, podDir, err := createAndStartPod(config) + p, sandboxDir, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -1632,7 +1632,7 @@ func TestEnterContainerHyperstartAgentSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1655,22 +1655,22 @@ func TestEnterContainerHyperstartAgentSuccessful(t *testing.T) { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) bindUnmountAllRootfs(defaultSharedDir, *pImpl) } -func TestEnterContainerFailingNoPod(t *testing.T) { +func TestEnterContainerFailingNoSandbox(t *testing.T) { cleanUp() - podDir := filepath.Join(configStoragePath, testPodID) + sandboxDir := filepath.Join(configStoragePath, testSandboxID) contID := "100" - os.RemoveAll(podDir) + os.RemoveAll(sandboxDir) cmd := newBasicTestCmd() - _, c, _, err := EnterContainer(testPodID, contID, cmd) + _, c, _, err := EnterContainer(testSandboxID, contID, cmd) if c != nil || err == nil { t.Fatal() } @@ -1680,15 +1680,15 @@ func TestEnterContainerFailingNoContainer(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1705,9 +1705,9 @@ func TestEnterContainerFailingContNotStarted(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, podDir, err := createAndStartPod(config) + p, sandboxDir, err := createAndStartSandbox(config) if p == nil || err != nil { t.Fatal(err) } @@ -1719,7 +1719,7 @@ func TestEnterContainerFailingContNotStarted(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1737,15 +1737,15 @@ func TestStatusContainerSuccessful(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1757,7 +1757,7 @@ func TestStatusContainerSuccessful(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) @@ -1768,7 +1768,7 @@ func TestStatusContainerSuccessful(t *testing.T) { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) cImpl, ok := c.(*Container) @@ -1788,15 +1788,15 @@ func TestStatusContainerStateReady(t *testing.T) { // (homage to a great album! ;) contID := "101" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1808,14 +1808,14 @@ func TestStatusContainerStateReady(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) } // fresh lookup - p2, err := fetchPod(p.ID()) + p2, err := fetchSandbox(p.ID()) if err != nil { t.Fatal(err) } @@ -1851,20 +1851,20 @@ func TestStatusContainerStateRunning(t *testing.T) { // (homage to a great album! ;) contID := "101" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - p, err = StartPod(p.ID()) + p, err = StartSandbox(p.ID()) if p == nil || err != nil { t.Fatal(err) } - podDir := filepath.Join(configStoragePath, p.ID()) - _, err = os.Stat(podDir) + sandboxDir := filepath.Join(configStoragePath, p.ID()) + _, err = os.Stat(sandboxDir) if err != nil { t.Fatal(err) } @@ -1881,14 +1881,14 @@ func TestStatusContainerStateRunning(t *testing.T) { t.Fatal(err) } - contDir := filepath.Join(podDir, contID) + contDir := filepath.Join(sandboxDir, contID) _, err = os.Stat(contDir) if err != nil { t.Fatal(err) } // fresh lookup - p2, err := fetchPod(p.ID()) + p2, err := fetchSandbox(p.ID()) if err != nil { t.Fatal(err) } @@ -1923,18 +1923,18 @@ func TestStatusContainerFailing(t *testing.T) { cleanUp() contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if p == nil || err != nil { t.Fatal(err) } - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(t, ok) os.RemoveAll(pImpl.configPath) - globalPodList.removePod(p.ID()) + globalSandboxList.removeSandbox(p.ID()) _, err = StatusContainer(p.ID(), contID) if err == nil { @@ -1962,12 +1962,12 @@ func TestProcessListContainer(t *testing.T) { _, err = ProcessListContainer("xyz", "xyz", options) assert.Error(err) - config := newTestPodConfigNoop() - p, err := CreatePod(config) + config := newTestSandboxConfigNoop() + p, err := CreateSandbox(config) assert.NoError(err) assert.NotNil(p) - pImpl, ok := p.(*Pod) + pImpl, ok := p.(*Sandbox) assert.True(ok) defer os.RemoveAll(pImpl.configPath) @@ -1983,7 +1983,7 @@ func TestProcessListContainer(t *testing.T) { assert.Error(err) _, err = ProcessListContainer(pImpl.id, contID, options) - // Pod not running, impossible to ps the container + // Sandbox not running, impossible to ps the container assert.Error(err) } @@ -1991,7 +1991,7 @@ func TestProcessListContainer(t *testing.T) { * Benchmarks */ -func createNewPodConfig(hType HypervisorType, aType AgentType, aConfig interface{}, netModel NetworkModel) PodConfig { +func createNewSandboxConfig(hType HypervisorType, aType AgentType, aConfig interface{}, netModel NetworkModel) SandboxConfig { hypervisorConfig := HypervisorConfig{ KernelPath: "/usr/share/kata-containers/vmlinux.container", ImagePath: "/usr/share/kata-containers/kata-containers.img", @@ -2002,8 +2002,8 @@ func createNewPodConfig(hType HypervisorType, aType AgentType, aConfig interface NumInterfaces: 1, } - return PodConfig{ - ID: testPodID, + return SandboxConfig{ + ID: testSandboxID, HypervisorType: hType, HypervisorConfig: hypervisorConfig, @@ -2051,62 +2051,62 @@ func createNewContainerConfigs(numOfContainers int) []ContainerConfig { return contConfigs } -// createAndStartPod handles the common test operation of creating and -// starting a pod. -func createAndStartPod(config PodConfig) (pod VCPod, podDir string, +// createAndStartSandbox handles the common test operation of creating and +// starting a sandbox. +func createAndStartSandbox(config SandboxConfig) (sandbox VCSandbox, sandboxDir string, err error) { - // Create pod - pod, err = CreatePod(config) - if pod == nil || err != nil { + // Create sandbox + sandbox, err = CreateSandbox(config) + if sandbox == nil || err != nil { return nil, "", err } - podDir = filepath.Join(configStoragePath, pod.ID()) - _, err = os.Stat(podDir) + sandboxDir = filepath.Join(configStoragePath, sandbox.ID()) + _, err = os.Stat(sandboxDir) if err != nil { return nil, "", err } - // Start pod - pod, err = StartPod(pod.ID()) - if pod == nil || err != nil { + // Start sandbox + sandbox, err = StartSandbox(sandbox.ID()) + if sandbox == nil || err != nil { return nil, "", err } - return pod, podDir, nil + return sandbox, sandboxDir, nil } -func createStartStopDeletePod(b *testing.B, podConfig PodConfig) { - p, _, err := createAndStartPod(podConfig) +func createStartStopDeleteSandbox(b *testing.B, sandboxConfig SandboxConfig) { + p, _, err := createAndStartSandbox(sandboxConfig) if p == nil || err != nil { - b.Fatalf("Could not create and start pod: %s", err) + b.Fatalf("Could not create and start sandbox: %s", err) } - // Stop pod - _, err = StopPod(p.ID()) + // Stop sandbox + _, err = StopSandbox(p.ID()) if err != nil { - b.Fatalf("Could not stop pod: %s", err) + b.Fatalf("Could not stop sandbox: %s", err) } - // Delete pod - _, err = DeletePod(p.ID()) + // Delete sandbox + _, err = DeleteSandbox(p.ID()) if err != nil { - b.Fatalf("Could not delete pod: %s", err) + b.Fatalf("Could not delete sandbox: %s", err) } } -func createStartStopDeleteContainers(b *testing.B, podConfig PodConfig, contConfigs []ContainerConfig) { - // Create pod - p, err := CreatePod(podConfig) +func createStartStopDeleteContainers(b *testing.B, sandboxConfig SandboxConfig, contConfigs []ContainerConfig) { + // Create sandbox + p, err := CreateSandbox(sandboxConfig) if err != nil { - b.Fatalf("Could not create pod: %s", err) + b.Fatalf("Could not create sandbox: %s", err) } - // Start pod - _, err = StartPod(p.ID()) + // Start sandbox + _, err = StartSandbox(p.ID()) if err != nil { - b.Fatalf("Could not start pod: %s", err) + b.Fatalf("Could not start sandbox: %s", err) } // Create containers @@ -2141,22 +2141,22 @@ func createStartStopDeleteContainers(b *testing.B, podConfig PodConfig, contConf } } - // Stop pod - _, err = StopPod(p.ID()) + // Stop sandbox + _, err = StopSandbox(p.ID()) if err != nil { - b.Fatalf("Could not stop pod: %s", err) + b.Fatalf("Could not stop sandbox: %s", err) } - // Delete pod - _, err = DeletePod(p.ID()) + // Delete sandbox + _, err = DeleteSandbox(p.ID()) if err != nil { - b.Fatalf("Could not delete pod: %s", err) + b.Fatalf("Could not delete sandbox: %s", err) } } -func BenchmarkCreateStartStopDeletePodQemuHypervisorHyperstartAgentNetworkCNI(b *testing.B) { +func BenchmarkCreateStartStopDeleteSandboxQemuHypervisorHyperstartAgentNetworkCNI(b *testing.B) { for i := 0; i < b.N; i++ { - podConfig := createNewPodConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, CNINetworkModel) + sandboxConfig := createNewSandboxConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, CNINetworkModel) sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -2171,20 +2171,20 @@ func BenchmarkCreateStartStopDeletePodQemuHypervisorHyperstartAgentNetworkCNI(b proxy.Start() defer proxy.Stop() - createStartStopDeletePod(b, podConfig) + createStartStopDeleteSandbox(b, sandboxConfig) } } -func BenchmarkCreateStartStopDeletePodQemuHypervisorNoopAgentNetworkCNI(b *testing.B) { +func BenchmarkCreateStartStopDeleteSandboxQemuHypervisorNoopAgentNetworkCNI(b *testing.B) { for i := 0; i < b.N; i++ { - podConfig := createNewPodConfig(QemuHypervisor, NoopAgentType, nil, CNINetworkModel) - createStartStopDeletePod(b, podConfig) + sandboxConfig := createNewSandboxConfig(QemuHypervisor, NoopAgentType, nil, CNINetworkModel) + createStartStopDeleteSandbox(b, sandboxConfig) } } -func BenchmarkCreateStartStopDeletePodQemuHypervisorHyperstartAgentNetworkNoop(b *testing.B) { +func BenchmarkCreateStartStopDeleteSandboxQemuHypervisorHyperstartAgentNetworkNoop(b *testing.B) { for i := 0; i < b.N; i++ { - podConfig := createNewPodConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, NoopNetworkModel) + sandboxConfig := createNewSandboxConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, NoopNetworkModel) sockDir, err := testGenerateCCProxySockDir() if err != nil { @@ -2199,27 +2199,27 @@ func BenchmarkCreateStartStopDeletePodQemuHypervisorHyperstartAgentNetworkNoop(b proxy.Start() defer proxy.Stop() - createStartStopDeletePod(b, podConfig) + createStartStopDeleteSandbox(b, sandboxConfig) } } -func BenchmarkCreateStartStopDeletePodQemuHypervisorNoopAgentNetworkNoop(b *testing.B) { +func BenchmarkCreateStartStopDeleteSandboxQemuHypervisorNoopAgentNetworkNoop(b *testing.B) { for i := 0; i < b.N; i++ { - podConfig := createNewPodConfig(QemuHypervisor, NoopAgentType, nil, NoopNetworkModel) - createStartStopDeletePod(b, podConfig) + sandboxConfig := createNewSandboxConfig(QemuHypervisor, NoopAgentType, nil, NoopNetworkModel) + createStartStopDeleteSandbox(b, sandboxConfig) } } -func BenchmarkCreateStartStopDeletePodMockHypervisorNoopAgentNetworkNoop(b *testing.B) { +func BenchmarkCreateStartStopDeleteSandboxMockHypervisorNoopAgentNetworkNoop(b *testing.B) { for i := 0; i < b.N; i++ { - podConfig := createNewPodConfig(MockHypervisor, NoopAgentType, nil, NoopNetworkModel) - createStartStopDeletePod(b, podConfig) + sandboxConfig := createNewSandboxConfig(MockHypervisor, NoopAgentType, nil, NoopNetworkModel) + createStartStopDeleteSandbox(b, sandboxConfig) } } func BenchmarkStartStop1ContainerQemuHypervisorHyperstartAgentNetworkNoop(b *testing.B) { for i := 0; i < b.N; i++ { - podConfig := createNewPodConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, NoopNetworkModel) + sandboxConfig := createNewSandboxConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, NoopNetworkModel) contConfigs := createNewContainerConfigs(1) sockDir, err := testGenerateCCProxySockDir() @@ -2235,13 +2235,13 @@ func BenchmarkStartStop1ContainerQemuHypervisorHyperstartAgentNetworkNoop(b *tes proxy.Start() defer proxy.Stop() - createStartStopDeleteContainers(b, podConfig, contConfigs) + createStartStopDeleteContainers(b, sandboxConfig, contConfigs) } } func BenchmarkStartStop10ContainerQemuHypervisorHyperstartAgentNetworkNoop(b *testing.B) { for i := 0; i < b.N; i++ { - podConfig := createNewPodConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, NoopNetworkModel) + sandboxConfig := createNewSandboxConfig(QemuHypervisor, HyperstartAgent, HyperConfig{}, NoopNetworkModel) contConfigs := createNewContainerConfigs(10) sockDir, err := testGenerateCCProxySockDir() @@ -2257,6 +2257,6 @@ func BenchmarkStartStop10ContainerQemuHypervisorHyperstartAgentNetworkNoop(b *te proxy.Start() defer proxy.Stop() - createStartStopDeleteContainers(b, podConfig, contConfigs) + createStartStopDeleteContainers(b, sandboxConfig, contConfigs) } } diff --git a/virtcontainers/asset.go b/virtcontainers/asset.go index 6b223c47a..044eeb80f 100644 --- a/virtcontainers/asset.go +++ b/virtcontainers/asset.go @@ -115,8 +115,8 @@ func (a *asset) hash(hashType string) (string, error) { return hash, nil } -// newAsset returns a new asset from the pod annotations. -func newAsset(podConfig *PodConfig, t assetType) (*asset, error) { +// newAsset returns a new asset from the sandbox annotations. +func newAsset(sandboxConfig *SandboxConfig, t assetType) (*asset, error) { pathAnnotation, hashAnnotation, err := t.annotations() if err != nil { return nil, err @@ -126,7 +126,7 @@ func newAsset(podConfig *PodConfig, t assetType) (*asset, error) { return nil, fmt.Errorf("Missing annotation paths for %s", t) } - path, ok := podConfig.Annotations[pathAnnotation] + path, ok := sandboxConfig.Annotations[pathAnnotation] if !ok || path == "" { return nil, nil } @@ -137,13 +137,13 @@ func newAsset(podConfig *PodConfig, t assetType) (*asset, error) { a := &asset{path: path, kind: t} - hash, ok := podConfig.Annotations[hashAnnotation] + hash, ok := sandboxConfig.Annotations[hashAnnotation] if !ok || hash == "" { return a, nil } // We have a hash annotation, we need to verify the asset against it. - hashType, ok := podConfig.Annotations[annotations.AssetHashType] + hashType, ok := sandboxConfig.Annotations[annotations.AssetHashType] if !ok { virtLog.Warningf("Unrecognized hash type: %s, switching to %s", hashType, annotations.SHA512) hashType = annotations.SHA512 diff --git a/virtcontainers/asset_test.go b/virtcontainers/asset_test.go index 132f9f6ba..21a901c49 100644 --- a/virtcontainers/asset_test.go +++ b/virtcontainers/asset_test.go @@ -90,7 +90,7 @@ func TestAssetNew(t *testing.T) { _, err = tmpfile.Write(assetContent) assert.Nil(err) - p := &PodConfig{ + p := &SandboxConfig{ Annotations: map[string]string{ annotations.KernelPath: tmpfile.Name(), annotations.KernelHash: assetContentHash, @@ -105,7 +105,7 @@ func TestAssetNew(t *testing.T) { assert.Nil(err) assert.Equal(assetContentHash, a.computedHash) - p = &PodConfig{ + p = &SandboxConfig{ Annotations: map[string]string{ annotations.KernelPath: tmpfile.Name(), annotations.KernelHash: assetContentWrongHash, diff --git a/virtcontainers/cc_proxy.go b/virtcontainers/cc_proxy.go index 6675f6c29..bb1f9eafa 100644 --- a/virtcontainers/cc_proxy.go +++ b/virtcontainers/cc_proxy.go @@ -24,14 +24,14 @@ type ccProxy struct { } // start is the proxy start implementation for ccProxy. -func (p *ccProxy) start(pod Pod, params proxyParams) (int, string, error) { - config, err := newProxyConfig(pod.config) +func (p *ccProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { + config, err := newProxyConfig(sandbox.config) if err != nil { return -1, "", err } // construct the socket path the proxy instance will use - proxyURL, err := defaultProxyURL(pod, SocketTypeUNIX) + proxyURL, err := defaultProxyURL(sandbox, SocketTypeUNIX) if err != nil { return -1, "", err } @@ -49,6 +49,6 @@ func (p *ccProxy) start(pod Pod, params proxyParams) (int, string, error) { return cmd.Process.Pid, proxyURL, nil } -func (p *ccProxy) stop(pod Pod, pid int) error { +func (p *ccProxy) stop(sandbox Sandbox, pid int) error { return nil } diff --git a/virtcontainers/cc_proxy_test.go b/virtcontainers/cc_proxy_test.go index ec67a40d4..164fad5be 100644 --- a/virtcontainers/cc_proxy_test.go +++ b/virtcontainers/cc_proxy_test.go @@ -35,27 +35,27 @@ func TestCCProxyStart(t *testing.T) { proxy := &ccProxy{} type testData struct { - pod Pod + sandbox Sandbox expectedURI string expectError bool } invalidPath := filepath.Join(tmpdir, "enoent") - expectedSocketPath := filepath.Join(runStoragePath, testPodID, "proxy.sock") + expectedSocketPath := filepath.Join(runStoragePath, testSandboxID, "proxy.sock") expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath) data := []testData{ - {Pod{}, "", true}, + {Sandbox{}, "", true}, { - Pod{ - config: &PodConfig{ + Sandbox{ + config: &SandboxConfig{ ProxyType: "invalid", }, }, "", true, }, { - Pod{ - config: &PodConfig{ + Sandbox{ + config: &SandboxConfig{ ProxyType: CCProxyType, ProxyConfig: ProxyConfig{ // invalid - no path @@ -64,8 +64,8 @@ func TestCCProxyStart(t *testing.T) { }, "", true, }, { - Pod{ - config: &PodConfig{ + Sandbox{ + config: &SandboxConfig{ ProxyType: CCProxyType, ProxyConfig: ProxyConfig{ Path: invalidPath, @@ -74,9 +74,9 @@ func TestCCProxyStart(t *testing.T) { }, "", true, }, { - Pod{ - id: testPodID, - config: &PodConfig{ + Sandbox{ + id: testSandboxID, + config: &SandboxConfig{ ProxyType: CCProxyType, ProxyConfig: ProxyConfig{ Path: "echo", @@ -87,7 +87,7 @@ func TestCCProxyStart(t *testing.T) { } for _, d := range data { - pid, uri, err := proxy.start(d.pod, proxyParams{}) + pid, uri, err := proxy.start(d.sandbox, proxyParams{}) if d.expectError { assert.Error(err) continue diff --git a/virtcontainers/cc_shim.go b/virtcontainers/cc_shim.go index ddf2db2d6..d0cc4cace 100644 --- a/virtcontainers/cc_shim.go +++ b/virtcontainers/cc_shim.go @@ -25,12 +25,12 @@ type ccShim struct{} // 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(pod Pod, params ShimParams) (int, error) { - if pod.config == nil { - return -1, fmt.Errorf("Pod config cannot be nil") +func (s *ccShim) start(sandbox Sandbox, params ShimParams) (int, error) { + if sandbox.config == nil { + return -1, fmt.Errorf("Sandbox config cannot be nil") } - config, ok := newShimConfig(*(pod.config)).(ShimConfig) + config, ok := newShimConfig(*(sandbox.config)).(ShimConfig) if !ok { return -1, fmt.Errorf("Wrong shim config type, should be CCShimConfig type") } diff --git a/virtcontainers/cc_shim_test.go b/virtcontainers/cc_shim_test.go index 9811b3163..960af3c3e 100644 --- a/virtcontainers/cc_shim_test.go +++ b/virtcontainers/cc_shim_test.go @@ -46,65 +46,65 @@ func getMockCCShimBinPath() string { return DefaultMockCCShimBinPath } -func testCCShimStart(t *testing.T, pod Pod, params ShimParams, expectFail bool) { +func testCCShimStart(t *testing.T, sandbox Sandbox, params ShimParams, expectFail bool) { s := &ccShim{} - pid, err := s.start(pod, params) + pid, err := s.start(sandbox, params) if expectFail { if err == nil || pid != -1 { - t.Fatalf("This test should fail (pod %+v, params %+v, expectFail %t)", - pod, params, expectFail) + t.Fatalf("This test should fail (sandbox %+v, params %+v, expectFail %t)", + sandbox, params, expectFail) } } else { if err != nil { - t.Fatalf("This test should pass (pod %+v, params %+v, expectFail %t): %s", - pod, params, expectFail, err) + t.Fatalf("This test should pass (sandbox %+v, params %+v, expectFail %t): %s", + sandbox, params, expectFail, err) } if pid == -1 { - t.Fatalf("This test should pass (pod %+v, params %+v, expectFail %t)", - pod, params, expectFail) + t.Fatalf("This test should pass (sandbox %+v, params %+v, expectFail %t)", + sandbox, params, expectFail) } } } -func TestCCShimStartNilPodConfigFailure(t *testing.T) { - testCCShimStart(t, Pod{}, ShimParams{}, true) +func TestCCShimStartNilSandboxConfigFailure(t *testing.T) { + testCCShimStart(t, Sandbox{}, ShimParams{}, true) } func TestCCShimStartNilShimConfigFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{}, + sandbox := Sandbox{ + config: &SandboxConfig{}, } - testCCShimStart(t, pod, ShimParams{}, true) + testCCShimStart(t, sandbox, ShimParams{}, true) } func TestCCShimStartShimPathEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{}, }, } - testCCShimStart(t, pod, ShimParams{}, true) + testCCShimStart(t, sandbox, ShimParams{}, true) } func TestCCShimStartShimTypeInvalid(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: "foo", ShimConfig: ShimConfig{}, }, } - testCCShimStart(t, pod, ShimParams{}, true) + testCCShimStart(t, sandbox, ShimParams{}, true) } func TestCCShimStartParamsTokenEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{ Path: getMockCCShimBinPath(), @@ -112,12 +112,12 @@ func TestCCShimStartParamsTokenEmptyFailure(t *testing.T) { }, } - testCCShimStart(t, pod, ShimParams{}, true) + testCCShimStart(t, sandbox, ShimParams{}, true) } func TestCCShimStartParamsURLEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{ Path: getMockCCShimBinPath(), @@ -129,12 +129,12 @@ func TestCCShimStartParamsURLEmptyFailure(t *testing.T) { Token: "testToken", } - testCCShimStart(t, pod, params, true) + testCCShimStart(t, sandbox, params, true) } func TestCCShimStartParamsContainerEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{ Path: getMockCCShimBinPath(), @@ -147,7 +147,7 @@ func TestCCShimStartParamsContainerEmptyFailure(t *testing.T) { URL: "unix://is/awesome", } - testCCShimStart(t, pod, params, true) + testCCShimStart(t, sandbox, params, true) } func TestCCShimStartParamsInvalidCommand(t *testing.T) { @@ -159,8 +159,8 @@ func TestCCShimStartParamsInvalidCommand(t *testing.T) { cmd := filepath.Join(dir, "does-not-exist") - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{ Path: cmd, @@ -173,20 +173,20 @@ func TestCCShimStartParamsInvalidCommand(t *testing.T) { URL: "http://foo", } - testCCShimStart(t, pod, params, true) + testCCShimStart(t, sandbox, params, true) } -func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, Pod, ShimParams, error) { +func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, Sandbox, ShimParams, error) { saveStdout := os.Stdout rStdout, wStdout, err := os.Pipe() if err != nil { - return nil, nil, nil, Pod{}, ShimParams{}, err + return nil, nil, nil, Sandbox{}, ShimParams{}, err } os.Stdout = wStdout - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{ Path: getMockCCShimBinPath(), @@ -201,11 +201,11 @@ func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.Fi Detach: detach, } - return rStdout, wStdout, saveStdout, pod, params, nil + return rStdout, wStdout, saveStdout, sandbox, params, nil } func TestCCShimStartSuccessful(t *testing.T) { - rStdout, wStdout, saveStdout, pod, params, err := startCCShimStartWithoutConsoleSuccessful(t, false) + rStdout, wStdout, saveStdout, sandbox, params, err := startCCShimStartWithoutConsoleSuccessful(t, false) if err != nil { t.Fatal(err) } @@ -216,7 +216,7 @@ func TestCCShimStartSuccessful(t *testing.T) { wStdout.Close() }() - testCCShimStart(t, pod, params, false) + testCCShimStart(t, sandbox, params, false) bufStdout := make([]byte, 1024) if _, err := rStdout.Read(bufStdout); err != nil { @@ -229,7 +229,7 @@ func TestCCShimStartSuccessful(t *testing.T) { } func TestCCShimStartDetachSuccessful(t *testing.T) { - rStdout, wStdout, saveStdout, pod, params, err := startCCShimStartWithoutConsoleSuccessful(t, true) + rStdout, wStdout, saveStdout, sandbox, params, err := startCCShimStartWithoutConsoleSuccessful(t, true) if err != nil { t.Fatal(err) } @@ -240,7 +240,7 @@ func TestCCShimStartDetachSuccessful(t *testing.T) { rStdout.Close() }() - testCCShimStart(t, pod, params, false) + testCCShimStart(t, sandbox, params, false) readCh := make(chan error) go func() { @@ -270,8 +270,8 @@ func TestCCShimStartDetachSuccessful(t *testing.T) { } func TestCCShimStartWithConsoleNonExistingFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{ Path: getMockCCShimBinPath(), @@ -285,7 +285,7 @@ func TestCCShimStartWithConsoleNonExistingFailure(t *testing.T) { Console: testWrongConsolePath, } - testCCShimStart(t, pod, params, true) + testCCShimStart(t, sandbox, params, true) } func ioctl(fd uintptr, flag, data uintptr) error { @@ -346,8 +346,8 @@ func TestCCShimStartWithConsoleSuccessful(t *testing.T) { t.Fatal(err) } - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: CCShimType, ShimConfig: ShimConfig{ Path: getMockCCShimBinPath(), @@ -362,6 +362,6 @@ func TestCCShimStartWithConsoleSuccessful(t *testing.T) { Console: console, } - testCCShimStart(t, pod, params, false) + testCCShimStart(t, sandbox, params, false) master.Close() } diff --git a/virtcontainers/cni.go b/virtcontainers/cni.go index 6cad65651..fba20e494 100644 --- a/virtcontainers/cni.go +++ b/virtcontainers/cni.go @@ -70,7 +70,7 @@ func convertCNIResult(cniResult cniTypes.Result) (NetworkInfo, error) { } } -func (n *cni) invokePluginsAdd(pod Pod, networkNS *NetworkNamespace) (*NetworkInfo, error) { +func (n *cni) invokePluginsAdd(sandbox Sandbox, networkNS *NetworkNamespace) (*NetworkInfo, error) { netPlugin, err := cniPlugin.NewNetworkPlugin() if err != nil { return nil, err @@ -79,7 +79,7 @@ func (n *cni) invokePluginsAdd(pod Pod, networkNS *NetworkNamespace) (*NetworkIn // Note: In the case of multus or cni-genie this will return only the results // corresponding to the primary interface. The remaining results need to be // derived - result, err := netPlugin.AddNetwork(pod.id, networkNS.NetNsPath, CniPrimaryInterface) + result, err := netPlugin.AddNetwork(sandbox.id, networkNS.NetNsPath, CniPrimaryInterface) if err != nil { return nil, err } @@ -97,13 +97,13 @@ func (n *cni) invokePluginsAdd(pod Pod, networkNS *NetworkNamespace) (*NetworkIn return &netInfo, nil } -func (n *cni) invokePluginsDelete(pod Pod, networkNS NetworkNamespace) error { +func (n *cni) invokePluginsDelete(sandbox Sandbox, networkNS NetworkNamespace) error { netPlugin, err := cniPlugin.NewNetworkPlugin() if err != nil { return err } - err = netPlugin.RemoveNetwork(pod.id, networkNS.NetNsPath, CniPrimaryInterface) + err = netPlugin.RemoveNetwork(sandbox.id, networkNS.NetNsPath, CniPrimaryInterface) if err != nil { return err } @@ -141,14 +141,14 @@ func (n *cni) run(networkNSPath string, cb func() error) error { } // add adds all needed interfaces inside the network namespace for the CNI network. -func (n *cni) add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { +func (n *cni) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { networkNS := NetworkNamespace{ NetNsPath: netNsPath, NetNsCreated: netNsCreated, } - netInfo, err := n.invokePluginsAdd(pod, &networkNS) + netInfo, err := n.invokePluginsAdd(sandbox, &networkNS) if err != nil { return NetworkNamespace{}, err } @@ -157,7 +157,7 @@ func (n *cni) add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated return NetworkNamespace{}, err } - if err := addNetworkCommon(pod, &networkNS); err != nil { + if err := addNetworkCommon(sandbox, &networkNS); err != nil { return NetworkNamespace{}, err } @@ -166,12 +166,12 @@ func (n *cni) add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated // remove unbridges and deletes TAP interfaces. It also removes virtual network // interfaces and deletes the network namespace for the CNI network. -func (n *cni) remove(pod Pod, networkNS NetworkNamespace) error { +func (n *cni) remove(sandbox Sandbox, networkNS NetworkNamespace) error { if err := removeNetworkCommon(networkNS); err != nil { return err } - if err := n.invokePluginsDelete(pod, networkNS); err != nil { + if err := n.invokePluginsDelete(sandbox, networkNS); err != nil { return err } diff --git a/virtcontainers/cnm.go b/virtcontainers/cnm.go index 773acf432..83d256c98 100644 --- a/virtcontainers/cnm.go +++ b/virtcontainers/cnm.go @@ -39,7 +39,7 @@ func (n *cnm) run(networkNSPath string, cb func() error) error { } // add adds all needed interfaces inside the network namespace for the CNM network. -func (n *cnm) add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { +func (n *cnm) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { endpoints, err := createEndpointsFromScan(netNsPath, config) if err != nil { return NetworkNamespace{}, err @@ -51,7 +51,7 @@ func (n *cnm) add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated Endpoints: endpoints, } - if err := addNetworkCommon(pod, &networkNS); err != nil { + if err := addNetworkCommon(sandbox, &networkNS); err != nil { return NetworkNamespace{}, err } @@ -60,7 +60,7 @@ func (n *cnm) add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated // remove unbridges and deletes TAP interfaces. It also removes virtual network // interfaces and deletes the network namespace for the CNM network. -func (n *cnm) remove(pod Pod, networkNS NetworkNamespace) error { +func (n *cnm) remove(sandbox Sandbox, networkNS NetworkNamespace) error { if err := removeNetworkCommon(networkNS); err != nil { return err } diff --git a/virtcontainers/container.go b/virtcontainers/container.go index e085e9b22..bc8f6e0c6 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -31,10 +31,10 @@ import ( // Process gathers data related to a container process. type Process struct { // Token is the process execution context ID. It must be - // unique per pod. + // unique per sandbox. // Token is used to manipulate processes for containers // that have not started yet, and later identify them - // uniquely within a pod. + // uniquely within a sandbox. Token string // Pid is the process ID as seen by the host software @@ -125,14 +125,14 @@ type SystemMountsInfo struct { // Container is composed of a set of containers and a runtime environment. // A Container can be created, deleted, started, stopped, listed, entered, paused and restored. type Container struct { - id string - podID string + id string + sandboxID string rootFs string config *ContainerConfig - pod *Pod + sandbox *Sandbox runPath string configPath string @@ -159,13 +159,13 @@ func (c *Container) Logger() *logrus.Entry { return virtLog.WithFields(logrus.Fields{ "subsystem": "container", "container-id": c.id, - "pod-id": c.podID, + "sandbox-id": c.sandboxID, }) } -// Pod returns the pod handler related to this container. -func (c *Container) Pod() VCPod { - return c.pod +// Sandbox returns the sandbox handler related to this container. +func (c *Container) Sandbox() VCSandbox { + return c.sandbox } // Process returns the container process. @@ -193,7 +193,7 @@ func (c *Container) SetPid(pid int) error { func (c *Container) setStateBlockIndex(index int) error { c.state.BlockIndex = index - err := c.pod.storage.storeContainerResource(c.pod.id, c.id, stateFileType, c.state) + err := c.sandbox.storage.storeContainerResource(c.sandbox.id, c.id, stateFileType, c.state) if err != nil { return err } @@ -204,7 +204,7 @@ func (c *Container) setStateBlockIndex(index int) error { func (c *Container) setStateFstype(fstype string) error { c.state.Fstype = fstype - err := c.pod.storage.storeContainerResource(c.pod.id, c.id, stateFileType, c.state) + err := c.sandbox.storage.storeContainerResource(c.sandbox.id, c.id, stateFileType, c.state) if err != nil { return err } @@ -215,7 +215,7 @@ func (c *Container) setStateFstype(fstype string) error { func (c *Container) setStateHotpluggedDrive(hotplugged bool) error { c.state.HotpluggedDrive = hotplugged - err := c.pod.storage.storeContainerResource(c.pod.id, c.id, stateFileType, c.state) + err := c.sandbox.storage.storeContainerResource(c.sandbox.id, c.id, stateFileType, c.state) if err != nil { return err } @@ -229,29 +229,29 @@ func (c *Container) GetAnnotations() map[string]string { } func (c *Container) storeProcess() error { - return c.pod.storage.storeContainerProcess(c.podID, c.id, c.process) + return c.sandbox.storage.storeContainerProcess(c.sandboxID, c.id, c.process) } func (c *Container) storeMounts() error { - return c.pod.storage.storeContainerMounts(c.podID, c.id, c.mounts) + return c.sandbox.storage.storeContainerMounts(c.sandboxID, c.id, c.mounts) } func (c *Container) fetchMounts() ([]Mount, error) { - return c.pod.storage.fetchContainerMounts(c.podID, c.id) + return c.sandbox.storage.fetchContainerMounts(c.sandboxID, c.id) } func (c *Container) storeDevices() error { - return c.pod.storage.storeContainerDevices(c.podID, c.id, c.devices) + return c.sandbox.storage.storeContainerDevices(c.sandboxID, c.id, c.devices) } func (c *Container) fetchDevices() ([]Device, error) { - return c.pod.storage.fetchContainerDevices(c.podID, c.id) + return c.sandbox.storage.fetchContainerDevices(c.sandboxID, c.id) } // storeContainer stores a container config. func (c *Container) storeContainer() error { fs := filesystem{} - err := fs.storeContainerResource(c.pod.id, c.id, configFileType, *(c.config)) + err := fs.storeContainerResource(c.sandbox.id, c.id, configFileType, *(c.config)) if err != nil { return err } @@ -270,7 +270,7 @@ func (c *Container) setContainerState(state stateString) error { c.state.State = state // update on-disk state - err := c.pod.storage.storeContainerResource(c.pod.id, c.id, stateFileType, c.state) + err := c.sandbox.storage.storeContainerResource(c.sandbox.id, c.id, stateFileType, c.state) if err != nil { return err } @@ -286,7 +286,7 @@ func (c *Container) createContainersDirs() error { err = os.MkdirAll(c.configPath, dirMode) if err != nil { - c.pod.storage.deleteContainerResources(c.podID, c.id, nil) + c.sandbox.storage.deleteContainerResources(c.sandboxID, c.id, nil) return err } @@ -330,7 +330,7 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) ( } // Attach this block device, all other devices passed in the config have been attached at this point - if err := b.attach(c.pod.hypervisor, c); err != nil { + if err := b.attach(c.sandbox.hypervisor, c); err != nil { return nil, err } @@ -345,7 +345,7 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) ( // These mounts are created in the shared dir filename := fmt.Sprintf("%s-%s-%s", c.id, hex.EncodeToString(randBytes), filepath.Base(m.Destination)) - mountDest := filepath.Join(hostSharedDir, c.pod.id, filename) + mountDest := filepath.Join(hostSharedDir, c.sandbox.id, filename) if err := bindMount(m.Source, mountDest, false); err != nil { return nil, err @@ -397,32 +397,32 @@ func (c *Container) unmountHostMounts() error { return nil } -// newContainer creates a Container structure from a pod and a container configuration. -func newContainer(pod *Pod, contConfig ContainerConfig) (*Container, error) { +// newContainer creates a Container structure from a sandbox and a container configuration. +func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, error) { if contConfig.valid() == false { return &Container{}, fmt.Errorf("Invalid container configuration") } c := &Container{ id: contConfig.ID, - podID: pod.id, + sandboxID: sandbox.id, rootFs: contConfig.RootFs, config: &contConfig, - pod: pod, - runPath: filepath.Join(runStoragePath, pod.id, contConfig.ID), - configPath: filepath.Join(configStoragePath, pod.id, contConfig.ID), - containerPath: filepath.Join(pod.id, contConfig.ID), + sandbox: sandbox, + runPath: filepath.Join(runStoragePath, sandbox.id, contConfig.ID), + configPath: filepath.Join(configStoragePath, sandbox.id, contConfig.ID), + containerPath: filepath.Join(sandbox.id, contConfig.ID), state: State{}, process: Process{}, mounts: contConfig.Mounts, } - state, err := c.pod.storage.fetchContainerState(c.podID, c.id) + state, err := c.sandbox.storage.fetchContainerState(c.sandboxID, c.id) if err == nil { c.state = state } - process, err := c.pod.storage.fetchContainerProcess(c.podID, c.id) + process, err := c.sandbox.storage.fetchContainerProcess(c.sandboxID, c.id) if err == nil { c.process = process } @@ -467,9 +467,9 @@ func (c *Container) rollbackFailingContainerCreation() { } func (c *Container) checkBlockDeviceSupport() bool { - if !c.pod.config.HypervisorConfig.DisableBlockDeviceUse { - agentCaps := c.pod.agent.capabilities() - hypervisorCaps := c.pod.hypervisor.capabilities() + if !c.sandbox.config.HypervisorConfig.DisableBlockDeviceUse { + agentCaps := c.sandbox.agent.capabilities() + hypervisorCaps := c.sandbox.hypervisor.capabilities() if agentCaps.isBlockDeviceSupported() && hypervisorCaps.isBlockDeviceHotplugSupported() { return true @@ -479,14 +479,14 @@ func (c *Container) checkBlockDeviceSupport() bool { return false } -// createContainer creates and start a container inside a Pod. It has to be -// called only when a new container, not known by the pod, has to be created. -func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err error) { - if pod == nil { - return nil, errNeedPod +// createContainer creates and start a container inside a Sandbox. It has to be +// called only when a new container, not known by the sandbox, has to be created. +func createContainer(sandbox *Sandbox, contConfig ContainerConfig) (c *Container, err error) { + if sandbox == nil { + return nil, errNeedSandbox } - c, err = newContainer(pod, contConfig) + c, err = newContainer(sandbox, contConfig) if err != nil { return } @@ -526,7 +526,7 @@ func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err er return } - process, err := pod.agent.createContainer(c.pod, c) + process, err := sandbox.agent.createContainer(c.sandbox, c) if err != nil { return c, err } @@ -550,26 +550,26 @@ func (c *Container) delete() error { return fmt.Errorf("Container not ready or stopped, impossible to delete") } - // Remove the container from pod structure - if err := c.pod.removeContainer(c.id); err != nil { + // Remove the container from sandbox structure + if err := c.sandbox.removeContainer(c.id); err != nil { return err } - return c.pod.storage.deleteContainerResources(c.podID, c.id, nil) + return c.sandbox.storage.deleteContainerResources(c.sandboxID, c.id, nil) } -// checkPodRunning validates the container state. +// checkSandboxRunning validates the container state. // // cmd specifies the operation (or verb) that the retrieval is destined // for and is only used to make the returned error as descriptive as // possible. -func (c *Container) checkPodRunning(cmd string) error { +func (c *Container) checkSandboxRunning(cmd string) error { if cmd == "" { return fmt.Errorf("Cmd cannot be empty") } - if c.pod.state.State != StateRunning { - return fmt.Errorf("Pod not running, impossible to %s the container", cmd) + if c.sandbox.state.State != StateRunning { + return fmt.Errorf("Sandbox not running, impossible to %s the container", cmd) } return nil @@ -589,7 +589,7 @@ func (c *Container) getSystemMountInfo() { } func (c *Container) start() error { - if err := c.checkPodRunning("start"); err != nil { + if err := c.checkSandboxRunning("start"); err != nil { return err } @@ -602,7 +602,7 @@ func (c *Container) start() error { return err } - if err := c.pod.agent.startContainer(*(c.pod), c); err != nil { + if err := c.sandbox.agent.startContainer(*(c.sandbox), c); err != nil { c.Logger().WithError(err).Error("Failed to start container") if err := c.stop(); err != nil { @@ -627,8 +627,8 @@ func (c *Container) stop() error { return nil } - if c.pod.state.State != StateReady && c.pod.state.State != StateRunning { - return fmt.Errorf("Pod not ready or running, impossible to stop the container") + if c.sandbox.state.State != StateReady && c.sandbox.state.State != StateRunning { + return fmt.Errorf("Sandbox not ready or running, impossible to stop the container") } if err := c.state.validTransition(c.state.State, StateStopped); err != nil { @@ -656,7 +656,7 @@ func (c *Container) stop() error { // return an error, but instead try to kill it forcefully. if err := waitForShim(c.process.Pid); err != nil { // Force the container to be killed. - if err := c.pod.agent.killContainer(*(c.pod), *c, syscall.SIGKILL, true); err != nil { + if err := c.sandbox.agent.killContainer(*(c.sandbox), *c, syscall.SIGKILL, true); err != nil { return err } @@ -669,7 +669,7 @@ func (c *Container) stop() error { } } - if err := c.pod.agent.stopContainer(*(c.pod), *c); err != nil { + if err := c.sandbox.agent.stopContainer(*(c.sandbox), *c); err != nil { return err } @@ -689,7 +689,7 @@ func (c *Container) stop() error { } func (c *Container) enter(cmd Cmd) (*Process, error) { - if err := c.checkPodRunning("enter"); err != nil { + if err := c.checkSandboxRunning("enter"); err != nil { return nil, err } @@ -699,7 +699,7 @@ func (c *Container) enter(cmd Cmd) (*Process, error) { "impossible to enter") } - process, err := c.pod.agent.exec(c.pod, *c, cmd) + process, err := c.sandbox.agent.exec(c.sandbox, *c, cmd) if err != nil { return nil, err } @@ -708,19 +708,19 @@ func (c *Container) enter(cmd Cmd) (*Process, error) { } func (c *Container) kill(signal syscall.Signal, all bool) error { - if c.pod.state.State != StateReady && c.pod.state.State != StateRunning { - return fmt.Errorf("Pod not ready or running, impossible to signal the container") + if c.sandbox.state.State != StateReady && c.sandbox.state.State != StateRunning { + return fmt.Errorf("Sandbox not ready or running, impossible to signal the container") } if c.state.State != StateReady && c.state.State != StateRunning { return fmt.Errorf("Container not ready or running, impossible to signal the container") } - return c.pod.agent.killContainer(*(c.pod), *c, signal, all) + return c.sandbox.agent.killContainer(*(c.sandbox), *c, signal, all) } func (c *Container) processList(options ProcessListOptions) (ProcessList, error) { - if err := c.checkPodRunning("ps"); err != nil { + if err := c.checkSandboxRunning("ps"); err != nil { return nil, err } @@ -728,7 +728,7 @@ func (c *Container) processList(options ProcessListOptions) (ProcessList, error) return nil, fmt.Errorf("Container not running, impossible to list processes") } - return c.pod.agent.processListContainer(*(c.pod), *c, options) + return c.sandbox.agent.processListContainer(*(c.sandbox), *c, options) } func (c *Container) hotplugDrive() error { @@ -768,7 +768,7 @@ func (c *Container) hotplugDrive() error { "fs-type": fsType, }).Info("Block device detected") - driveIndex, err := c.pod.getAndSetPodBlockIndex() + driveIndex, err := c.sandbox.getAndSetSandboxBlockIndex() if err != nil { return err } @@ -782,7 +782,7 @@ func (c *Container) hotplugDrive() error { Index: driveIndex, } - if err := c.pod.hypervisor.hotplugAddDevice(drive, blockDev); err != nil { + if err := c.sandbox.hypervisor.hotplugAddDevice(drive, blockDev); err != nil { return err } c.setStateHotpluggedDrive(true) @@ -814,7 +814,7 @@ func (c *Container) removeDrive() (err error) { l := c.Logger().WithField("device-id", devID) l.Info("Unplugging block device") - if err := c.pod.hypervisor.hotplugRemoveDevice(drive, blockDev); err != nil { + if err := c.sandbox.hypervisor.hotplugRemoveDevice(drive, blockDev); err != nil { l.WithError(err).Info("Failed to unplug block device") return err } @@ -825,7 +825,7 @@ func (c *Container) removeDrive() (err error) { func (c *Container) attachDevices() error { for _, device := range c.devices { - if err := device.attach(c.pod.hypervisor, c); err != nil { + if err := device.attach(c.sandbox.hypervisor, c); err != nil { return err } } @@ -835,7 +835,7 @@ func (c *Container) attachDevices() error { func (c *Container) detachDevices() error { for _, device := range c.devices { - if err := device.detach(c.pod.hypervisor); err != nil { + if err := device.detach(c.sandbox.hypervisor); err != nil { return err } } @@ -852,11 +852,11 @@ func (c *Container) addResources() error { vCPUs := ConstraintsToVCPUs(c.config.Resources.CPUQuota, c.config.Resources.CPUPeriod) if vCPUs != 0 { virtLog.Debugf("hot adding %d vCPUs", vCPUs) - if err := c.pod.hypervisor.hotplugAddDevice(uint32(vCPUs), cpuDev); err != nil { + if err := c.sandbox.hypervisor.hotplugAddDevice(uint32(vCPUs), cpuDev); err != nil { return err } - return c.pod.agent.onlineCPUMem() + return c.sandbox.agent.onlineCPUMem() } return nil @@ -871,7 +871,7 @@ func (c *Container) removeResources() error { vCPUs := ConstraintsToVCPUs(c.config.Resources.CPUQuota, c.config.Resources.CPUPeriod) if vCPUs != 0 { virtLog.Debugf("hot removing %d vCPUs", vCPUs) - if err := c.pod.hypervisor.hotplugRemoveDevice(uint32(vCPUs), cpuDev); err != nil { + if err := c.sandbox.hypervisor.hotplugRemoveDevice(uint32(vCPUs), cpuDev); err != nil { return err } } diff --git a/virtcontainers/container_test.go b/virtcontainers/container_test.go index 4897e34a3..9bffb429c 100644 --- a/virtcontainers/container_test.go +++ b/virtcontainers/container_test.go @@ -79,33 +79,33 @@ func TestContainerSystemMountsInfo(t *testing.T) { assert.False(t, c.systemMountsInfo.BindMountDev) } -func TestContainerPod(t *testing.T) { - expectedPod := &Pod{} +func TestContainerSandbox(t *testing.T) { + expectedSandbox := &Sandbox{} container := Container{ - pod: expectedPod, + sandbox: expectedSandbox, } - pod := container.Pod() + sandbox := container.Sandbox() - if !reflect.DeepEqual(pod, expectedPod) { - t.Fatalf("Expecting %+v\nGot %+v", expectedPod, pod) + if !reflect.DeepEqual(sandbox, expectedSandbox) { + t.Fatalf("Expecting %+v\nGot %+v", expectedSandbox, sandbox) } } func TestContainerRemoveDrive(t *testing.T) { - pod := &Pod{} + sandbox := &Sandbox{} container := Container{ - pod: pod, - id: "testContainer", + sandbox: sandbox, + id: "testContainer", } container.state.Fstype = "" err := container.removeDrive() // hotplugRemoveDevice for hypervisor should not be called. - // test should pass without a hypervisor created for the container's pod. + // test should pass without a hypervisor created for the container's sandbox. if err != nil { t.Fatal("") } @@ -120,7 +120,7 @@ func TestContainerRemoveDrive(t *testing.T) { } container.state.HotpluggedDrive = true - pod.hypervisor = &mockHypervisor{} + sandbox.hypervisor = &mockHypervisor{} err = container.removeDrive() if err != nil { @@ -206,12 +206,12 @@ func TestContainerAddDriveDir(t *testing.T) { } fs := &filesystem{} - pod := &Pod{ - id: testPodID, + sandbox := &Sandbox{ + id: testSandboxID, storage: fs, hypervisor: &mockHypervisor{}, agent: &noopAgent{}, - config: &PodConfig{ + config: &SandboxConfig{ HypervisorConfig: HypervisorConfig{ DisableBlockDeviceUse: false, }, @@ -220,13 +220,13 @@ func TestContainerAddDriveDir(t *testing.T) { contID := "100" container := Container{ - pod: pod, - id: contID, - rootFs: fakeRootfs, + sandbox: sandbox, + id: contID, + rootFs: fakeRootfs, } // create state file - path := filepath.Join(runStoragePath, testPodID, container.ID()) + path := filepath.Join(runStoragePath, testSandboxID, container.ID()) err = os.MkdirAll(path, dirMode) if err != nil { t.Fatal(err) @@ -266,29 +266,29 @@ func TestContainerAddDriveDir(t *testing.T) { } } -func TestCheckPodRunningEmptyCmdFailure(t *testing.T) { +func TestCheckSandboxRunningEmptyCmdFailure(t *testing.T) { c := &Container{} - err := c.checkPodRunning("") + err := c.checkSandboxRunning("") assert.NotNil(t, err, "Should fail because provided command is empty") } -func TestCheckPodRunningNotRunningFailure(t *testing.T) { +func TestCheckSandboxRunningNotRunningFailure(t *testing.T) { c := &Container{ - pod: &Pod{}, + sandbox: &Sandbox{}, } - err := c.checkPodRunning("test_cmd") - assert.NotNil(t, err, "Should fail because pod state is empty") + err := c.checkSandboxRunning("test_cmd") + assert.NotNil(t, err, "Should fail because sandbox state is empty") } -func TestCheckPodRunningSuccessful(t *testing.T) { +func TestCheckSandboxRunningSuccessful(t *testing.T) { c := &Container{ - pod: &Pod{ + sandbox: &Sandbox{ state: State{ State: StateRunning, }, }, } - err := c.checkPodRunning("test_cmd") + err := c.checkSandboxRunning("test_cmd") assert.Nil(t, err, "%v", err) } @@ -312,7 +312,7 @@ func TestContainerAddResources(t *testing.T) { CPUQuota: 5000, CPUPeriod: 1000, } - c.pod = &Pod{ + c.sandbox = &Sandbox{ hypervisor: &mockHypervisor{}, agent: &noopAgent{}, } @@ -340,7 +340,7 @@ func TestContainerRemoveResources(t *testing.T) { CPUQuota: 5000, CPUPeriod: 1000, } - c.pod = &Pod{hypervisor: &mockHypervisor{}} + c.sandbox = &Sandbox{hypervisor: &mockHypervisor{}} err = c.removeResources() assert.Nil(err) } @@ -348,7 +348,7 @@ func TestContainerRemoveResources(t *testing.T) { func TestContainerEnterErrorsOnContainerStates(t *testing.T) { assert := assert.New(t) c := &Container{ - pod: &Pod{ + sandbox: &Sandbox{ state: State{ State: StateRunning, }, diff --git a/virtcontainers/device.go b/virtcontainers/device.go index e9943bdb2..123e26259 100644 --- a/virtcontainers/device.go +++ b/virtcontainers/device.go @@ -362,14 +362,14 @@ func (device *BlockDevice) attach(h hypervisor, c *Container) (err error) { device.DeviceInfo.ID = hex.EncodeToString(randBytes) - // Increment the block index for the pod. This is used to determine the name + // Increment the block index for the sandbox. This is used to determine the name // for the block device in the case where the block device is used as container // rootfs and the predicted block device name needs to be provided to the agent. - index, err := c.pod.getAndSetPodBlockIndex() + index, err := c.sandbox.getAndSetSandboxBlockIndex() defer func() { if err != nil { - c.pod.decrementPodBlockIndex() + c.sandbox.decrementSandboxBlockIndex() } }() @@ -397,7 +397,7 @@ func (device *BlockDevice) attach(h hypervisor, c *Container) (err error) { device.DeviceInfo.Hotplugged = true - if c.pod.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { + if c.sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { device.VirtPath = filepath.Join("/dev", driveName) } else { scsiAddr, err := getSCSIAddress(index) diff --git a/virtcontainers/device_test.go b/virtcontainers/device_test.go index f41593f31..6317f3dfa 100644 --- a/virtcontainers/device_test.go +++ b/virtcontainers/device_test.go @@ -326,12 +326,12 @@ func TestAttachBlockDevice(t *testing.T) { BlockDeviceDriver: VirtioBlock, } - config := &PodConfig{ + config := &SandboxConfig{ HypervisorConfig: hConfig, } - pod := &Pod{ - id: testPodID, + sandbox := &Sandbox{ + id: testSandboxID, storage: fs, hypervisor: hypervisor, config: config, @@ -339,12 +339,12 @@ func TestAttachBlockDevice(t *testing.T) { contID := "100" container := Container{ - pod: pod, - id: contID, + sandbox: sandbox, + id: contID, } // create state file - path := filepath.Join(runStoragePath, testPodID, container.ID()) + path := filepath.Join(runStoragePath, testSandboxID, container.ID()) err := os.MkdirAll(path, dirMode) if err != nil { t.Fatal(err) @@ -386,7 +386,7 @@ func TestAttachBlockDevice(t *testing.T) { err = device.detach(hypervisor) assert.Nil(t, err) - container.pod.config.HypervisorConfig.BlockDeviceDriver = VirtioSCSI + container.sandbox.config.HypervisorConfig.BlockDeviceDriver = VirtioSCSI err = device.attach(hypervisor, &container) assert.Nil(t, err) diff --git a/virtcontainers/doc.go b/virtcontainers/doc.go index 457eb8737..75eb601f9 100644 --- a/virtcontainers/doc.go +++ b/virtcontainers/doc.go @@ -17,12 +17,12 @@ /* Package virtcontainers manages hardware virtualized containers. Each container belongs to a set of containers sharing the same networking -namespace and storage, also known as a pod. +namespace and storage, also known as a sandbox. -Virtcontainers pods are hardware virtualized, i.e. they run on virtual machines. -Virtcontainers will create one VM per pod, and containers will be created as -processes within the pod VM. +Virtcontainers sandboxes are hardware virtualized, i.e. they run on virtual machines. +Virtcontainers will create one VM per sandbox, and containers will be created as +processes within the sandbox VM. -The virtcontainers package manages both pods and containers lifecycles. +The virtcontainers package manages both sandboxes and containers lifecycles. */ package virtcontainers diff --git a/virtcontainers/documentation/api/1.0/api.md b/virtcontainers/documentation/api/1.0/api.md index 9c1a0e456..b339d22ca 100644 --- a/virtcontainers/documentation/api/1.0/api.md +++ b/virtcontainers/documentation/api/1.0/api.md @@ -1,38 +1,38 @@ # virtcontainers 1.0 API The virtcontainers 1.0 API operates on two high level objects: -[Pods](#pod-api) and [containers](#container-api): +[Sandboxes](#sandbox-api) and [containers](#container-api): -* [Pod API](#pod-api) +* [Sandbox API](#sandbox-api) * [Container API](#container-api) * [Examples](#examples) -## Pod API +## Sandbox API -The virtcontainers 1.0 pod API manages hardware virtualized -[pod lifecycles](#pod-functions). The virtcontainers pod +The virtcontainers 1.0 sandbox API manages hardware virtualized +[sandbox lifecycles](#sandbox-functions). The virtcontainers sandbox semantics strictly follow the -[Kubernetes](https://kubernetes.io/docs/concepts/workloads/pods/pod/) ones. +[Kubernetes](https://kubernetes.io/docs/concepts/workloads/sandboxes/sandbox/) ones. -The pod API allows callers to [create](#createpod), [delete](#deletepod), -[start](#startpod), [stop](#stoppod), [run](#runpod), [pause](#pausepod), -[resume](resumepod) and [list](#listpod) VM (Virtual Machine) based pods. +The sandbox API allows callers to [create](#createsandbox), [delete](#deletesandbox), +[start](#startsandbox), [stop](#stopsandbox), [run](#runsandbox), [pause](#pausesandbox), +[resume](resumesandbox) and [list](#listsandbox) VM (Virtual Machine) based sandboxes. -To initially create a pod, the API caller must prepare a -[`PodConfig`](#podconfig) and pass it to either [`CreatePod`](#createpod) -or [`RunPod`](#runpod). Upon successful pod creation, the virtcontainers -API will return a [`VCPod`](#vcpod) interface back to the caller. +To initially create a sandbox, the API caller must prepare a +[`SandboxConfig`](#sandboxconfig) and pass it to either [`CreateSandbox`](#createsandbox) +or [`RunSandbox`](#runsandbox). Upon successful sandbox creation, the virtcontainers +API will return a [`VCSandbox`](#vcsandbox) interface back to the caller. -The `VCPod` interface is a pod abstraction hiding the internal and private -virtcontainers pod structure. It is a handle for API callers to manage the -pod lifecycle through the rest of the [pod API](#pod-functions). +The `VCSandbox` interface is a sandbox abstraction hiding the internal and private +virtcontainers sandbox structure. It is a handle for API callers to manage the +sandbox lifecycle through the rest of the [sandbox API](#sandbox-functions). -* [Structures](#pod-structures) -* [Functions](#pod-functions) +* [Structures](#sandbox-structures) +* [Functions](#sandbox-functions) -### Pod Structures +### Sandbox Structures -* [PodConfig](#podconfig) +* [SandboxConfig](#sandboxconfig) * [Resources](#resources) * [HypervisorType](#hypervisortype) * [HypervisorConfig](#hypervisorconfig) @@ -48,12 +48,12 @@ pod lifecycle through the rest of the [pod API](#pod-functions). * [Cmd](#cmd) * [Mount](#mount) * [DeviceInfo](#deviceinfo) -* [VCPod](#vcpod) +* [VCSandbox](#vcsandbox) -#### `PodConfig` +#### `SandboxConfig` ```Go -// PodConfig is a Pod configuration. -type PodConfig struct { +// SandboxConfig is a Sandbox configuration. +type SandboxConfig struct { ID string Hostname string @@ -61,7 +61,7 @@ type PodConfig struct { // Field specific to OCI specs, needed to setup all the hooks Hooks Hooks - // VMConfig is the VM configuration to set for this pod. + // VMConfig is the VM configuration to set for this sandbox. VMConfig Resources HypervisorType HypervisorType @@ -79,12 +79,12 @@ type PodConfig struct { NetworkModel NetworkModel NetworkConfig NetworkConfig - // Volumes is a list of shared volumes between the host and the Pod. + // Volumes is a list of shared volumes between the host and the Sandbox. Volumes []Volume - // Containers describe the list of containers within a Pod. + // Containers describe the list of containers within a Sandbox. // This list can be empty and populated by adding containers - // to the Pod a posteriori. + // to the Sandbox a posteriori. Containers []ContainerConfig // Annotations keys must be unique strings and must be name-spaced @@ -155,11 +155,11 @@ type HypervisorConfig struct { Debug bool // DefaultVCPUs specifies default number of vCPUs for the VM. - // Pod configuration VMConfig.VCPUs overwrites this. + // Sandbox configuration VMConfig.VCPUs overwrites this. DefaultVCPUs uint32 // DefaultMem specifies default memory size in MiB for the VM. - // Pod configuration VMConfig.Memory overwrites this. + // Sandbox configuration VMConfig.Memory overwrites this. DefaultMemSz uint32 // DefaultBridges specifies default number of bridges for the VM. @@ -188,7 +188,7 @@ type HypervisorConfig struct { ##### `AgentType` ```Go -// AgentType describes the type of guest agent a Pod should run. +// AgentType describes the type of guest agent a Sandbox should run. type AgentType string const ( @@ -456,11 +456,11 @@ type DeviceInfo struct { } ``` -#### `VCPod` +#### `VCSandbox` ```Go -// VCPod is the Pod interface -// (required since virtcontainers.Pod only contains private fields) -type VCPod interface { +// VCSandbox is the Sandbox interface +// (required since virtcontainers.Sandbox only contains private fields) +type VCSandbox interface { Annotations(key string) (string, error) GetAllContainers() []VCContainer GetAnnotations() map[string]string @@ -470,84 +470,84 @@ type VCPod interface { } ``` -### Pod Functions +### Sandbox Functions -* [CreatePod](#createpod) -* [DeletePod](#deletepod) -* [StartPod](#startpod) -* [StopPod](#stoppod) -* [RunPod](#runpod) -* [ListPod](#listpod) -* [StatusPod](#statuspod) -* [PausePod](#pausepod) -* [ResumePod](#resumepod) +* [CreateSandbox](#createsandbox) +* [DeleteSandbox](#deletesandbox) +* [StartSandbox](#startsandbox) +* [StopSandbox](#stopsandbox) +* [RunSandbox](#runsandbox) +* [ListSandbox](#listsandbox) +* [StatusSandbox](#statussandbox) +* [PauseSandbox](#pausesandbox) +* [ResumeSandbox](#resumesandbox) -#### `CreatePod` +#### `CreateSandbox` ```Go -// CreatePod is the virtcontainers pod creation entry point. -// CreatePod creates a pod and its containers. It does not start them. -func CreatePod(podConfig PodConfig) (VCPod, error) +// CreateSandbox is the virtcontainers sandbox creation entry point. +// CreateSandbox creates a sandbox and its containers. It does not start them. +func CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) ``` -#### `DeletePod` +#### `DeleteSandbox` ```Go -// DeletePod is the virtcontainers pod deletion entry point. -// DeletePod will stop an already running container and then delete it. -func DeletePod(podID string) (VCPod, error) +// DeleteSandbox is the virtcontainers sandbox deletion entry point. +// DeleteSandbox will stop an already running container and then delete it. +func DeleteSandbox(sandboxID string) (VCSandbox, error) ``` -#### `StartPod` +#### `StartSandbox` ```Go -// StartPod is the virtcontainers pod starting entry point. -// StartPod will talk to the given hypervisor to start an existing -// pod and all its containers. -func StartPod(podID string) (VCPod, error) +// StartSandbox is the virtcontainers sandbox starting entry point. +// StartSandbox will talk to the given hypervisor to start an existing +// sandbox and all its containers. +func StartSandbox(sandboxID string) (VCSandbox, error) ``` -#### `StopPod` +#### `StopSandbox` ```Go -// StopPod is the virtcontainers pod stopping entry point. -// StopPod will talk to the given agent to stop an existing pod -// and destroy all containers within that pod. -func StopPod(podID string) (VCPod, error) +// StopSandbox is the virtcontainers sandbox stopping entry point. +// StopSandbox will talk to the given agent to stop an existing sandbox +// and destroy all containers within that sandbox. +func StopSandbox(sandboxID string) (VCSandbox, error) ``` -#### `RunPod` +#### `RunSandbox` ```Go -// RunPod is the virtcontainers pod running entry point. -// RunPod creates a pod and its containers and then it starts them. -func RunPod(podConfig PodConfig) (VCPod, error) +// RunSandbox is the virtcontainers sandbox running entry point. +// RunSandbox creates a sandbox and its containers and then it starts them. +func RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) ``` -#### `ListPod` +#### `ListSandbox` ```Go -// ListPod is the virtcontainers pod listing entry point. -func ListPod() ([]PodStatus, error) +// ListSandbox is the virtcontainers sandbox listing entry point. +func ListSandbox() ([]SandboxStatus, error) ``` -#### `StatusPod` +#### `StatusSandbox` ```Go -// StatusPod is the virtcontainers pod status entry point. -func StatusPod(podID string) (PodStatus, error) +// StatusSandbox is the virtcontainers sandbox status entry point. +func StatusSandbox(sandboxID string) (SandboxStatus, error) ``` -#### `PausePod` +#### `PauseSandbox` ```Go -// PausePod is the virtcontainers pausing entry point which pauses an -// already running pod. -func PausePod(podID string) (VCPod, error) +// PauseSandbox is the virtcontainers pausing entry point which pauses an +// already running sandbox. +func PauseSandbox(sandboxID string) (VCSandbox, error) ``` -#### `ResumePod` +#### `ResumeSandbox` ```Go -// ResumePod is the virtcontainers resuming entry point which resumes -// (or unpauses) and already paused pod. -func ResumePod(podID string) (VCPod, error) +// ResumeSandbox is the virtcontainers resuming entry point which resumes +// (or unpauses) and already paused sandbox. +func ResumeSandbox(sandboxID string) (VCSandbox, error) ``` ## Container API -The virtcontainers 1.0 container API manages pod +The virtcontainers 1.0 container API manages sandbox [container lifecycles](#container-functions). A virtcontainers container is process running inside a containerized @@ -556,8 +556,8 @@ a virtcontainers container is just a regular container running inside a virtual machine's guest OS. A virtcontainers container always belong to one and only one -virtcontainers pod, again following the -[Kubernetes](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/) +virtcontainers sandbox, again following the +[Kubernetes](https://kubernetes.io/docs/concepts/workloads/sandboxes/sandbox-overview/) logic and semantics. The container API allows callers to [create](#createcontainer), @@ -566,12 +566,12 @@ The container API allows callers to [create](#createcontainer), allows for running [additional processes](#entercontainer) inside a specific container. -As a virtcontainers container is always linked to a pod, the entire container -API always takes a pod ID as its first argument. +As a virtcontainers container is always linked to a sandbox, the entire container +API always takes a sandbox ID as its first argument. To create a container, the API caller must prepare a [`ContainerConfig`](#containerconfig) and pass it to -[`CreateContainer`](#createcontainer) together with a pod ID. Upon successful +[`CreateContainer`](#createcontainer) together with a sandbox ID. Upon successful container creation, the virtcontainers API will return a [`VCContainer`](#vccontainer) interface back to the caller. @@ -729,10 +729,10 @@ type DeviceInfo struct { // Process gathers data related to a container process. type Process struct { // Token is the process execution context ID. It must be - // unique per pod. + // unique per sandbox. // Token is used to manipulate processes for containers // that have not started yet, and later identify them - // uniquely within a pod. + // uniquely within a sandbox. Token string // Pid is the process ID as seen by the host software @@ -786,7 +786,7 @@ type VCContainer interface { GetPid() int GetToken() string ID() string - Pod() VCPod + Sandbox() VCSandbox Process() Process SetPid(pid int) error } @@ -806,70 +806,70 @@ type VCContainer interface { #### `CreateContainer` ```Go // CreateContainer is the virtcontainers container creation entry point. -// CreateContainer creates a container on a given pod. -func CreateContainer(podID string, containerConfig ContainerConfig) (VCPod, VCContainer, error) +// CreateContainer creates a container on a given sandbox. +func CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) ``` #### `DeleteContainer` ```Go // DeleteContainer is the virtcontainers container deletion entry point. -// DeleteContainer deletes a Container from a Pod. If the container is running, +// DeleteContainer deletes a Container from a Sandbox. If the container is running, // it needs to be stopped first. -func DeleteContainer(podID, containerID string) (VCContainer, error) +func DeleteContainer(sandboxID, containerID string) (VCContainer, error) ``` #### `StartContainer` ```Go // StartContainer is the virtcontainers container starting entry point. // StartContainer starts an already created container. -func StartContainer(podID, containerID string) (VCContainer, error) +func StartContainer(sandboxID, containerID string) (VCContainer, error) ``` #### `StopContainer` ```Go // StopContainer is the virtcontainers container stopping entry point. // StopContainer stops an already running container. -func StopContainer(podID, containerID string) (VCContainer, error) +func StopContainer(sandboxID, containerID string) (VCContainer, error) ``` #### `EnterContainer` ```Go // EnterContainer is the virtcontainers container command execution entry point. // EnterContainer enters an already running container and runs a given command. -func EnterContainer(podID, containerID string, cmd Cmd) (VCPod, VCContainer, *Process, error) +func EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) ``` #### `StatusContainer` ```Go // StatusContainer is the virtcontainers container status entry point. // StatusContainer returns a detailed container status. -func StatusContainer(podID, containerID string) (ContainerStatus, error) +func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) ``` #### `KillContainer` ```Go // KillContainer is the virtcontainers entry point to send a signal -// to a container running inside a pod. If all is true, all processes in +// to a container running inside a sandbox. If all is true, all processes in // the container will be sent the signal. -func KillContainer(podID, containerID string, signal syscall.Signal, all bool) error +func KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error ``` #### `ProcessListContainer` ```Go // ProcessListContainer is the virtcontainers entry point to list // processes running inside a container -func ProcessListContainer(podID, containerID string, options ProcessListOptions) (ProcessList, error) +func ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) ``` ## Examples -### Preparing and running a pod +### Preparing and running a sandbox ```Go -// This example creates and starts a single container pod, +// This example creates and starts a single container sandbox, // using qemu as the hypervisor and hyperstart as the VM agent. -func Example_createAndStartPod() { +func Example_createAndStartSandbox() { envs := []vc.EnvVar{ { Var: "PATH", @@ -906,11 +906,11 @@ func Example_createAndStartPod() { Memory: 1024, } - // The pod configuration: + // The sandbox configuration: // - One container // - Hypervisor is QEMU // - Agent is hyperstart - podConfig := vc.PodConfig{ + sandboxConfig := vc.SandboxConfig{ VMConfig: vmConfig, HypervisorType: vc.QemuHypervisor, @@ -922,9 +922,9 @@ func Example_createAndStartPod() { Containers: []vc.ContainerConfig{container}, } - _, err := vc.RunPod(podConfig) + _, err := vc.RunSandbox(sandboxConfig) if err != nil { - fmt.Printf("Could not run pod: %s", err) + fmt.Printf("Could not run sandbox: %s", err) } return diff --git a/virtcontainers/errors.go b/virtcontainers/errors.go index fe0f5d250..c8bd59dea 100644 --- a/virtcontainers/errors.go +++ b/virtcontainers/errors.go @@ -22,10 +22,10 @@ import ( // common error objects used for argument checking var ( - errNeedPod = errors.New("Pod must be specified") - errNeedPodID = errors.New("Pod ID cannot be empty") + errNeedSandbox = errors.New("Sandbox must be specified") + errNeedSandboxID = errors.New("Sandbox ID cannot be empty") errNeedContainerID = errors.New("Container ID cannot be empty") errNeedFile = errors.New("File cannot be empty") errNeedState = errors.New("State cannot be empty") - errInvalidResource = errors.New("Invalid pod resource") + errInvalidResource = errors.New("Invalid sandbox resource") ) diff --git a/virtcontainers/example_pod_run_test.go b/virtcontainers/example_pod_run_test.go index d246ada94..12cc73378 100644 --- a/virtcontainers/example_pod_run_test.go +++ b/virtcontainers/example_pod_run_test.go @@ -25,9 +25,9 @@ import ( const containerRootfs = "/var/lib/container/bundle/" -// This example creates and starts a single container pod, +// This example creates and starts a single container sandbox, // using qemu as the hypervisor and hyperstart as the VM agent. -func Example_createAndStartPod() { +func Example_createAndStartSandbox() { envs := []vc.EnvVar{ { Var: "PATH", @@ -63,11 +63,11 @@ func Example_createAndStartPod() { Memory: 1024, } - // The pod configuration: + // The sandbox configuration: // - One container // - Hypervisor is QEMU // - Agent is hyperstart - podConfig := vc.PodConfig{ + sandboxConfig := vc.SandboxConfig{ VMConfig: vmConfig, HypervisorType: vc.QemuHypervisor, @@ -79,9 +79,9 @@ func Example_createAndStartPod() { Containers: []vc.ContainerConfig{container}, } - _, err := vc.RunPod(podConfig) + _, err := vc.RunSandbox(sandboxConfig) if err != nil { - fmt.Printf("Could not run pod: %s", err) + fmt.Printf("Could not run sandbox: %s", err) } return diff --git a/virtcontainers/filesystem.go b/virtcontainers/filesystem.go index 69e9adf46..d474ecf3e 100644 --- a/virtcontainers/filesystem.go +++ b/virtcontainers/filesystem.go @@ -26,32 +26,32 @@ import ( "github.com/sirupsen/logrus" ) -// podResource is an int representing a pod resource type. +// sandboxResource is an int representing a sandbox resource type. // -// Note that some are specific to the pod itself and others can apply to -// pods and containers. -type podResource int +// Note that some are specific to the sandbox itself and others can apply to +// sandboxes and containers. +type sandboxResource int const ( // configFileType represents a configuration file type - configFileType podResource = iota + configFileType sandboxResource = iota // stateFileType represents a state file type stateFileType - // networkFileType represents a network file type (pod only) + // networkFileType represents a network file type (sandbox only) networkFileType - // hypervisorFileType represents a hypervisor file type (pod only) + // hypervisorFileType represents a hypervisor file type (sandbox only) hypervisorFileType - // agentFileType represents an agent file type (pod only) + // agentFileType represents an agent file type (sandbox only) agentFileType // processFileType represents a process file type processFileType - // lockFileType represents a lock file type (pod only) + // lockFileType represents a lock file type (sandbox only) lockFileType // mountsFileType represents a mount file type @@ -61,13 +61,13 @@ const ( devicesFileType ) -// configFile is the file name used for every JSON pod configuration. +// configFile is the file name used for every JSON sandbox configuration. const configFile = "config.json" -// stateFile is the file name storing a pod state. +// stateFile is the file name storing a sandbox state. const stateFile = "state.json" -// networkFile is the file name storing a pod network. +// networkFile is the file name storing a sandbox network. const networkFile = "network.json" // hypervisorFile is the file name storing a hypervisor's state. @@ -79,7 +79,7 @@ const agentFile = "agent.json" // processFile is the file name storing a container process. const processFile = "process.json" -// lockFile is the file name locking the usage of a pod. +// lockFile is the file name locking the usage of a sandbox. const lockFileName = "lock" const mountsFile = "mounts.json" @@ -91,55 +91,55 @@ const devicesFile = "devices.json" const dirMode = os.FileMode(0750) | os.ModeDir // storagePathSuffix is the suffix used for all storage paths -const storagePathSuffix = "/virtcontainers/pods" +const storagePathSuffix = "/virtcontainers/sandboxes" -// configStoragePath is the pod configuration directory. -// It will contain one config.json file for each created pod. +// configStoragePath is the sandbox configuration directory. +// It will contain one config.json file for each created sandbox. var configStoragePath = filepath.Join("/var/lib", storagePathSuffix) -// runStoragePath is the pod runtime directory. -// It will contain one state.json and one lock file for each created pod. +// runStoragePath is the sandbox runtime directory. +// It will contain one state.json and one lock file for each created sandbox. var runStoragePath = filepath.Join("/run", storagePathSuffix) // resourceStorage is the virtcontainers resources (configuration, state, etc...) // storage interface. // The default resource storage implementation is filesystem. type resourceStorage interface { - // Create all resources for a pod - createAllResources(pod Pod) error + // Create all resources for a sandbox + createAllResources(sandbox Sandbox) error // Resources URIs functions return both the URI // for the actual resource and the URI base. - containerURI(podID, containerID string, resource podResource) (string, string, error) - podURI(podID string, resource podResource) (string, string, error) + containerURI(sandboxID, containerID string, resource sandboxResource) (string, string, error) + sandboxURI(sandboxID string, resource sandboxResource) (string, string, error) - // Pod resources - storePodResource(podID string, resource podResource, data interface{}) error - deletePodResources(podID string, resources []podResource) error - fetchPodConfig(podID string) (PodConfig, error) - fetchPodState(podID string) (State, error) - fetchPodNetwork(podID string) (NetworkNamespace, error) - storePodNetwork(podID string, networkNS NetworkNamespace) error + // Sandbox resources + storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error + deleteSandboxResources(sandboxID string, resources []sandboxResource) error + fetchSandboxConfig(sandboxID string) (SandboxConfig, error) + fetchSandboxState(sandboxID string) (State, error) + fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error) + storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error // Hypervisor resources - fetchHypervisorState(podID string, state interface{}) error - storeHypervisorState(podID string, state interface{}) error + fetchHypervisorState(sandboxID string, state interface{}) error + storeHypervisorState(sandboxID string, state interface{}) error // Agent resources - fetchAgentState(podID string, state interface{}) error - storeAgentState(podID string, state interface{}) error + fetchAgentState(sandboxID string, state interface{}) error + storeAgentState(sandboxID string, state interface{}) error // Container resources - storeContainerResource(podID, containerID string, resource podResource, data interface{}) error - deleteContainerResources(podID, containerID string, resources []podResource) error - fetchContainerConfig(podID, containerID string) (ContainerConfig, error) - fetchContainerState(podID, containerID string) (State, error) - fetchContainerProcess(podID, containerID string) (Process, error) - storeContainerProcess(podID, containerID string, process Process) error - fetchContainerMounts(podID, containerID string) ([]Mount, error) - storeContainerMounts(podID, containerID string, mounts []Mount) error - fetchContainerDevices(podID, containerID string) ([]Device, error) - storeContainerDevices(podID, containerID string, devices []Device) error + storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error + deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error + fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error) + fetchContainerState(sandboxID, containerID string) (State, error) + fetchContainerProcess(sandboxID, containerID string) (Process, error) + storeContainerProcess(sandboxID, containerID string, process Process) error + fetchContainerMounts(sandboxID, containerID string) ([]Mount, error) + storeContainerMounts(sandboxID, containerID string, mounts []Mount) error + fetchContainerDevices(sandboxID, containerID string) ([]Device, error) + storeContainerDevices(sandboxID, containerID string, devices []Device) error } // filesystem is a resourceStorage interface implementation for a local filesystem. @@ -151,37 +151,37 @@ func (fs *filesystem) Logger() *logrus.Entry { return virtLog.WithField("subsystem", "filesystem") } -func (fs *filesystem) createAllResources(pod Pod) (err error) { - for _, resource := range []podResource{stateFileType, configFileType} { - _, path, _ := fs.podURI(pod.id, resource) +func (fs *filesystem) createAllResources(sandbox Sandbox) (err error) { + for _, resource := range []sandboxResource{stateFileType, configFileType} { + _, path, _ := fs.sandboxURI(sandbox.id, resource) err = os.MkdirAll(path, dirMode) if err != nil { return err } } - for _, container := range pod.containers { - for _, resource := range []podResource{stateFileType, configFileType} { - _, path, _ := fs.containerURI(pod.id, container.id, resource) + for _, container := range sandbox.containers { + for _, resource := range []sandboxResource{stateFileType, configFileType} { + _, path, _ := fs.containerURI(sandbox.id, container.id, resource) err = os.MkdirAll(path, dirMode) if err != nil { - fs.deletePodResources(pod.id, nil) + fs.deleteSandboxResources(sandbox.id, nil) return err } } } - podlockFile, _, err := fs.podURI(pod.id, lockFileType) + sandboxlockFile, _, err := fs.sandboxURI(sandbox.id, lockFileType) if err != nil { - fs.deletePodResources(pod.id, nil) + fs.deleteSandboxResources(sandbox.id, nil) return err } - _, err = os.Stat(podlockFile) + _, err = os.Stat(sandboxlockFile) if err != nil { - lockFile, err := os.Create(podlockFile) + lockFile, err := os.Create(sandboxlockFile) if err != nil { - fs.deletePodResources(pod.id, nil) + fs.deleteSandboxResources(sandbox.id, nil) return err } lockFile.Close() @@ -262,7 +262,7 @@ func (fs *filesystem) storeDeviceFile(file string, data interface{}) error { return nil } -func (fs *filesystem) fetchFile(file string, resource podResource, data interface{}) error { +func (fs *filesystem) fetchFile(file string, resource sandboxResource, data interface{}) error { if file == "" { return errNeedFile } @@ -332,27 +332,27 @@ func (fs *filesystem) fetchDeviceFile(fileData []byte, devices *[]Device) error } // resourceNeedsContainerID determines if the specified -// podResource needs a containerID. Since some podResources can -// be used for both pods and containers, it is necessary to specify -// whether the resource is being used in a pod-specific context using -// the podSpecific parameter. -func resourceNeedsContainerID(podSpecific bool, resource podResource) bool { +// sandboxResource needs a containerID. Since some sandboxResources can +// be used for both sandboxes and containers, it is necessary to specify +// whether the resource is being used in a sandbox-specific context using +// the sandboxSpecific parameter. +func resourceNeedsContainerID(sandboxSpecific bool, resource sandboxResource) bool { switch resource { case lockFileType, networkFileType, hypervisorFileType, agentFileType: - // pod-specific resources + // sandbox-specific resources return false default: - return !podSpecific + return !sandboxSpecific } } -func resourceDir(podSpecific bool, podID, containerID string, resource podResource) (string, error) { - if podID == "" { - return "", errNeedPodID +func resourceDir(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource) (string, error) { + if sandboxID == "" { + return "", errNeedSandboxID } - if resourceNeedsContainerID(podSpecific, resource) == true && containerID == "" { + if resourceNeedsContainerID(sandboxSpecific, resource) == true && containerID == "" { return "", errNeedContainerID } @@ -369,23 +369,23 @@ func resourceDir(podSpecific bool, podID, containerID string, resource podResour return "", errInvalidResource } - dirPath := filepath.Join(path, podID, containerID) + dirPath := filepath.Join(path, sandboxID, containerID) return dirPath, nil } -// If podSpecific is true, the resource is being applied for an empty -// pod (meaning containerID may be blank). +// If sandboxSpecific is true, the resource is being applied for an empty +// sandbox (meaning containerID may be blank). // Note that this function defers determining if containerID can be // blank to resourceDIR() -func (fs *filesystem) resourceURI(podSpecific bool, podID, containerID string, resource podResource) (string, string, error) { - if podID == "" { - return "", "", errNeedPodID +func (fs *filesystem) resourceURI(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource) (string, string, error) { + if sandboxID == "" { + return "", "", errNeedSandboxID } var filename string - dirPath, err := resourceDir(podSpecific, podID, containerID, resource) + dirPath, err := resourceDir(sandboxSpecific, sandboxID, containerID, resource) if err != nil { return "", "", err } @@ -422,30 +422,30 @@ func (fs *filesystem) resourceURI(podSpecific bool, podID, containerID string, r return filePath, dirPath, nil } -func (fs *filesystem) containerURI(podID, containerID string, resource podResource) (string, string, error) { - if podID == "" { - return "", "", errNeedPodID +func (fs *filesystem) containerURI(sandboxID, containerID string, resource sandboxResource) (string, string, error) { + if sandboxID == "" { + return "", "", errNeedSandboxID } if containerID == "" { return "", "", errNeedContainerID } - return fs.resourceURI(false, podID, containerID, resource) + return fs.resourceURI(false, sandboxID, containerID, resource) } -func (fs *filesystem) podURI(podID string, resource podResource) (string, string, error) { - return fs.resourceURI(true, podID, "", resource) +func (fs *filesystem) sandboxURI(sandboxID string, resource sandboxResource) (string, string, error) { + return fs.resourceURI(true, sandboxID, "", resource) } // commonResourceChecks performs basic checks common to both setting and -// getting a podResource. -func (fs *filesystem) commonResourceChecks(podSpecific bool, podID, containerID string, resource podResource) error { - if podID == "" { - return errNeedPodID +// getting a sandboxResource. +func (fs *filesystem) commonResourceChecks(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource) error { + if sandboxID == "" { + return errNeedSandboxID } - if resourceNeedsContainerID(podSpecific, resource) == true && containerID == "" { + if resourceNeedsContainerID(sandboxSpecific, resource) == true && containerID == "" { return errNeedContainerID } @@ -465,12 +465,12 @@ func (fs *filesystem) commonResourceChecks(podSpecific bool, podID, containerID return nil } -func (fs *filesystem) storePodAndContainerConfigResource(podSpecific bool, podID, containerID string, resource podResource, file interface{}) error { +func (fs *filesystem) storeSandboxAndContainerConfigResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, file interface{}) error { if resource != configFileType { return errInvalidResource } - configFile, _, err := fs.resourceURI(podSpecific, podID, containerID, configFileType) + configFile, _, err := fs.resourceURI(sandboxSpecific, sandboxID, containerID, configFileType) if err != nil { return err } @@ -478,12 +478,12 @@ func (fs *filesystem) storePodAndContainerConfigResource(podSpecific bool, podID return fs.storeFile(configFile, file) } -func (fs *filesystem) storeStateResource(podSpecific bool, podID, containerID string, resource podResource, file interface{}) error { +func (fs *filesystem) storeStateResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, file interface{}) error { if resource != stateFileType { return errInvalidResource } - stateFile, _, err := fs.resourceURI(podSpecific, podID, containerID, stateFileType) + stateFile, _, err := fs.resourceURI(sandboxSpecific, sandboxID, containerID, stateFileType) if err != nil { return err } @@ -491,13 +491,13 @@ func (fs *filesystem) storeStateResource(podSpecific bool, podID, containerID st return fs.storeFile(stateFile, file) } -func (fs *filesystem) storeNetworkResource(podSpecific bool, podID, containerID string, resource podResource, file interface{}) error { +func (fs *filesystem) storeNetworkResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, file interface{}) error { if resource != networkFileType { return errInvalidResource } - // pod only resource - networkFile, _, err := fs.resourceURI(true, podID, containerID, networkFileType) + // sandbox only resource + networkFile, _, err := fs.resourceURI(true, sandboxID, containerID, networkFileType) if err != nil { return err } @@ -505,12 +505,12 @@ func (fs *filesystem) storeNetworkResource(podSpecific bool, podID, containerID return fs.storeFile(networkFile, file) } -func (fs *filesystem) storeProcessResource(podSpecific bool, podID, containerID string, resource podResource, file interface{}) error { +func (fs *filesystem) storeProcessResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, file interface{}) error { if resource != processFileType { return errInvalidResource } - processFile, _, err := fs.resourceURI(podSpecific, podID, containerID, processFileType) + processFile, _, err := fs.resourceURI(sandboxSpecific, sandboxID, containerID, processFileType) if err != nil { return err } @@ -518,12 +518,12 @@ func (fs *filesystem) storeProcessResource(podSpecific bool, podID, containerID return fs.storeFile(processFile, file) } -func (fs *filesystem) storeMountResource(podSpecific bool, podID, containerID string, resource podResource, file interface{}) error { +func (fs *filesystem) storeMountResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, file interface{}) error { if resource != mountsFileType { return errInvalidResource } - mountsFile, _, err := fs.resourceURI(podSpecific, podID, containerID, mountsFileType) + mountsFile, _, err := fs.resourceURI(sandboxSpecific, sandboxID, containerID, mountsFileType) if err != nil { return err } @@ -531,12 +531,12 @@ func (fs *filesystem) storeMountResource(podSpecific bool, podID, containerID st return fs.storeFile(mountsFile, file) } -func (fs *filesystem) storeDeviceResource(podSpecific bool, podID, containerID string, resource podResource, file interface{}) error { +func (fs *filesystem) storeDeviceResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, file interface{}) error { if resource != devicesFileType { return errInvalidResource } - devicesFile, _, err := fs.resourceURI(podSpecific, podID, containerID, devicesFileType) + devicesFile, _, err := fs.resourceURI(sandboxSpecific, sandboxID, containerID, devicesFileType) if err != nil { return err } @@ -544,41 +544,41 @@ func (fs *filesystem) storeDeviceResource(podSpecific bool, podID, containerID s return fs.storeDeviceFile(devicesFile, file) } -func (fs *filesystem) storeResource(podSpecific bool, podID, containerID string, resource podResource, data interface{}) error { - if err := fs.commonResourceChecks(podSpecific, podID, containerID, resource); err != nil { +func (fs *filesystem) storeResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, data interface{}) error { + if err := fs.commonResourceChecks(sandboxSpecific, sandboxID, containerID, resource); err != nil { return err } switch file := data.(type) { - case PodConfig, ContainerConfig: - return fs.storePodAndContainerConfigResource(podSpecific, podID, containerID, resource, file) + case SandboxConfig, ContainerConfig: + return fs.storeSandboxAndContainerConfigResource(sandboxSpecific, sandboxID, containerID, resource, file) case State: - return fs.storeStateResource(podSpecific, podID, containerID, resource, file) + return fs.storeStateResource(sandboxSpecific, sandboxID, containerID, resource, file) case NetworkNamespace: - return fs.storeNetworkResource(podSpecific, podID, containerID, resource, file) + return fs.storeNetworkResource(sandboxSpecific, sandboxID, containerID, resource, file) case Process: - return fs.storeProcessResource(podSpecific, podID, containerID, resource, file) + return fs.storeProcessResource(sandboxSpecific, sandboxID, containerID, resource, file) case []Mount: - return fs.storeMountResource(podSpecific, podID, containerID, resource, file) + return fs.storeMountResource(sandboxSpecific, sandboxID, containerID, resource, file) case []Device: - return fs.storeDeviceResource(podSpecific, podID, containerID, resource, file) + return fs.storeDeviceResource(sandboxSpecific, sandboxID, containerID, resource, file) default: return fmt.Errorf("Invalid resource data type") } } -func (fs *filesystem) fetchResource(podSpecific bool, podID, containerID string, resource podResource, data interface{}) error { - if err := fs.commonResourceChecks(podSpecific, podID, containerID, resource); err != nil { +func (fs *filesystem) fetchResource(sandboxSpecific bool, sandboxID, containerID string, resource sandboxResource, data interface{}) error { + if err := fs.commonResourceChecks(sandboxSpecific, sandboxID, containerID, resource); err != nil { return err } - path, _, err := fs.resourceURI(podSpecific, podID, containerID, resource) + path, _, err := fs.resourceURI(sandboxSpecific, sandboxID, containerID, resource) if err != nil { return err } @@ -586,54 +586,54 @@ func (fs *filesystem) fetchResource(podSpecific bool, podID, containerID string, return fs.fetchFile(path, resource, data) } -func (fs *filesystem) storePodResource(podID string, resource podResource, data interface{}) error { - return fs.storeResource(true, podID, "", resource, data) +func (fs *filesystem) storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error { + return fs.storeResource(true, sandboxID, "", resource, data) } -func (fs *filesystem) fetchPodConfig(podID string) (PodConfig, error) { - var podConfig PodConfig +func (fs *filesystem) fetchSandboxConfig(sandboxID string) (SandboxConfig, error) { + var sandboxConfig SandboxConfig - if err := fs.fetchResource(true, podID, "", configFileType, &podConfig); err != nil { - return PodConfig{}, err + if err := fs.fetchResource(true, sandboxID, "", configFileType, &sandboxConfig); err != nil { + return SandboxConfig{}, err } - return podConfig, nil + return sandboxConfig, nil } -func (fs *filesystem) fetchPodState(podID string) (State, error) { +func (fs *filesystem) fetchSandboxState(sandboxID string) (State, error) { var state State - if err := fs.fetchResource(true, podID, "", stateFileType, &state); err != nil { + if err := fs.fetchResource(true, sandboxID, "", stateFileType, &state); err != nil { return State{}, err } return state, nil } -func (fs *filesystem) fetchPodNetwork(podID string) (NetworkNamespace, error) { +func (fs *filesystem) fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error) { var networkNS NetworkNamespace - if err := fs.fetchResource(true, podID, "", networkFileType, &networkNS); err != nil { + if err := fs.fetchResource(true, sandboxID, "", networkFileType, &networkNS); err != nil { return NetworkNamespace{}, err } return networkNS, nil } -func (fs *filesystem) fetchHypervisorState(podID string, state interface{}) error { - return fs.fetchResource(true, podID, "", hypervisorFileType, state) +func (fs *filesystem) fetchHypervisorState(sandboxID string, state interface{}) error { + return fs.fetchResource(true, sandboxID, "", hypervisorFileType, state) } -func (fs *filesystem) fetchAgentState(podID string, state interface{}) error { - return fs.fetchResource(true, podID, "", agentFileType, state) +func (fs *filesystem) fetchAgentState(sandboxID string, state interface{}) error { + return fs.fetchResource(true, sandboxID, "", agentFileType, state) } -func (fs *filesystem) storePodNetwork(podID string, networkNS NetworkNamespace) error { - return fs.storePodResource(podID, networkFileType, networkNS) +func (fs *filesystem) storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error { + return fs.storeSandboxResource(sandboxID, networkFileType, networkNS) } -func (fs *filesystem) storeHypervisorState(podID string, state interface{}) error { - hypervisorFile, _, err := fs.resourceURI(true, podID, "", hypervisorFileType) +func (fs *filesystem) storeHypervisorState(sandboxID string, state interface{}) error { + hypervisorFile, _, err := fs.resourceURI(true, sandboxID, "", hypervisorFileType) if err != nil { return err } @@ -641,8 +641,8 @@ func (fs *filesystem) storeHypervisorState(podID string, state interface{}) erro return fs.storeFile(hypervisorFile, state) } -func (fs *filesystem) storeAgentState(podID string, state interface{}) error { - agentFile, _, err := fs.resourceURI(true, podID, "", agentFileType) +func (fs *filesystem) storeAgentState(sandboxID string, state interface{}) error { + agentFile, _, err := fs.resourceURI(true, sandboxID, "", agentFileType) if err != nil { return err } @@ -650,13 +650,13 @@ func (fs *filesystem) storeAgentState(podID string, state interface{}) error { return fs.storeFile(agentFile, state) } -func (fs *filesystem) deletePodResources(podID string, resources []podResource) error { +func (fs *filesystem) deleteSandboxResources(sandboxID string, resources []sandboxResource) error { if resources == nil { - resources = []podResource{configFileType, stateFileType} + resources = []sandboxResource{configFileType, stateFileType} } for _, resource := range resources { - _, dir, err := fs.podURI(podID, resource) + _, dir, err := fs.sandboxURI(sandboxID, resource) if err != nil { return err } @@ -670,87 +670,87 @@ func (fs *filesystem) deletePodResources(podID string, resources []podResource) return nil } -func (fs *filesystem) storeContainerResource(podID, containerID string, resource podResource, data interface{}) error { - if podID == "" { - return errNeedPodID +func (fs *filesystem) storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error { + if sandboxID == "" { + return errNeedSandboxID } if containerID == "" { return errNeedContainerID } - return fs.storeResource(false, podID, containerID, resource, data) + return fs.storeResource(false, sandboxID, containerID, resource, data) } -func (fs *filesystem) fetchContainerConfig(podID, containerID string) (ContainerConfig, error) { +func (fs *filesystem) fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error) { var config ContainerConfig - if err := fs.fetchResource(false, podID, containerID, configFileType, &config); err != nil { + if err := fs.fetchResource(false, sandboxID, containerID, configFileType, &config); err != nil { return ContainerConfig{}, err } return config, nil } -func (fs *filesystem) fetchContainerState(podID, containerID string) (State, error) { +func (fs *filesystem) fetchContainerState(sandboxID, containerID string) (State, error) { var state State - if err := fs.fetchResource(false, podID, containerID, stateFileType, &state); err != nil { + if err := fs.fetchResource(false, sandboxID, containerID, stateFileType, &state); err != nil { return State{}, err } return state, nil } -func (fs *filesystem) fetchContainerProcess(podID, containerID string) (Process, error) { +func (fs *filesystem) fetchContainerProcess(sandboxID, containerID string) (Process, error) { var process Process - if err := fs.fetchResource(false, podID, containerID, processFileType, &process); err != nil { + if err := fs.fetchResource(false, sandboxID, containerID, processFileType, &process); err != nil { return Process{}, err } return process, nil } -func (fs *filesystem) storeContainerProcess(podID, containerID string, process Process) error { - return fs.storeContainerResource(podID, containerID, processFileType, process) +func (fs *filesystem) storeContainerProcess(sandboxID, containerID string, process Process) error { + return fs.storeContainerResource(sandboxID, containerID, processFileType, process) } -func (fs *filesystem) fetchContainerMounts(podID, containerID string) ([]Mount, error) { +func (fs *filesystem) fetchContainerMounts(sandboxID, containerID string) ([]Mount, error) { var mounts []Mount - if err := fs.fetchResource(false, podID, containerID, mountsFileType, &mounts); err != nil { + if err := fs.fetchResource(false, sandboxID, containerID, mountsFileType, &mounts); err != nil { return []Mount{}, err } return mounts, nil } -func (fs *filesystem) fetchContainerDevices(podID, containerID string) ([]Device, error) { +func (fs *filesystem) fetchContainerDevices(sandboxID, containerID string) ([]Device, error) { var devices []Device - if err := fs.fetchResource(false, podID, containerID, devicesFileType, &devices); err != nil { + if err := fs.fetchResource(false, sandboxID, containerID, devicesFileType, &devices); err != nil { return []Device{}, err } return devices, nil } -func (fs *filesystem) storeContainerMounts(podID, containerID string, mounts []Mount) error { - return fs.storeContainerResource(podID, containerID, mountsFileType, mounts) +func (fs *filesystem) storeContainerMounts(sandboxID, containerID string, mounts []Mount) error { + return fs.storeContainerResource(sandboxID, containerID, mountsFileType, mounts) } -func (fs *filesystem) storeContainerDevices(podID, containerID string, devices []Device) error { - return fs.storeContainerResource(podID, containerID, devicesFileType, devices) +func (fs *filesystem) storeContainerDevices(sandboxID, containerID string, devices []Device) error { + return fs.storeContainerResource(sandboxID, containerID, devicesFileType, devices) } -func (fs *filesystem) deleteContainerResources(podID, containerID string, resources []podResource) error { +func (fs *filesystem) deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error { if resources == nil { - resources = []podResource{configFileType, stateFileType} + resources = []sandboxResource{configFileType, stateFileType} } for _, resource := range resources { - _, dir, err := fs.podURI(podID, resource) + _, dir, err := fs.sandboxURI(sandboxID, resource) if err != nil { return err } diff --git a/virtcontainers/filesystem_test.go b/virtcontainers/filesystem_test.go index 5b00461de..5a3f19fd1 100644 --- a/virtcontainers/filesystem_test.go +++ b/virtcontainers/filesystem_test.go @@ -34,52 +34,52 @@ func TestFilesystemCreateAllResourcesSuccessful(t *testing.T) { {ID: "100"}, } - podConfig := &PodConfig{ + sandboxConfig := &SandboxConfig{ Containers: contConfigs, } - pod := Pod{ - id: testPodID, + sandbox := Sandbox{ + id: testSandboxID, storage: fs, - config: podConfig, + config: sandboxConfig, } - if err := pod.newContainers(); err != nil { + if err := sandbox.newContainers(); err != nil { t.Fatal(err) } - podConfigPath := filepath.Join(configStoragePath, testPodID) - podRunPath := filepath.Join(runStoragePath, testPodID) + sandboxConfigPath := filepath.Join(configStoragePath, testSandboxID) + sandboxRunPath := filepath.Join(runStoragePath, testSandboxID) - os.RemoveAll(podConfigPath) - os.RemoveAll(podRunPath) + os.RemoveAll(sandboxConfigPath) + os.RemoveAll(sandboxRunPath) for _, container := range contConfigs { - configPath := filepath.Join(configStoragePath, testPodID, container.ID) + configPath := filepath.Join(configStoragePath, testSandboxID, container.ID) os.RemoveAll(configPath) - runPath := filepath.Join(runStoragePath, testPodID, container.ID) + runPath := filepath.Join(runStoragePath, testSandboxID, container.ID) os.RemoveAll(runPath) } - err := fs.createAllResources(pod) + err := fs.createAllResources(sandbox) if err != nil { t.Fatal(err) } // Check resources - _, err = os.Stat(podConfigPath) + _, err = os.Stat(sandboxConfigPath) if err != nil { t.Fatal(err) } - _, err = os.Stat(podRunPath) + _, err = os.Stat(sandboxRunPath) if err != nil { t.Fatal(err) } for _, container := range contConfigs { - configPath := filepath.Join(configStoragePath, testPodID, container.ID) + configPath := filepath.Join(configStoragePath, testSandboxID, container.ID) s, err := os.Stat(configPath) if err != nil { t.Fatal(err) @@ -90,7 +90,7 @@ func TestFilesystemCreateAllResourcesSuccessful(t *testing.T) { t.Fatal(fmt.Errorf("dirmode [%v] != expected [%v]", s.Mode(), dirMode)) } - runPath := filepath.Join(runStoragePath, testPodID, container.ID) + runPath := filepath.Join(runStoragePath, testSandboxID, container.ID) s, err = os.Stat(runPath) if err != nil { t.Fatal(err) @@ -104,12 +104,12 @@ func TestFilesystemCreateAllResourcesSuccessful(t *testing.T) { } } -func TestFilesystemCreateAllResourcesFailingPodIDEmpty(t *testing.T) { +func TestFilesystemCreateAllResourcesFailingSandboxIDEmpty(t *testing.T) { fs := &filesystem{} - pod := Pod{} + sandbox := Sandbox{} - err := fs.createAllResources(pod) + err := fs.createAllResources(sandbox) if err == nil { t.Fatal() } @@ -122,12 +122,12 @@ func TestFilesystemCreateAllResourcesFailingContainerIDEmpty(t *testing.T) { {id: ""}, } - pod := Pod{ - id: testPodID, + sandbox := Sandbox{ + id: testSandboxID, containers: containers, } - err := fs.createAllResources(pod) + err := fs.createAllResources(sandbox) if err == nil { t.Fatal() } @@ -234,7 +234,7 @@ func TestFilesystemFetchFileSuccessful(t *testing.T) { } f.Close() - err = fs.fetchFile(path, podResource(-1), &data) + err = fs.fetchFile(path, sandboxResource(-1), &data) if err != nil { t.Fatal(err) } @@ -256,7 +256,7 @@ func TestFilesystemFetchFileFailingNoFile(t *testing.T) { path := filepath.Join(testDir, "testFilesystem") os.Remove(path) - err := fs.fetchFile(path, podResource(-1), &data) + err := fs.fetchFile(path, sandboxResource(-1), &data) if err == nil { t.Fatal() } @@ -275,7 +275,7 @@ func TestFilesystemFetchFileFailingUnMarshalling(t *testing.T) { } f.Close() - err = fs.fetchFile(path, podResource(-1), data) + err = fs.fetchFile(path, sandboxResource(-1), data) if err == nil { t.Fatal() } @@ -286,7 +286,7 @@ func TestFilesystemFetchContainerConfigSuccessful(t *testing.T) { contID := "100" rootFs := "rootfs" - contConfigDir := filepath.Join(configStoragePath, testPodID, contID) + contConfigDir := filepath.Join(configStoragePath, testSandboxID, contID) os.MkdirAll(contConfigDir, dirMode) path := filepath.Join(contConfigDir, configFile) @@ -305,7 +305,7 @@ func TestFilesystemFetchContainerConfigSuccessful(t *testing.T) { } f.Close() - data, err := fs.fetchContainerConfig(testPodID, contID) + data, err := fs.fetchContainerConfig(testSandboxID, contID) if err != nil { t.Fatal(err) } @@ -323,13 +323,13 @@ func TestFilesystemFetchContainerConfigSuccessful(t *testing.T) { func TestFilesystemFetchContainerConfigFailingContIDEmpty(t *testing.T) { fs := &filesystem{} - _, err := fs.fetchContainerConfig(testPodID, "") + _, err := fs.fetchContainerConfig(testSandboxID, "") if err == nil { t.Fatal() } } -func TestFilesystemFetchContainerConfigFailingPodIDEmpty(t *testing.T) { +func TestFilesystemFetchContainerConfigFailingSandboxIDEmpty(t *testing.T) { fs := &filesystem{} _, err := fs.fetchContainerConfig("", "100") @@ -342,7 +342,7 @@ func TestFilesystemFetchContainerMountsSuccessful(t *testing.T) { fs := &filesystem{} contID := "100" - contMountsDir := filepath.Join(runStoragePath, testPodID, contID) + contMountsDir := filepath.Join(runStoragePath, testSandboxID, contID) os.MkdirAll(contMountsDir, dirMode) path := filepath.Join(contMountsDir, mountsFile) @@ -378,7 +378,7 @@ func TestFilesystemFetchContainerMountsSuccessful(t *testing.T) { } f.Close() - data, err := fs.fetchContainerMounts(testPodID, contID) + data, err := fs.fetchContainerMounts(testSandboxID, contID) if err != nil { data, _ := ioutil.ReadFile(path) t.Logf("Data from file : %s", string(data[:])) @@ -404,7 +404,7 @@ func TestFilesystemFetchContainerMountsInvalidType(t *testing.T) { fs := &filesystem{} contID := "100" - contMountsDir := filepath.Join(runStoragePath, testPodID, contID) + contMountsDir := filepath.Join(runStoragePath, testSandboxID, contID) os.MkdirAll(contMountsDir, dirMode) path := filepath.Join(contMountsDir, mountsFile) @@ -423,7 +423,7 @@ func TestFilesystemFetchContainerMountsInvalidType(t *testing.T) { } f.Close() - _, err = fs.fetchContainerMounts(testPodID, contID) + _, err = fs.fetchContainerMounts(testSandboxID, contID) if err == nil { t.Fatal() } @@ -432,13 +432,13 @@ func TestFilesystemFetchContainerMountsInvalidType(t *testing.T) { func TestFilesystemFetchContainerMountsFailingContIDEmpty(t *testing.T) { fs := &filesystem{} - _, err := fs.fetchContainerMounts(testPodID, "") + _, err := fs.fetchContainerMounts(testSandboxID, "") if err == nil { t.Fatal() } } -func TestFilesystemFetchContainerMountsFailingPodIDEmpty(t *testing.T) { +func TestFilesystemFetchContainerMountsFailingSandboxIDEmpty(t *testing.T) { fs := &filesystem{} _, err := fs.fetchContainerMounts("", "100") @@ -447,7 +447,7 @@ func TestFilesystemFetchContainerMountsFailingPodIDEmpty(t *testing.T) { } } -func TestFilesystemResourceDirFailingPodIDEmpty(t *testing.T) { +func TestFilesystemResourceDirFailingSandboxIDEmpty(t *testing.T) { for _, b := range []bool{true, false} { _, err := resourceDir(b, "", "", configFileType) if err == nil { @@ -458,7 +458,7 @@ func TestFilesystemResourceDirFailingPodIDEmpty(t *testing.T) { func TestFilesystemResourceDirFailingInvalidResource(t *testing.T) { for _, b := range []bool{true, false} { - _, err := resourceDir(b, testPodID, "100", podResource(-1)) + _, err := resourceDir(b, testSandboxID, "100", sandboxResource(-1)) if err == nil { t.Fatal() } @@ -469,19 +469,19 @@ func TestFilesystemResourceURIFailingResourceDir(t *testing.T) { fs := &filesystem{} for _, b := range []bool{true, false} { - _, _, err := fs.resourceURI(b, testPodID, "100", podResource(-1)) + _, _, err := fs.resourceURI(b, testSandboxID, "100", sandboxResource(-1)) if err == nil { t.Fatal() } } } -func TestFilesystemStoreResourceFailingPodConfigStateFileType(t *testing.T) { +func TestFilesystemStoreResourceFailingSandboxConfigStateFileType(t *testing.T) { fs := &filesystem{} - data := PodConfig{} + data := SandboxConfig{} for _, b := range []bool{true, false} { - err := fs.storeResource(b, testPodID, "100", stateFileType, data) + err := fs.storeResource(b, testSandboxID, "100", stateFileType, data) if err == nil { t.Fatal() } @@ -493,16 +493,16 @@ func TestFilesystemStoreResourceFailingContainerConfigStateFileType(t *testing.T data := ContainerConfig{} for _, b := range []bool{true, false} { - err := fs.storeResource(b, testPodID, "100", stateFileType, data) + err := fs.storeResource(b, testSandboxID, "100", stateFileType, data) if err == nil { t.Fatal() } } } -func TestFilesystemStoreResourceFailingPodConfigResourceURI(t *testing.T) { +func TestFilesystemStoreResourceFailingSandboxConfigResourceURI(t *testing.T) { fs := &filesystem{} - data := PodConfig{} + data := SandboxConfig{} for _, b := range []bool{true, false} { err := fs.storeResource(b, "", "100", configFileType, data) @@ -529,7 +529,7 @@ func TestFilesystemStoreResourceFailingStateConfigFileType(t *testing.T) { data := State{} for _, b := range []bool{true, false} { - err := fs.storeResource(b, testPodID, "100", configFileType, data) + err := fs.storeResource(b, testSandboxID, "100", configFileType, data) if err == nil { t.Fatal() } @@ -553,7 +553,7 @@ func TestFilesystemStoreResourceFailingWrongDataType(t *testing.T) { data := TestNoopStructure{} for _, b := range []bool{true, false} { - err := fs.storeResource(b, testPodID, "100", configFileType, data) + err := fs.storeResource(b, testSandboxID, "100", configFileType, data) if err == nil { t.Fatal() } @@ -564,7 +564,7 @@ func TestFilesystemFetchResourceFailingWrongResourceType(t *testing.T) { fs := &filesystem{} for _, b := range []bool{true, false} { - if err := fs.fetchResource(b, testPodID, "100", lockFileType, nil); err == nil { + if err := fs.fetchResource(b, testSandboxID, "100", lockFileType, nil); err == nil { t.Fatal() } } diff --git a/virtcontainers/hack/virtc/README.md b/virtcontainers/hack/virtc/README.md index c5cfbde4f..7fea49e5a 100644 --- a/virtcontainers/hack/virtc/README.md +++ b/virtcontainers/hack/virtc/README.md @@ -5,7 +5,7 @@ This is example software; unlike other projects like runc, runv, or rkt, virtcon ## Virtc example -Here we explain how to use the pod and container API from `virtc` command line. +Here we explain how to use the sandbox and container API from `virtc` command line. ### Prepare your environment @@ -93,81 +93,81 @@ The shim will be installed at the following location: `/usr/libexec/clear-contai _Start a new container_ ``` -# ./virtc container start --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc container start --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` _Execute a new process on a running container_ ``` -# ./virtc container enter --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc container enter --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` -_Start a pod with container(s) previously created_ +_Start a sandbox with container(s) previously created_ ``` -# ./virtc pod start --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc sandbox start --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` -Notice that in both cases, the `--pod-id` and `--id` options have been defined when previously creating a pod and a container. +Notice that in both cases, the `--sandbox-id` and `--id` options have been defined when previously creating a sandbox and a container. ### Run virtc -All following commands __MUST__ be run as root. By default, and unless you decide to modify it and rebuild it, `virtc` starts empty pods (no container started). +All following commands __MUST__ be run as root. By default, and unless you decide to modify it and rebuild it, `virtc` starts empty sandboxes (no container started). -#### Run a new pod (Create + Start) +#### Run a new sandbox (Create + Start) ``` -# ./virtc pod run --agent="hyperstart" --network="CNI" --proxy="ccProxy" --proxy-url="unix:///var/run/clearcontainers/proxy.sock" --shim="ccShim" --shim-path="/usr/libexec/cc-shim" +# ./virtc sandbox run --agent="hyperstart" --network="CNI" --proxy="ccProxy" --proxy-url="unix:///var/run/clearcontainers/proxy.sock" --shim="ccShim" --shim-path="/usr/libexec/cc-shim" ``` -#### Create a new pod +#### Create a new sandbox ``` -# ./virtc pod run --agent="hyperstart" --network="CNI" --proxy="ccProxy" --proxy-url="unix:///var/run/clearcontainers/proxy.sock" --shim="ccShim" --shim-path="/usr/libexec/cc-shim" +# ./virtc sandbox run --agent="hyperstart" --network="CNI" --proxy="ccProxy" --proxy-url="unix:///var/run/clearcontainers/proxy.sock" --shim="ccShim" --shim-path="/usr/libexec/cc-shim" ``` This will generate output similar to the following: ``` -Pod 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 created +Sandbox 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 created ``` -#### Start an existing pod +#### Start an existing sandbox ``` -# ./virtc pod start --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc sandbox start --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` This will generate output similar to the following: ``` -Pod 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 started +Sandbox 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 started ``` -#### Stop an existing pod +#### Stop an existing sandbox ``` -# ./virtc pod stop --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc sandbox stop --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` This will generate output similar to the following: ``` -Pod 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 stopped +Sandbox 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 stopped ``` -#### Get the status of an existing pod and its containers +#### Get the status of an existing sandbox and its containers ``` -# ./virtc pod status --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc sandbox status --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` -This will generate output similar to the following (assuming the pod has been started): +This will generate output similar to the following (assuming the sandbox has been started): ``` -POD ID STATE HYPERVISOR AGENT +SB ID STATE HYPERVISOR AGENT 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 running qemu hyperstart CONTAINER ID STATE ``` -#### Delete an existing pod +#### Delete an existing sandbox ``` -# ./virtc pod delete --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc sandbox delete --id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` This will generate output similar to the following: ``` -Pod 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 deleted +Sandbox 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 deleted ``` -#### List all existing pods +#### List all existing sandboxes ``` -# ./virtc pod list +# ./virtc sandbox list ``` This should generate that kind of output ``` -POD ID STATE HYPERVISOR AGENT +SB ID STATE HYPERVISOR AGENT 306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 running qemu hyperstart 92d73f74-4514-4a0d-81df-db1cc4c59100 running qemu hyperstart 7088148c-049b-4be7-b1be-89b3ae3c551c ready qemu hyperstart @@ -176,7 +176,7 @@ POD ID STATE HYPERVISOR AGENT #### Create a new container ``` -# ./virtc container create --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 --rootfs="/tmp/bundles/busybox/rootfs" --cmd="/bin/ifconfig" --console="/dev/pts/30" +# ./virtc container create --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 --rootfs="/tmp/bundles/busybox/rootfs" --cmd="/bin/ifconfig" --console="/dev/pts/30" ``` This will generate output similar to the following: ``` @@ -190,7 +190,7 @@ That way, you make sure you have a dedicated input/output terminal. #### Start an existing container ``` -# ./virtc container start --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc container start --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` This will generate output similar to the following: ``` @@ -199,7 +199,7 @@ Container 1 started #### Run a new process on an existing container ``` -# ./virtc container enter --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 --cmd="/bin/ps" --console="/dev/pts/30" +# ./virtc container enter --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 --cmd="/bin/ps" --console="/dev/pts/30" ``` This will generate output similar to the following: ``` @@ -213,7 +213,7 @@ That way, you make sure you have a dedicated input/output terminal. #### Stop an existing container ``` -# ./virtc container stop --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc container stop --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` This will generate output similar to the following: ``` @@ -222,7 +222,7 @@ Container 1 stopped #### Delete an existing container ``` -# ./virtc container delete --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc container delete --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` This will generate output similar to the following: ``` @@ -231,7 +231,7 @@ Container 1 deleted #### Get the status of an existing container ``` -# ./virtc container status --id=1 --pod-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 +# ./virtc container status --id=1 --sandbox-id=306ecdcf-0a6f-4a06-a03e-86a7b868ffc8 ``` This will generate output similar to the following (assuming the container has been started): ``` diff --git a/virtcontainers/hack/virtc/main.go b/virtcontainers/hack/virtc/main.go index d0e86a1ff..e483b0a6f 100644 --- a/virtcontainers/hack/virtc/main.go +++ b/virtcontainers/hack/virtc/main.go @@ -37,10 +37,10 @@ var statusFormat = "%s\t%s\n" var ( errNeedContainerID = errors.New("Container ID cannot be empty") - errNeedPodID = errors.New("Pod ID cannot be empty") + errNeedSandboxID = errors.New("Sandbox ID cannot be empty") ) -var podConfigFlags = []cli.Flag{ +var sandboxConfigFlags = []cli.Flag{ cli.GenericFlag{ Name: "agent", Value: new(vc.AgentType), @@ -50,7 +50,7 @@ var podConfigFlags = []cli.Flag{ cli.StringFlag{ Name: "id", Value: "", - Usage: "the pod identifier (default: auto-generated)", + Usage: "the sandbox identifier (default: auto-generated)", }, cli.StringFlag{ @@ -104,13 +104,13 @@ var podConfigFlags = []cli.Flag{ cli.UintFlag{ Name: "cpus", Value: 0, - Usage: "the number of virtual cpus available for this pod", + Usage: "the number of virtual cpus available for this sandbox", }, cli.UintFlag{ Name: "memory", Value: 0, - Usage: "the amount of memory available for this pod in MiB", + Usage: "the amount of memory available for this sandbox in MiB", }, } @@ -143,7 +143,7 @@ func buildKernelParams(config *vc.HypervisorConfig) error { return nil } -func buildPodConfig(context *cli.Context) (vc.PodConfig, error) { +func buildSandboxConfig(context *cli.Context) (vc.SandboxConfig, error) { var agConfig interface{} hyperCtlSockName := context.String("hyper-ctl-sock-name") @@ -154,22 +154,22 @@ func buildPodConfig(context *cli.Context) (vc.PodConfig, error) { vmMemory := context.Uint("vm-memory") agentType, ok := context.Generic("agent").(*vc.AgentType) if ok != true { - return vc.PodConfig{}, fmt.Errorf("Could not convert agent type") + return vc.SandboxConfig{}, fmt.Errorf("Could not convert agent type") } networkModel, ok := context.Generic("network").(*vc.NetworkModel) if ok != true { - return vc.PodConfig{}, fmt.Errorf("Could not convert network model") + return vc.SandboxConfig{}, fmt.Errorf("Could not convert network model") } proxyType, ok := context.Generic("proxy").(*vc.ProxyType) if ok != true { - return vc.PodConfig{}, fmt.Errorf("Could not convert proxy type") + return vc.SandboxConfig{}, fmt.Errorf("Could not convert proxy type") } shimType, ok := context.Generic("shim").(*vc.ShimType) if ok != true { - return vc.PodConfig{}, fmt.Errorf("Could not convert shim type") + return vc.SandboxConfig{}, fmt.Errorf("Could not convert shim type") } kernelPath := "/usr/share/clear-containers/vmlinuz.container" @@ -184,7 +184,7 @@ func buildPodConfig(context *cli.Context) (vc.PodConfig, error) { } if err := buildKernelParams(&hypervisorConfig); err != nil { - return vc.PodConfig{}, err + return vc.SandboxConfig{}, err } netConfig := vc.NetworkConfig{ @@ -211,11 +211,11 @@ func buildPodConfig(context *cli.Context) (vc.PodConfig, error) { id := context.String("id") if id == "" { - // auto-generate pod name + // auto-generate sandbox name id = uuid.Generate().String() } - podConfig := vc.PodConfig{ + sandboxConfig := vc.SandboxConfig{ ID: id, VMConfig: vmConfig, @@ -237,7 +237,7 @@ func buildPodConfig(context *cli.Context) (vc.PodConfig, error) { Containers: []vc.ContainerConfig{}, } - return podConfig, nil + return sandboxConfig, nil } func getProxyConfig(proxyType vc.ProxyType, path string) vc.ProxyConfig { @@ -271,10 +271,10 @@ func getShimConfig(shimType vc.ShimType, path string) interface{} { return shimConfig } -// checkRequiredPodArgs checks to ensure the required command-line -// arguments have been specified for the pod sub-command specified by +// checkRequiredSandboxArgs checks to ensure the required command-line +// arguments have been specified for the sandbox sub-command specified by // the context argument. -func checkRequiredPodArgs(context *cli.Context) error { +func checkRequiredSandboxArgs(context *cli.Context) error { if context == nil { return fmt.Errorf("BUG: need Context") } @@ -294,7 +294,7 @@ func checkRequiredPodArgs(context *cli.Context) error { id := context.String("id") if id == "" { - return errNeedPodID + return errNeedSandboxID } return nil @@ -311,9 +311,9 @@ func checkRequiredContainerArgs(context *cli.Context) error { // sub-sub-command name name := context.Command.Name - podID := context.String("pod-id") - if podID == "" { - return errNeedPodID + sandboxID := context.String("sandbox-id") + if sandboxID == "" { + return errNeedSandboxID } rootfs := context.String("rootfs") @@ -329,38 +329,38 @@ func checkRequiredContainerArgs(context *cli.Context) error { return nil } -func runPod(context *cli.Context) error { - podConfig, err := buildPodConfig(context) +func runSandbox(context *cli.Context) error { + sandboxConfig, err := buildSandboxConfig(context) if err != nil { - return fmt.Errorf("Could not build pod config: %s", err) + return fmt.Errorf("Could not build sandbox config: %s", err) } - _, err = vc.RunPod(podConfig) + _, err = vc.RunSandbox(sandboxConfig) if err != nil { - return fmt.Errorf("Could not run pod: %s", err) + return fmt.Errorf("Could not run sandbox: %s", err) } return nil } -func createPod(context *cli.Context) error { - podConfig, err := buildPodConfig(context) +func createSandbox(context *cli.Context) error { + sandboxConfig, err := buildSandboxConfig(context) if err != nil { - return fmt.Errorf("Could not build pod config: %s", err) + return fmt.Errorf("Could not build sandbox config: %s", err) } - p, err := vc.CreatePod(podConfig) + p, err := vc.CreateSandbox(sandboxConfig) if err != nil { - return fmt.Errorf("Could not create pod: %s", err) + return fmt.Errorf("Could not create sandbox: %s", err) } - fmt.Printf("Pod %s created\n", p.ID()) + fmt.Printf("Sandbox %s created\n", p.ID()) return nil } -func checkPodArgs(context *cli.Context, f func(context *cli.Context) error) error { - if err := checkRequiredPodArgs(context); err != nil { +func checkSandboxArgs(context *cli.Context, f func(context *cli.Context) error) error { + if err := checkRequiredSandboxArgs(context); err != nil { return err } @@ -375,73 +375,73 @@ func checkContainerArgs(context *cli.Context, f func(context *cli.Context) error return f(context) } -func deletePod(context *cli.Context) error { - p, err := vc.DeletePod(context.String("id")) +func deleteSandbox(context *cli.Context) error { + p, err := vc.DeleteSandbox(context.String("id")) if err != nil { - return fmt.Errorf("Could not delete pod: %s", err) + return fmt.Errorf("Could not delete sandbox: %s", err) } - fmt.Printf("Pod %s deleted\n", p.ID()) + fmt.Printf("Sandbox %s deleted\n", p.ID()) return nil } -func startPod(context *cli.Context) error { - p, err := vc.StartPod(context.String("id")) +func startSandbox(context *cli.Context) error { + p, err := vc.StartSandbox(context.String("id")) if err != nil { - return fmt.Errorf("Could not start pod: %s", err) + return fmt.Errorf("Could not start sandbox: %s", err) } - fmt.Printf("Pod %s started\n", p.ID()) + fmt.Printf("Sandbox %s started\n", p.ID()) return nil } -func stopPod(context *cli.Context) error { - p, err := vc.StopPod(context.String("id")) +func stopSandbox(context *cli.Context) error { + p, err := vc.StopSandbox(context.String("id")) if err != nil { - return fmt.Errorf("Could not stop pod: %s", err) + return fmt.Errorf("Could not stop sandbox: %s", err) } - fmt.Printf("Pod %s stopped\n", p.ID()) + fmt.Printf("Sandbox %s stopped\n", p.ID()) return nil } -func pausePod(context *cli.Context) error { - p, err := vc.PausePod(context.String("id")) +func pauseSandbox(context *cli.Context) error { + p, err := vc.PauseSandbox(context.String("id")) if err != nil { - return fmt.Errorf("Could not pause pod: %s", err) + return fmt.Errorf("Could not pause sandbox: %s", err) } - fmt.Printf("Pod %s paused\n", p.ID()) + fmt.Printf("Sandbox %s paused\n", p.ID()) return nil } -func resumePod(context *cli.Context) error { - p, err := vc.ResumePod(context.String("id")) +func resumeSandbox(context *cli.Context) error { + p, err := vc.ResumeSandbox(context.String("id")) if err != nil { - return fmt.Errorf("Could not resume pod: %s", err) + return fmt.Errorf("Could not resume sandbox: %s", err) } - fmt.Printf("Pod %s resumed\n", p.ID()) + fmt.Printf("Sandbox %s resumed\n", p.ID()) return nil } -func listPods(context *cli.Context) error { - podStatusList, err := vc.ListPod() +func listSandboxes(context *cli.Context) error { + sandboxStatusList, err := vc.ListSandbox() if err != nil { - return fmt.Errorf("Could not list pod: %s", err) + return fmt.Errorf("Could not list sandbox: %s", err) } w := tabwriter.NewWriter(os.Stdout, 2, 8, 1, '\t', 0) - fmt.Fprintf(w, listFormat, "POD ID", "STATE", "HYPERVISOR", "AGENT") + fmt.Fprintf(w, listFormat, "SB ID", "STATE", "HYPERVISOR", "AGENT") - for _, podStatus := range podStatusList { + for _, sandboxStatus := range sandboxStatusList { fmt.Fprintf(w, listFormat, - podStatus.ID, podStatus.State.State, podStatus.Hypervisor, podStatus.Agent) + sandboxStatus.ID, sandboxStatus.State.State, sandboxStatus.Hypervisor, sandboxStatus.Agent) } w.Flush() @@ -449,21 +449,21 @@ func listPods(context *cli.Context) error { return nil } -func statusPod(context *cli.Context) error { - podStatus, err := vc.StatusPod(context.String("id")) +func statusSandbox(context *cli.Context) error { + sandboxStatus, err := vc.StatusSandbox(context.String("id")) if err != nil { - return fmt.Errorf("Could not get pod status: %s", err) + return fmt.Errorf("Could not get sandbox status: %s", err) } w := tabwriter.NewWriter(os.Stdout, 2, 8, 1, '\t', 0) - fmt.Fprintf(w, listFormat, "POD ID", "STATE", "HYPERVISOR", "AGENT") + fmt.Fprintf(w, listFormat, "SB ID", "STATE", "HYPERVISOR", "AGENT") fmt.Fprintf(w, listFormat+"\n", - podStatus.ID, podStatus.State.State, podStatus.Hypervisor, podStatus.Agent) + sandboxStatus.ID, sandboxStatus.State.State, sandboxStatus.Hypervisor, sandboxStatus.Agent) fmt.Fprintf(w, statusFormat, "CONTAINER ID", "STATE") - for _, contStatus := range podStatus.ContainersStatus { + for _, contStatus := range sandboxStatus.ContainersStatus { fmt.Fprintf(w, statusFormat, contStatus.ID, contStatus.State.State) } @@ -472,119 +472,119 @@ func statusPod(context *cli.Context) error { return nil } -var runPodCommand = cli.Command{ +var runSandboxCommand = cli.Command{ Name: "run", - Usage: "run a pod", - Flags: podConfigFlags, + Usage: "run a sandbox", + Flags: sandboxConfigFlags, Action: func(context *cli.Context) error { - return checkPodArgs(context, runPod) + return checkSandboxArgs(context, runSandbox) }, } -var createPodCommand = cli.Command{ +var createSandboxCommand = cli.Command{ Name: "create", - Usage: "create a pod", - Flags: podConfigFlags, + Usage: "create a sandbox", + Flags: sandboxConfigFlags, Action: func(context *cli.Context) error { - return checkPodArgs(context, createPod) + return checkSandboxArgs(context, createSandbox) }, } -var deletePodCommand = cli.Command{ +var deleteSandboxCommand = cli.Command{ Name: "delete", - Usage: "delete an existing pod", + Usage: "delete an existing sandbox", Flags: []cli.Flag{ cli.StringFlag{ Name: "id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { - return checkPodArgs(context, deletePod) + return checkSandboxArgs(context, deleteSandbox) }, } -var startPodCommand = cli.Command{ +var startSandboxCommand = cli.Command{ Name: "start", - Usage: "start an existing pod", + Usage: "start an existing sandbox", Flags: []cli.Flag{ cli.StringFlag{ Name: "id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { - return checkPodArgs(context, startPod) + return checkSandboxArgs(context, startSandbox) }, } -var stopPodCommand = cli.Command{ +var stopSandboxCommand = cli.Command{ Name: "stop", - Usage: "stop an existing pod", + Usage: "stop an existing sandbox", Flags: []cli.Flag{ cli.StringFlag{ Name: "id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { - return checkPodArgs(context, stopPod) + return checkSandboxArgs(context, stopSandbox) }, } -var listPodsCommand = cli.Command{ +var listSandboxesCommand = cli.Command{ Name: "list", - Usage: "list all existing pods", + Usage: "list all existing sandboxes", Action: func(context *cli.Context) error { - return checkPodArgs(context, listPods) + return checkSandboxArgs(context, listSandboxes) }, } -var statusPodCommand = cli.Command{ +var statusSandboxCommand = cli.Command{ Name: "status", - Usage: "returns a detailed pod status", + Usage: "returns a detailed sandbox status", Flags: []cli.Flag{ cli.StringFlag{ Name: "id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { - return checkPodArgs(context, statusPod) + return checkSandboxArgs(context, statusSandbox) }, } -var pausePodCommand = cli.Command{ +var pauseSandboxCommand = cli.Command{ Name: "pause", - Usage: "pause an existing pod", + Usage: "pause an existing sandbox", Flags: []cli.Flag{ cli.StringFlag{ Name: "id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { - return checkPodArgs(context, pausePod) + return checkSandboxArgs(context, pauseSandbox) }, } -var resumePodCommand = cli.Command{ +var resumeSandboxCommand = cli.Command{ Name: "resume", - Usage: "unpause a paused pod", + Usage: "unpause a paused sandbox", Flags: []cli.Flag{ cli.StringFlag{ Name: "id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { - return checkPodArgs(context, resumePod) + return checkSandboxArgs(context, resumeSandbox) }, } @@ -623,7 +623,7 @@ func createContainer(context *cli.Context) error { Cmd: cmd, } - _, c, err := vc.CreateContainer(context.String("pod-id"), containerConfig) + _, c, err := vc.CreateContainer(context.String("sandbox-id"), containerConfig) if err != nil { return fmt.Errorf("Could not create container: %s", err) } @@ -634,7 +634,7 @@ func createContainer(context *cli.Context) error { } func deleteContainer(context *cli.Context) error { - c, err := vc.DeleteContainer(context.String("pod-id"), context.String("id")) + c, err := vc.DeleteContainer(context.String("sandbox-id"), context.String("id")) if err != nil { return fmt.Errorf("Could not delete container: %s", err) } @@ -645,7 +645,7 @@ func deleteContainer(context *cli.Context) error { } func startContainer(context *cli.Context) error { - c, err := vc.StartContainer(context.String("pod-id"), context.String("id")) + c, err := vc.StartContainer(context.String("sandbox-id"), context.String("id")) if err != nil { return fmt.Errorf("Could not start container: %s", err) } @@ -656,7 +656,7 @@ func startContainer(context *cli.Context) error { } func stopContainer(context *cli.Context) error { - c, err := vc.StopContainer(context.String("pod-id"), context.String("id")) + c, err := vc.StopContainer(context.String("sandbox-id"), context.String("id")) if err != nil { return fmt.Errorf("Could not stop container: %s", err) } @@ -689,7 +689,7 @@ func enterContainer(context *cli.Context) error { Console: console, } - _, c, _, err := vc.EnterContainer(context.String("pod-id"), context.String("id"), cmd) + _, c, _, err := vc.EnterContainer(context.String("sandbox-id"), context.String("id"), cmd) if err != nil { return fmt.Errorf("Could not enter container: %s", err) } @@ -700,7 +700,7 @@ func enterContainer(context *cli.Context) error { } func statusContainer(context *cli.Context) error { - contStatus, err := vc.StatusContainer(context.String("pod-id"), context.String("id")) + contStatus, err := vc.StatusContainer(context.String("sandbox-id"), context.String("id")) if err != nil { return fmt.Errorf("Could not get container status: %s", err) } @@ -724,9 +724,9 @@ var createContainerCommand = cli.Command{ Usage: "the container identifier (default: auto-generated)", }, cli.StringFlag{ - Name: "pod-id", + Name: "sandbox-id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, cli.StringFlag{ Name: "rootfs", @@ -759,9 +759,9 @@ var deleteContainerCommand = cli.Command{ Usage: "the container identifier", }, cli.StringFlag{ - Name: "pod-id", + Name: "sandbox-id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { @@ -779,9 +779,9 @@ var startContainerCommand = cli.Command{ Usage: "the container identifier", }, cli.StringFlag{ - Name: "pod-id", + Name: "sandbox-id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { @@ -799,9 +799,9 @@ var stopContainerCommand = cli.Command{ Usage: "the container identifier", }, cli.StringFlag{ - Name: "pod-id", + Name: "sandbox-id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { @@ -819,9 +819,9 @@ var enterContainerCommand = cli.Command{ Usage: "the container identifier", }, cli.StringFlag{ - Name: "pod-id", + Name: "sandbox-id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, cli.StringFlag{ Name: "cmd", @@ -849,9 +849,9 @@ var statusContainerCommand = cli.Command{ Usage: "the container identifier", }, cli.StringFlag{ - Name: "pod-id", + Name: "sandbox-id", Value: "", - Usage: "the pod identifier", + Usage: "the sandbox identifier", }, }, Action: func(context *cli.Context) error { @@ -888,18 +888,18 @@ func main() { virtc.Commands = []cli.Command{ { - Name: "pod", - Usage: "pod commands", + Name: "sandbox", + Usage: "sandbox commands", Subcommands: []cli.Command{ - createPodCommand, - deletePodCommand, - listPodsCommand, - pausePodCommand, - resumePodCommand, - runPodCommand, - startPodCommand, - stopPodCommand, - statusPodCommand, + createSandboxCommand, + deleteSandboxCommand, + listSandboxesCommand, + pauseSandboxCommand, + resumeSandboxCommand, + runSandboxCommand, + startSandboxCommand, + stopSandboxCommand, + statusSandboxCommand, }, }, { diff --git a/virtcontainers/hyperstart_agent.go b/virtcontainers/hyperstart_agent.go index 73294e3a7..a0a928dfb 100644 --- a/virtcontainers/hyperstart_agent.go +++ b/virtcontainers/hyperstart_agent.go @@ -36,7 +36,7 @@ var defaultSockPathTemplates = []string{"%s/%s/hyper.sock", "%s/%s/tty.sock"} var defaultChannelTemplate = "sh.hyper.channel.%d" var defaultDeviceIDTemplate = "channel%d" var defaultIDTemplate = "charch%d" -var defaultSharedDir = "/run/hyper/shared/pods/" +var defaultSharedDir = "/run/hyper/shared/sandboxes/" var mountTag = "hyperShared" var maxHostnameLen = 64 @@ -47,25 +47,25 @@ type HyperConfig struct { SockTtyName string } -func (h *hyper) generateSockets(pod Pod, c HyperConfig) { - podSocketPaths := []string{ - fmt.Sprintf(defaultSockPathTemplates[0], runStoragePath, pod.id), - fmt.Sprintf(defaultSockPathTemplates[1], runStoragePath, pod.id), +func (h *hyper) generateSockets(sandbox Sandbox, c HyperConfig) { + sandboxSocketPaths := []string{ + fmt.Sprintf(defaultSockPathTemplates[0], runStoragePath, sandbox.id), + fmt.Sprintf(defaultSockPathTemplates[1], runStoragePath, sandbox.id), } if c.SockCtlName != "" { - podSocketPaths[0] = c.SockCtlName + sandboxSocketPaths[0] = c.SockCtlName } if c.SockTtyName != "" { - podSocketPaths[1] = c.SockTtyName + sandboxSocketPaths[1] = c.SockTtyName } - for i := 0; i < len(podSocketPaths); i++ { + for i := 0; i < len(sandboxSocketPaths); i++ { s := Socket{ DeviceID: fmt.Sprintf(defaultDeviceIDTemplate, i), ID: fmt.Sprintf(defaultIDTemplate, i), - HostPath: podSocketPaths[i], + HostPath: sandboxSocketPaths[i], Name: fmt.Sprintf(defaultChannelTemplate, i), } h.sockets = append(h.sockets, s) @@ -81,11 +81,11 @@ type HyperAgentState struct { // hyper is the Agent interface implementation for hyperstart. type hyper struct { - pod Pod - shim shim - proxy proxy - client *proxyClient.Client - state HyperAgentState + sandbox Sandbox + shim shim + proxy proxy + client *proxyClient.Client + state HyperAgentState sockets []Socket } @@ -173,14 +173,14 @@ func (h *hyper) processHyperRoute(route netlink.Route, deviceName string) *hyper } } -func (h *hyper) buildNetworkInterfacesAndRoutes(pod Pod) ([]hyperstart.NetworkIface, []hyperstart.Route, error) { - if pod.networkNS.NetNsPath == "" { +func (h *hyper) buildNetworkInterfacesAndRoutes(sandbox Sandbox) ([]hyperstart.NetworkIface, []hyperstart.Route, error) { + if sandbox.networkNS.NetNsPath == "" { return []hyperstart.NetworkIface{}, []hyperstart.Route{}, nil } var ifaces []hyperstart.NetworkIface var routes []hyperstart.Route - for _, endpoint := range pod.networkNS.Endpoints { + for _, endpoint := range sandbox.networkNS.Endpoints { var ipAddresses []hyperstart.IPAddress for _, addr := range endpoint.Properties().Addrs { // Skip IPv6 because not supported by hyperstart. @@ -239,39 +239,39 @@ func fsMapFromMounts(mounts []Mount) []*hyperstart.FsmapDescriptor { } // init is the agent initialization implementation for hyperstart. -func (h *hyper) init(pod *Pod, config interface{}) (err error) { +func (h *hyper) init(sandbox *Sandbox, config interface{}) (err error) { switch c := config.(type) { case HyperConfig: // Create agent sockets from paths provided through // configuration, or generate them from scratch. - h.generateSockets(*pod, c) + h.generateSockets(*sandbox, c) - h.pod = *pod + h.sandbox = *sandbox default: return fmt.Errorf("Invalid config type") } - h.proxy, err = newProxy(pod.config.ProxyType) + h.proxy, err = newProxy(sandbox.config.ProxyType) if err != nil { return err } - h.shim, err = newShim(pod.config.ShimType) + h.shim, err = newShim(sandbox.config.ShimType) if err != nil { return err } // Fetch agent runtime info. - if err := pod.storage.fetchAgentState(pod.id, &h.state); err != nil { + if err := sandbox.storage.fetchAgentState(sandbox.id, &h.state); err != nil { h.Logger().Debug("Could not retrieve anything from storage") } return nil } -func (h *hyper) createPod(pod *Pod) (err error) { +func (h *hyper) createSandbox(sandbox *Sandbox) (err error) { for _, socket := range h.sockets { - err := pod.hypervisor.addDevice(socket, serialPortDev) + err := sandbox.hypervisor.addDevice(socket, serialPortDev) if err != nil { return err } @@ -281,14 +281,14 @@ func (h *hyper) createPod(pod *Pod) (err error) { // This volume contains all bind mounted container bundles. sharedVolume := Volume{ MountTag: mountTag, - HostPath: filepath.Join(defaultSharedDir, pod.id), + HostPath: filepath.Join(defaultSharedDir, sandbox.id), } if err := os.MkdirAll(sharedVolume.HostPath, dirMode); err != nil { return err } - return pod.hypervisor.addDevice(sharedVolume, fsDev) + return sandbox.hypervisor.addDevice(sharedVolume, fsDev) } func (h *hyper) capabilities() capabilities { @@ -301,7 +301,7 @@ func (h *hyper) capabilities() capabilities { } // exec is the agent command execution implementation for hyperstart. -func (h *hyper) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) { +func (h *hyper) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) { token, err := h.attach() if err != nil { return nil, err @@ -328,7 +328,7 @@ func (h *hyper) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) { }, } - process, err := prepareAndStartShim(pod, h.shim, c.id, + process, err := prepareAndStartShim(sandbox, h.shim, c.id, token, h.state.URL, cmd, []ns.NSType{}, enterNSList) if err != nil { return nil, err @@ -347,10 +347,10 @@ func (h *hyper) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) { return process, nil } -// startPod is the agent Pod starting implementation for hyperstart. -func (h *hyper) startPod(pod Pod) error { +// startSandbox is the agent Sandbox starting implementation for hyperstart. +func (h *hyper) startSandbox(sandbox Sandbox) error { // Start the proxy here - pid, uri, err := h.proxy.start(pod, proxyParams{}) + pid, uri, err := h.proxy.start(sandbox, proxyParams{}) if err != nil { return err } @@ -358,7 +358,7 @@ func (h *hyper) startPod(pod Pod) error { // Fill agent state with proxy information, and store them. h.state.ProxyPid = pid h.state.URL = uri - if err := pod.storage.storeAgentState(pod.id, h.state); err != nil { + if err := sandbox.storage.storeAgentState(sandbox.id, h.state); err != nil { return err } @@ -368,17 +368,17 @@ func (h *hyper) startPod(pod Pod) error { return err } - ifaces, routes, err := h.buildNetworkInterfacesAndRoutes(pod) + ifaces, routes, err := h.buildNetworkInterfacesAndRoutes(sandbox) if err != nil { return err } - hostname := pod.config.Hostname + hostname := sandbox.config.Hostname if len(hostname) > maxHostnameLen { hostname = hostname[:maxHostnameLen] } - hyperPod := hyperstart.Pod{ + hyperSandbox := hyperstart.Sandbox{ Hostname: hostname, Containers: []hyperstart.Container{}, Interfaces: ifaces, @@ -387,18 +387,18 @@ func (h *hyper) startPod(pod Pod) error { } proxyCmd := hyperstartProxyCmd{ - cmd: hyperstart.StartPod, - message: hyperPod, + cmd: hyperstart.StartSandbox, + message: hyperSandbox, } _, err = h.sendCmd(proxyCmd) return err } -// stopPod is the agent Pod stopping implementation for hyperstart. -func (h *hyper) stopPod(pod Pod) error { +// stopSandbox is the agent Sandbox stopping implementation for hyperstart. +func (h *hyper) stopSandbox(sandbox Sandbox) error { proxyCmd := hyperstartProxyCmd{ - cmd: hyperstart.DestroyPod, + cmd: hyperstart.DestroySandbox, message: nil, } @@ -410,7 +410,7 @@ func (h *hyper) stopPod(pod Pod) error { return err } - return h.proxy.stop(pod, h.state.ProxyPid) + return h.proxy.stop(sandbox, h.state.ProxyPid) } // handleBlockVolumes handles volumes that are block device files, by @@ -424,7 +424,7 @@ func (h *hyper) handleBlockVolumes(c *Container) { } } -func (h *hyper) startOneContainer(pod Pod, c *Container) error { +func (h *hyper) startOneContainer(sandbox Sandbox, c *Container) error { process, err := h.buildHyperContainerProcess(c.config.Cmd) if err != nil { return err @@ -452,7 +452,7 @@ func (h *hyper) startOneContainer(pod Pod, c *Container) error { if c.state.Fstype != "" { // Pass a drive name only in case of block driver - if pod.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { + if sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { driveName, err := getVirtDriveName(c.state.BlockIndex) if err != nil { return err @@ -469,8 +469,8 @@ func (h *hyper) startOneContainer(pod Pod, c *Container) error { container.Fstype = c.state.Fstype } else { - if err := bindMountContainerRootfs(defaultSharedDir, pod.id, c.id, c.rootFs, false); err != nil { - bindUnmountAllRootfs(defaultSharedDir, pod) + if err := bindMountContainerRootfs(defaultSharedDir, sandbox.id, c.id, c.rootFs, false); err != nil { + bindUnmountAllRootfs(defaultSharedDir, sandbox) return err } } @@ -480,7 +480,7 @@ func (h *hyper) startOneContainer(pod Pod, c *Container) error { // Handle container mounts newMounts, err := c.mountSharedDirMounts(defaultSharedDir, "") if err != nil { - bindUnmountAllRootfs(defaultSharedDir, pod) + bindUnmountAllRootfs(defaultSharedDir, sandbox) return err } @@ -521,7 +521,7 @@ func (h *hyper) startOneContainer(pod Pod, c *Container) error { } // createContainer is the agent Container creation implementation for hyperstart. -func (h *hyper) createContainer(pod *Pod, c *Container) (*Process, error) { +func (h *hyper) createContainer(sandbox *Sandbox, c *Container) (*Process, error) { token, err := h.attach() if err != nil { return nil, err @@ -531,31 +531,31 @@ func (h *hyper) createContainer(pod *Pod, c *Container) (*Process, error) { enterNSList := []ns.Namespace{ { - Path: pod.networkNS.NetNsPath, + Path: sandbox.networkNS.NetNsPath, Type: ns.NSTypeNet, }, } - return prepareAndStartShim(pod, h.shim, c.id, token, + return prepareAndStartShim(sandbox, h.shim, c.id, token, h.state.URL, c.config.Cmd, createNSList, enterNSList) } // startContainer is the agent Container starting implementation for hyperstart. -func (h *hyper) startContainer(pod Pod, c *Container) error { - return h.startOneContainer(pod, c) +func (h *hyper) startContainer(sandbox Sandbox, c *Container) error { + return h.startOneContainer(sandbox, c) } // stopContainer is the agent Container stopping implementation for hyperstart. -func (h *hyper) stopContainer(pod Pod, c Container) error { +func (h *hyper) stopContainer(sandbox Sandbox, c Container) error { // Nothing to be done in case the container has not been started. if c.state.State == StateReady { return nil } - return h.stopOneContainer(pod.id, c) + return h.stopOneContainer(sandbox.id, c) } -func (h *hyper) stopOneContainer(podID string, c Container) error { +func (h *hyper) stopOneContainer(sandboxID string, c Container) error { removeCommand := hyperstart.RemoveCommand{ Container: c.id, } @@ -574,7 +574,7 @@ func (h *hyper) stopOneContainer(podID string, c Container) error { } if c.state.Fstype == "" { - if err := bindUnmountContainerRootfs(defaultSharedDir, podID, c.id); err != nil { + if err := bindUnmountContainerRootfs(defaultSharedDir, sandboxID, c.id); err != nil { return err } } @@ -583,7 +583,7 @@ func (h *hyper) stopOneContainer(podID string, c Container) error { } // killContainer is the agent process signal implementation for hyperstart. -func (h *hyper) killContainer(pod Pod, c Container, signal syscall.Signal, all bool) error { +func (h *hyper) killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error { // Send the signal to the shim directly in case the container has not // been started yet. if c.state.State == StateReady { @@ -612,11 +612,11 @@ func (h *hyper) killOneContainer(cID string, signal syscall.Signal, all bool) er return nil } -func (h *hyper) processListContainer(pod Pod, c Container, options ProcessListOptions) (ProcessList, error) { - return h.processListOneContainer(pod.id, c.id, options) +func (h *hyper) processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) { + return h.processListOneContainer(sandbox.id, c.id, options) } -func (h *hyper) processListOneContainer(podID, cID string, options ProcessListOptions) (ProcessList, error) { +func (h *hyper) processListOneContainer(sandboxID, cID string, options ProcessListOptions) (ProcessList, error) { psCmd := hyperstart.PsCommand{ Container: cID, Format: options.Format, @@ -635,7 +635,7 @@ func (h *hyper) processListOneContainer(podID, cID string, options ProcessListOp msg, ok := response.([]byte) if !ok { - return nil, fmt.Errorf("failed to get response message from container %s pod %s", cID, podID) + return nil, fmt.Errorf("failed to get response message from container %s sandbox %s", cID, sandboxID) } return msg, nil @@ -742,11 +742,11 @@ func (h *hyper) register() error { defer h.disconnect() registerVMOptions := &proxyClient.RegisterVMOptions{ - Console: h.pod.hypervisor.getPodConsole(h.pod.id), + Console: h.sandbox.hypervisor.getSandboxConsole(h.sandbox.id), NumIOStreams: 0, } - _, err := h.client.RegisterVM(h.pod.id, h.sockets[0].HostPath, + _, err := h.client.RegisterVM(h.sandbox.id, h.sockets[0].HostPath, h.sockets[1].HostPath, registerVMOptions) return err } @@ -757,7 +757,7 @@ func (h *hyper) unregister() error { } defer h.disconnect() - h.client.UnregisterVM(h.pod.id) + h.client.UnregisterVM(h.sandbox.id) return nil } @@ -773,7 +773,7 @@ func (h *hyper) attach() (string, error) { NumIOStreams: numTokens, } - attachVMReturn, err := h.client.AttachVM(h.pod.id, attachVMOptions) + attachVMReturn, err := h.client.AttachVM(h.sandbox.id, attachVMOptions) if err != nil { return "", err } @@ -796,7 +796,7 @@ func (h *hyper) sendCmd(proxyCmd hyperstartProxyCmd) (interface{}, error) { NumIOStreams: 0, } - if _, err := h.client.AttachVM(h.pod.id, attachVMOptions); err != nil { + if _, err := h.client.AttachVM(h.sandbox.id, attachVMOptions); err != nil { return nil, err } diff --git a/virtcontainers/hyperstart_agent_test.go b/virtcontainers/hyperstart_agent_test.go index e94c5e501..b669d8a2d 100644 --- a/virtcontainers/hyperstart_agent_test.go +++ b/virtcontainers/hyperstart_agent_test.go @@ -37,13 +37,13 @@ func TestHyperstartGenerateSocketsSuccessful(t *testing.T) { SockTtyName: "ttySock", } - pod := Pod{ - id: testPodID, + sandbox := Sandbox{ + id: testSandboxID, } h := &hyper{} - h.generateSockets(pod, config) + h.generateSockets(sandbox, config) expectedSockets := []Socket{ { @@ -68,25 +68,25 @@ func TestHyperstartGenerateSocketsSuccessful(t *testing.T) { func TestHyperstartGenerateSocketsSuccessfulNoPathProvided(t *testing.T) { config := HyperConfig{} - pod := Pod{ - id: testPodID, + sandbox := Sandbox{ + id: testSandboxID, } h := &hyper{} - h.generateSockets(pod, config) + h.generateSockets(sandbox, config) expectedSockets := []Socket{ { DeviceID: fmt.Sprintf(defaultDeviceIDTemplate, 0), ID: fmt.Sprintf(defaultIDTemplate, 0), - HostPath: fmt.Sprintf(defaultSockPathTemplates[0], runStoragePath, pod.id), + HostPath: fmt.Sprintf(defaultSockPathTemplates[0], runStoragePath, sandbox.id), Name: fmt.Sprintf(defaultChannelTemplate, 0), }, { DeviceID: fmt.Sprintf(defaultDeviceIDTemplate, 1), ID: fmt.Sprintf(defaultIDTemplate, 1), - HostPath: fmt.Sprintf(defaultSockPathTemplates[1], runStoragePath, pod.id), + HostPath: fmt.Sprintf(defaultSockPathTemplates[1], runStoragePath, sandbox.id), Name: fmt.Sprintf(defaultChannelTemplate, 1), }, } diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index b5d0d3d8c..ef387f937 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -181,7 +181,7 @@ type HypervisorConfig struct { // customAssets is a map of assets. // Each value in that map takes precedence over the configured assets. // For example, if there is a value for the "kernel" key in this map, - // it will be used for the pod's kernel path instead of KernelPath. + // it will be used for the sandbox's kernel path instead of KernelPath. customAssets map[assetType]*asset // DefaultVCPUs specifies default number of vCPUs for the VM. @@ -191,7 +191,7 @@ type HypervisorConfig struct { DefaultMaxVCPUs uint32 // DefaultMem specifies default memory size in MiB for the VM. - // Pod configuration VMConfig.Memory overwrites this. + // Sandbox configuration VMConfig.Memory overwrites this. DefaultMemSz uint32 // DefaultBridges specifies default number of bridges for the VM. @@ -505,16 +505,16 @@ func RunningOnVMM(cpuInfoPath string) (bool, error) { // hypervisor is the virtcontainers hypervisor interface. // The default hypervisor implementation is Qemu. type hypervisor interface { - init(pod *Pod) error - createPod(podConfig PodConfig) error - startPod() error - waitPod(timeout int) error - stopPod() error - pausePod() error - resumePod() error + init(sandbox *Sandbox) error + createSandbox(sandboxConfig SandboxConfig) error + startSandbox() error + waitSandbox(timeout int) error + stopSandbox() error + pauseSandbox() error + resumeSandbox() error addDevice(devInfo interface{}, devType deviceType) error hotplugAddDevice(devInfo interface{}, devType deviceType) error hotplugRemoveDevice(devInfo interface{}, devType deviceType) error - getPodConsole(podID string) string + getSandboxConsole(sandboxID string) string capabilities() capabilities } diff --git a/virtcontainers/implementation.go b/virtcontainers/implementation.go index a43c4e849..5b6d90bcf 100644 --- a/virtcontainers/implementation.go +++ b/virtcontainers/implementation.go @@ -33,87 +33,87 @@ func (impl *VCImpl) SetLogger(logger logrus.FieldLogger) { SetLogger(logger) } -// CreatePod implements the VC function of the same name. -func (impl *VCImpl) CreatePod(podConfig PodConfig) (VCPod, error) { - return CreatePod(podConfig) +// CreateSandbox implements the VC function of the same name. +func (impl *VCImpl) CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) { + return CreateSandbox(sandboxConfig) } -// DeletePod implements the VC function of the same name. -func (impl *VCImpl) DeletePod(podID string) (VCPod, error) { - return DeletePod(podID) +// DeleteSandbox implements the VC function of the same name. +func (impl *VCImpl) DeleteSandbox(sandboxID string) (VCSandbox, error) { + return DeleteSandbox(sandboxID) } -// StartPod implements the VC function of the same name. -func (impl *VCImpl) StartPod(podID string) (VCPod, error) { - return StartPod(podID) +// StartSandbox implements the VC function of the same name. +func (impl *VCImpl) StartSandbox(sandboxID string) (VCSandbox, error) { + return StartSandbox(sandboxID) } -// StopPod implements the VC function of the same name. -func (impl *VCImpl) StopPod(podID string) (VCPod, error) { - return StopPod(podID) +// StopSandbox implements the VC function of the same name. +func (impl *VCImpl) StopSandbox(sandboxID string) (VCSandbox, error) { + return StopSandbox(sandboxID) } -// RunPod implements the VC function of the same name. -func (impl *VCImpl) RunPod(podConfig PodConfig) (VCPod, error) { - return RunPod(podConfig) +// RunSandbox implements the VC function of the same name. +func (impl *VCImpl) RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) { + return RunSandbox(sandboxConfig) } -// ListPod implements the VC function of the same name. -func (impl *VCImpl) ListPod() ([]PodStatus, error) { - return ListPod() +// ListSandbox implements the VC function of the same name. +func (impl *VCImpl) ListSandbox() ([]SandboxStatus, error) { + return ListSandbox() } -// StatusPod implements the VC function of the same name. -func (impl *VCImpl) StatusPod(podID string) (PodStatus, error) { - return StatusPod(podID) +// StatusSandbox implements the VC function of the same name. +func (impl *VCImpl) StatusSandbox(sandboxID string) (SandboxStatus, error) { + return StatusSandbox(sandboxID) } -// PausePod implements the VC function of the same name. -func (impl *VCImpl) PausePod(podID string) (VCPod, error) { - return PausePod(podID) +// PauseSandbox implements the VC function of the same name. +func (impl *VCImpl) PauseSandbox(sandboxID string) (VCSandbox, error) { + return PauseSandbox(sandboxID) } -// ResumePod implements the VC function of the same name. -func (impl *VCImpl) ResumePod(podID string) (VCPod, error) { - return ResumePod(podID) +// ResumeSandbox implements the VC function of the same name. +func (impl *VCImpl) ResumeSandbox(sandboxID string) (VCSandbox, error) { + return ResumeSandbox(sandboxID) } // CreateContainer implements the VC function of the same name. -func (impl *VCImpl) CreateContainer(podID string, containerConfig ContainerConfig) (VCPod, VCContainer, error) { - return CreateContainer(podID, containerConfig) +func (impl *VCImpl) CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) { + return CreateContainer(sandboxID, containerConfig) } // DeleteContainer implements the VC function of the same name. -func (impl *VCImpl) DeleteContainer(podID, containerID string) (VCContainer, error) { - return DeleteContainer(podID, containerID) +func (impl *VCImpl) DeleteContainer(sandboxID, containerID string) (VCContainer, error) { + return DeleteContainer(sandboxID, containerID) } // StartContainer implements the VC function of the same name. -func (impl *VCImpl) StartContainer(podID, containerID string) (VCContainer, error) { - return StartContainer(podID, containerID) +func (impl *VCImpl) StartContainer(sandboxID, containerID string) (VCContainer, error) { + return StartContainer(sandboxID, containerID) } // StopContainer implements the VC function of the same name. -func (impl *VCImpl) StopContainer(podID, containerID string) (VCContainer, error) { - return StopContainer(podID, containerID) +func (impl *VCImpl) StopContainer(sandboxID, containerID string) (VCContainer, error) { + return StopContainer(sandboxID, containerID) } // EnterContainer implements the VC function of the same name. -func (impl *VCImpl) EnterContainer(podID, containerID string, cmd Cmd) (VCPod, VCContainer, *Process, error) { - return EnterContainer(podID, containerID, cmd) +func (impl *VCImpl) EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) { + return EnterContainer(sandboxID, containerID, cmd) } // StatusContainer implements the VC function of the same name. -func (impl *VCImpl) StatusContainer(podID, containerID string) (ContainerStatus, error) { - return StatusContainer(podID, containerID) +func (impl *VCImpl) StatusContainer(sandboxID, containerID string) (ContainerStatus, error) { + return StatusContainer(sandboxID, containerID) } // KillContainer implements the VC function of the same name. -func (impl *VCImpl) KillContainer(podID, containerID string, signal syscall.Signal, all bool) error { - return KillContainer(podID, containerID, signal, all) +func (impl *VCImpl) KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error { + return KillContainer(sandboxID, containerID, signal, all) } // ProcessListContainer implements the VC function of the same name. -func (impl *VCImpl) ProcessListContainer(podID, containerID string, options ProcessListOptions) (ProcessList, error) { - return ProcessListContainer(podID, containerID, options) +func (impl *VCImpl) ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) { + return ProcessListContainer(sandboxID, containerID, options) } diff --git a/virtcontainers/interfaces.go b/virtcontainers/interfaces.go index 1476a9ac1..e32d4822e 100644 --- a/virtcontainers/interfaces.go +++ b/virtcontainers/interfaces.go @@ -24,29 +24,29 @@ import ( type VC interface { SetLogger(logger logrus.FieldLogger) - CreatePod(podConfig PodConfig) (VCPod, error) - DeletePod(podID string) (VCPod, error) - ListPod() ([]PodStatus, error) - PausePod(podID string) (VCPod, error) - ResumePod(podID string) (VCPod, error) - RunPod(podConfig PodConfig) (VCPod, error) - StartPod(podID string) (VCPod, error) - StatusPod(podID string) (PodStatus, error) - StopPod(podID string) (VCPod, error) + CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) + DeleteSandbox(sandboxID string) (VCSandbox, error) + ListSandbox() ([]SandboxStatus, error) + PauseSandbox(sandboxID string) (VCSandbox, error) + ResumeSandbox(sandboxID string) (VCSandbox, error) + RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) + StartSandbox(sandboxID string) (VCSandbox, error) + StatusSandbox(sandboxID string) (SandboxStatus, error) + StopSandbox(sandboxID string) (VCSandbox, error) - CreateContainer(podID string, containerConfig ContainerConfig) (VCPod, VCContainer, error) - DeleteContainer(podID, containerID string) (VCContainer, error) - EnterContainer(podID, containerID string, cmd Cmd) (VCPod, VCContainer, *Process, error) - KillContainer(podID, containerID string, signal syscall.Signal, all bool) error - StartContainer(podID, containerID string) (VCContainer, error) - StatusContainer(podID, containerID string) (ContainerStatus, error) - StopContainer(podID, containerID string) (VCContainer, error) - ProcessListContainer(podID, containerID string, options ProcessListOptions) (ProcessList, error) + CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) + DeleteContainer(sandboxID, containerID string) (VCContainer, error) + EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) + KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error + StartContainer(sandboxID, containerID string) (VCContainer, error) + StatusContainer(sandboxID, containerID string) (ContainerStatus, error) + StopContainer(sandboxID, containerID string) (VCContainer, error) + ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) } -// VCPod is the Pod interface -// (required since virtcontainers.Pod only contains private fields) -type VCPod interface { +// VCSandbox is the Sandbox interface +// (required since virtcontainers.Sandbox only contains private fields) +type VCSandbox interface { Annotations(key string) (string, error) GetAllContainers() []VCContainer GetAnnotations() map[string]string @@ -62,7 +62,7 @@ type VCContainer interface { GetPid() int GetToken() string ID() string - Pod() VCPod + Sandbox() VCSandbox Process() Process SetPid(pid int) error } diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 879e2e974..4a70d7ae6 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -43,7 +43,7 @@ var ( defaultKataID = "charch0" errorMissingProxy = errors.New("Missing proxy pointer") errorMissingOCISpec = errors.New("Missing OCI specification") - kataHostSharedDir = "/run/kata-containers/shared/pods/" + kataHostSharedDir = "/run/kata-containers/shared/sandboxes/" kataGuestSharedDir = "/run/kata-containers/shared/containers/" mountGuest9pTag = "kataShared" type9pFs = "9p" @@ -112,14 +112,14 @@ func parseVSOCKAddr(sock string) (uint32, uint32, error) { return uint32(cid), uint32(port), nil } -func (k *kataAgent) generateVMSocket(pod Pod, c KataAgentConfig) error { +func (k *kataAgent) generateVMSocket(sandbox Sandbox, c KataAgentConfig) error { cid, port, err := parseVSOCKAddr(c.GRPCSocket) if err != nil { // We need to generate a host UNIX socket path for the emulated serial port. k.vmSocket = Socket{ DeviceID: defaultKataDeviceID, ID: defaultKataID, - HostPath: fmt.Sprintf(defaultKataSockPathTemplate, runStoragePath, pod.id), + HostPath: fmt.Sprintf(defaultKataSockPathTemplate, runStoragePath, sandbox.id), Name: defaultKataChannel, } } else { @@ -133,28 +133,28 @@ func (k *kataAgent) generateVMSocket(pod Pod, c KataAgentConfig) error { return nil } -func (k *kataAgent) init(pod *Pod, config interface{}) (err error) { +func (k *kataAgent) init(sandbox *Sandbox, config interface{}) (err error) { switch c := config.(type) { case KataAgentConfig: - if err := k.generateVMSocket(*pod, c); err != nil { + if err := k.generateVMSocket(*sandbox, c); err != nil { return err } default: return fmt.Errorf("Invalid config type") } - k.proxy, err = newProxy(pod.config.ProxyType) + k.proxy, err = newProxy(sandbox.config.ProxyType) if err != nil { return err } - k.shim, err = newShim(pod.config.ShimType) + k.shim, err = newShim(sandbox.config.ShimType) if err != nil { return err } // Fetch agent runtime info. - if err := pod.storage.fetchAgentState(pod.id, &k.state); err != nil { + if err := sandbox.storage.fetchAgentState(sandbox.id, &k.state); err != nil { k.Logger().Debug("Could not retrieve anything from storage") } @@ -181,10 +181,10 @@ func (k *kataAgent) capabilities() capabilities { return caps } -func (k *kataAgent) createPod(pod *Pod) error { +func (k *kataAgent) createSandbox(sandbox *Sandbox) error { switch s := k.vmSocket.(type) { case Socket: - err := pod.hypervisor.addDevice(s, serialPortDev) + err := sandbox.hypervisor.addDevice(s, serialPortDev) if err != nil { return err } @@ -198,14 +198,14 @@ func (k *kataAgent) createPod(pod *Pod) error { // This volume contains all bind mounted container bundles. sharedVolume := Volume{ MountTag: mountGuest9pTag, - HostPath: filepath.Join(kataHostSharedDir, pod.id), + HostPath: filepath.Join(kataHostSharedDir, sandbox.id), } if err := os.MkdirAll(sharedVolume.HostPath, dirMode); err != nil { return err } - return pod.hypervisor.addDevice(sharedVolume, fsDev) + return sandbox.hypervisor.addDevice(sharedVolume, fsDev) } func cmdToKataProcess(cmd Cmd) (process *grpc.Process, err error) { @@ -285,7 +285,7 @@ func cmdEnvsToStringSlice(ev []EnvVar) []string { return env } -func (k *kataAgent) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) { +func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) { var kataProcess *grpc.Process kataProcess, err := cmdToKataProcess(cmd) @@ -314,7 +314,7 @@ func (k *kataAgent) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) { }, } - return prepareAndStartShim(pod, k.shim, c.id, req.ExecId, + return prepareAndStartShim(sandbox, k.shim, c.id, req.ExecId, k.state.URL, cmd, []ns.NSType{}, enterNSList) } @@ -405,7 +405,7 @@ func (k *kataAgent) generateInterfacesAndRoutes(networkNS NetworkNamespace) ([]* return ifaces, routes, nil } -func (k *kataAgent) startPod(pod Pod) error { +func (k *kataAgent) startSandbox(sandbox Sandbox) error { if k.proxy == nil { return errorMissingProxy } @@ -418,30 +418,30 @@ func (k *kataAgent) startPod(pod Pod) error { proxyParams := proxyParams{ agentURL: agentURL, - logger: k.Logger().WithField("pod-id", pod.id), + logger: k.Logger().WithField("sandbox-id", sandbox.id), } // Start the proxy here - pid, uri, err := k.proxy.start(pod, proxyParams) + pid, uri, err := k.proxy.start(sandbox, proxyParams) if err != nil { return err } // Fill agent state with proxy information, and store them. k.state.ProxyPid = pid - k.state.ProxyBuiltIn = isProxyBuiltIn(pod.config.ProxyType) + k.state.ProxyBuiltIn = isProxyBuiltIn(sandbox.config.ProxyType) k.state.URL = uri - if err := pod.storage.storeAgentState(pod.id, k.state); err != nil { + if err := sandbox.storage.storeAgentState(sandbox.id, k.state); err != nil { return err } k.Logger().WithFields(logrus.Fields{ - "pod-id": pod.id, - "proxy-pid": pid, - "proxy-url": uri, + "sandbox-id": sandbox.id, + "proxy-pid": pid, + "proxy-url": uri, }).Info("proxy started") - hostname := pod.config.Hostname + hostname := sandbox.config.Hostname if len(hostname) > maxHostnameLen { hostname = hostname[:maxHostnameLen] } @@ -449,7 +449,7 @@ func (k *kataAgent) startPod(pod Pod) error { // // Setup network interfaces and routes // - interfaces, routes, err := k.generateInterfacesAndRoutes(pod.networkNS) + interfaces, routes, err := k.generateInterfacesAndRoutes(sandbox.networkNS) if err != nil { return err } @@ -508,7 +508,7 @@ func (k *kataAgent) startPod(pod Pod) error { return err } -func (k *kataAgent) stopPod(pod Pod) error { +func (k *kataAgent) stopSandbox(sandbox Sandbox) error { if k.proxy == nil { return errorMissingProxy } @@ -519,7 +519,7 @@ func (k *kataAgent) stopPod(pod Pod) error { return err } - return k.proxy.stop(pod, k.state.ProxyPid) + return k.proxy.stop(sandbox, k.state.ProxyPid) } func (k *kataAgent) replaceOCIMountSource(spec *specs.Spec, guestMounts []Mount) error { @@ -645,13 +645,13 @@ func (k *kataAgent) rollbackFailingContainerCreation(c *Container) { k.Logger().WithError(err2).Error("rollback failed unmountHostMounts()") } - if err2 := bindUnmountContainerRootfs(kataHostSharedDir, c.pod.id, c.id); err2 != nil { + if err2 := bindUnmountContainerRootfs(kataHostSharedDir, c.sandbox.id, c.id); err2 != nil { k.Logger().WithError(err2).Error("rollback failed bindUnmountContainerRootfs()") } } } -func (k *kataAgent) createContainer(pod *Pod, c *Container) (p *Process, err error) { +func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process, err error) { ociSpecJSON, ok := c.config.Annotations[vcAnnotations.ConfigJSONKey] if !ok { return nil, errorMissingOCISpec @@ -685,7 +685,7 @@ func (k *kataAgent) createContainer(pod *Pod, c *Container) (p *Process, err err // Pass a drive name only in case of virtio-blk driver. // If virtio-scsi driver, the agent will be able to find the // device based on the provided address. - if pod.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { + if sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { // driveName is the predicted virtio-block guest name (the vd* in /dev/vd*). driveName, err := getVirtDriveName(c.state.BlockIndex) if err != nil { @@ -727,7 +727,7 @@ func (k *kataAgent) createContainer(pod *Pod, c *Container) (p *Process, err err // (kataGuestSharedDir) is already mounted in the // guest. We only need to mount the rootfs from // the host and it will show up in the guest. - if err = bindMountContainerRootfs(kataHostSharedDir, pod.id, c.id, c.rootFs, false); err != nil { + if err = bindMountContainerRootfs(kataHostSharedDir, sandbox.id, c.id, c.rootFs, false); err != nil { return nil, err } } @@ -791,12 +791,12 @@ func (k *kataAgent) createContainer(pod *Pod, c *Container) (p *Process, err err enterNSList := []ns.Namespace{ { - Path: pod.networkNS.NetNsPath, + Path: sandbox.networkNS.NetNsPath, Type: ns.NSTypeNet, }, } - return prepareAndStartShim(pod, k.shim, c.id, req.ExecId, + return prepareAndStartShim(sandbox, k.shim, c.id, req.ExecId, k.state.URL, c.config.Cmd, createNSList, enterNSList) } @@ -819,7 +819,7 @@ func (k *kataAgent) handleBlockVolumes(c *Container) []*grpc.Storage { vol := &grpc.Storage{} - if c.pod.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { + if c.sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { vol.Driver = kataBlkDevType vol.Source = b.VirtPath } else { @@ -837,7 +837,7 @@ func (k *kataAgent) handleBlockVolumes(c *Container) []*grpc.Storage { return volumeStorages } -func (k *kataAgent) startContainer(pod Pod, c *Container) error { +func (k *kataAgent) startContainer(sandbox Sandbox, c *Container) error { req := &grpc.StartContainerRequest{ ContainerId: c.id, } @@ -846,7 +846,7 @@ func (k *kataAgent) startContainer(pod Pod, c *Container) error { return err } -func (k *kataAgent) stopContainer(pod Pod, c Container) error { +func (k *kataAgent) stopContainer(sandbox Sandbox, c Container) error { req := &grpc.RemoveContainerRequest{ ContainerId: c.id, } @@ -859,10 +859,10 @@ func (k *kataAgent) stopContainer(pod Pod, c Container) error { return err } - return bindUnmountContainerRootfs(kataHostSharedDir, pod.id, c.id) + return bindUnmountContainerRootfs(kataHostSharedDir, sandbox.id, c.id) } -func (k *kataAgent) killContainer(pod Pod, c Container, signal syscall.Signal, all bool) error { +func (k *kataAgent) killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error { req := &grpc.SignalProcessRequest{ ContainerId: c.id, ExecId: c.process.Token, @@ -873,7 +873,7 @@ func (k *kataAgent) killContainer(pod Pod, c Container, signal syscall.Signal, a return err } -func (k *kataAgent) processListContainer(pod Pod, c Container, options ProcessListOptions) (ProcessList, error) { +func (k *kataAgent) processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) { return nil, nil } diff --git a/virtcontainers/kata_builtin_proxy.go b/virtcontainers/kata_builtin_proxy.go index 3aeb47283..d84f7cc3a 100644 --- a/virtcontainers/kata_builtin_proxy.go +++ b/virtcontainers/kata_builtin_proxy.go @@ -28,20 +28,20 @@ import ( // This is a kata builtin proxy implementation of the proxy interface. Kata proxy // functionality is implemented inside the virtcontainers library. type kataBuiltInProxy struct { - podID string - conn net.Conn + sandboxID string + conn net.Conn } // start is the proxy start implementation for kata builtin proxy. // It starts the console watcher for the guest. // It returns agentURL to let agent connect directly. -func (p *kataBuiltInProxy) start(pod Pod, params proxyParams) (int, string, error) { +func (p *kataBuiltInProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { if p.conn != nil { - return -1, "", fmt.Errorf("kata builtin proxy running for pod %s", p.podID) + return -1, "", fmt.Errorf("kata builtin proxy running for sandbox %s", p.sandboxID) } - p.podID = pod.id - console := pod.hypervisor.getPodConsole(pod.id) + p.sandboxID = sandbox.id + console := sandbox.hypervisor.getSandboxConsole(sandbox.id) err := p.watchConsole(consoleProtoUnix, console, params.logger) if err != nil { return -1, "", err @@ -51,11 +51,11 @@ func (p *kataBuiltInProxy) start(pod Pod, params proxyParams) (int, string, erro } // stop is the proxy stop implementation for kata builtin proxy. -func (p *kataBuiltInProxy) stop(pod Pod, pid int) error { +func (p *kataBuiltInProxy) stop(sandbox Sandbox, pid int) error { if p.conn != nil { p.conn.Close() p.conn = nil - p.podID = "" + p.sandboxID = "" } return nil } @@ -84,7 +84,7 @@ func (p *kataBuiltInProxy) watchConsole(proto, console string, logger *logrus.En go func() { scanner = bufio.NewScanner(conn) for scanner.Scan() { - fmt.Printf("[POD-%s] vmconsole: %s\n", p.podID, scanner.Text()) + fmt.Printf("[SB-%s] vmconsole: %s\n", p.sandboxID, scanner.Text()) } if err := scanner.Err(); err != nil { diff --git a/virtcontainers/kata_builtin_shim.go b/virtcontainers/kata_builtin_shim.go index fa67e3d25..0c41d633a 100644 --- a/virtcontainers/kata_builtin_shim.go +++ b/virtcontainers/kata_builtin_shim.go @@ -21,6 +21,6 @@ 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(pod Pod, params ShimParams) (int, error) { +func (s *kataBuiltInShim) start(sandbox Sandbox, params ShimParams) (int, error) { return -1, nil } diff --git a/virtcontainers/kata_proxy.go b/virtcontainers/kata_proxy.go index 0be1f562a..fbdd92fff 100644 --- a/virtcontainers/kata_proxy.go +++ b/virtcontainers/kata_proxy.go @@ -29,8 +29,8 @@ type kataProxy struct { } // start is kataProxy start implementation for proxy interface. -func (p *kataProxy) start(pod Pod, params proxyParams) (int, string, error) { - if pod.agent == nil { +func (p *kataProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { + if sandbox.agent == nil { return -1, "", fmt.Errorf("No agent") } @@ -38,13 +38,13 @@ func (p *kataProxy) start(pod Pod, params proxyParams) (int, string, error) { return -1, "", fmt.Errorf("AgentURL cannot be empty") } - config, err := newProxyConfig(pod.config) + config, err := newProxyConfig(sandbox.config) if err != nil { return -1, "", err } // construct the socket path the proxy instance will use - proxyURL, err := defaultProxyURL(pod, SocketTypeUNIX) + proxyURL, err := defaultProxyURL(sandbox, SocketTypeUNIX) if err != nil { return -1, "", err } @@ -52,7 +52,7 @@ func (p *kataProxy) start(pod Pod, params proxyParams) (int, string, error) { args := []string{config.Path, "-listen-socket", proxyURL, "-mux-socket", params.agentURL} if config.Debug { args = append(args, "-log", "debug") - args = append(args, "-agent-logs-socket", pod.hypervisor.getPodConsole(pod.id)) + args = append(args, "-agent-logs-socket", sandbox.hypervisor.getSandboxConsole(sandbox.id)) } cmd := exec.Command(args[0], args[1:]...) @@ -64,7 +64,7 @@ func (p *kataProxy) start(pod Pod, params proxyParams) (int, string, error) { } // stop is kataProxy stop implementation for proxy interface. -func (p *kataProxy) stop(pod Pod, pid int) error { +func (p *kataProxy) stop(sandbox Sandbox, pid int) error { // Signal the proxy with SIGTERM. return syscall.Kill(pid, syscall.SIGTERM) } diff --git a/virtcontainers/kata_shim.go b/virtcontainers/kata_shim.go index e7b47abc2..9f1693e12 100644 --- a/virtcontainers/kata_shim.go +++ b/virtcontainers/kata_shim.go @@ -32,12 +32,12 @@ type KataShimConfig struct { // start is the ccShim start implementation. // It starts the cc-shim binary with URL and token flags provided by // the proxy. -func (s *kataShim) start(pod Pod, params ShimParams) (int, error) { - if pod.config == nil { - return -1, fmt.Errorf("Pod config cannot be nil") +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(*(pod.config)).(ShimConfig) + config, ok := newShimConfig(*(sandbox.config)).(ShimConfig) if !ok { return -1, fmt.Errorf("Wrong shim config type, should be KataShimConfig type") } diff --git a/virtcontainers/kata_shim_test.go b/virtcontainers/kata_shim_test.go index 777c2b72a..4d43780b0 100644 --- a/virtcontainers/kata_shim_test.go +++ b/virtcontainers/kata_shim_test.go @@ -40,65 +40,65 @@ func getMockKataShimBinPath() string { return DefaultMockKataShimBinPath } -func testKataShimStart(t *testing.T, pod Pod, params ShimParams, expectFail bool) { +func testKataShimStart(t *testing.T, sandbox Sandbox, params ShimParams, expectFail bool) { s := &kataShim{} - pid, err := s.start(pod, params) + pid, err := s.start(sandbox, params) if expectFail { if err == nil || pid != -1 { - t.Fatalf("This test should fail (pod %+v, params %+v, expectFail %t)", - pod, params, expectFail) + t.Fatalf("This test should fail (sandbox %+v, params %+v, expectFail %t)", + sandbox, params, expectFail) } } else { if err != nil { - t.Fatalf("This test should pass (pod %+v, params %+v, expectFail %t): %s", - pod, params, expectFail, err) + t.Fatalf("This test should pass (sandbox %+v, params %+v, expectFail %t): %s", + sandbox, params, expectFail, err) } if pid == -1 { - t.Fatalf("This test should pass (pod %+v, params %+v, expectFail %t)", - pod, params, expectFail) + t.Fatalf("This test should pass (sandbox %+v, params %+v, expectFail %t)", + sandbox, params, expectFail) } } } -func TestKataShimStartNilPodConfigFailure(t *testing.T) { - testKataShimStart(t, Pod{}, ShimParams{}, true) +func TestKataShimStartNilSandboxConfigFailure(t *testing.T) { + testKataShimStart(t, Sandbox{}, ShimParams{}, true) } func TestKataShimStartNilShimConfigFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{}, + sandbox := Sandbox{ + config: &SandboxConfig{}, } - testKataShimStart(t, pod, ShimParams{}, true) + testKataShimStart(t, sandbox, ShimParams{}, true) } func TestKataShimStartShimPathEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{}, }, } - testKataShimStart(t, pod, ShimParams{}, true) + testKataShimStart(t, sandbox, ShimParams{}, true) } func TestKataShimStartShimTypeInvalid(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: "foo", ShimConfig: ShimConfig{}, }, } - testKataShimStart(t, pod, ShimParams{}, true) + testKataShimStart(t, sandbox, ShimParams{}, true) } func TestKataShimStartParamsTokenEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{ Path: getMockKataShimBinPath(), @@ -106,12 +106,12 @@ func TestKataShimStartParamsTokenEmptyFailure(t *testing.T) { }, } - testKataShimStart(t, pod, ShimParams{}, true) + testKataShimStart(t, sandbox, ShimParams{}, true) } func TestKataShimStartParamsURLEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{ Path: getMockKataShimBinPath(), @@ -123,12 +123,12 @@ func TestKataShimStartParamsURLEmptyFailure(t *testing.T) { Token: "testToken", } - testKataShimStart(t, pod, params, true) + testKataShimStart(t, sandbox, params, true) } func TestKataShimStartParamsContainerEmptyFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{ Path: getMockKataShimBinPath(), @@ -141,7 +141,7 @@ func TestKataShimStartParamsContainerEmptyFailure(t *testing.T) { URL: "unix://is/awesome", } - testKataShimStart(t, pod, params, true) + testKataShimStart(t, sandbox, params, true) } func TestKataShimStartParamsInvalidCommand(t *testing.T) { @@ -153,8 +153,8 @@ func TestKataShimStartParamsInvalidCommand(t *testing.T) { cmd := filepath.Join(dir, "does-not-exist") - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{ Path: cmd, @@ -167,20 +167,20 @@ func TestKataShimStartParamsInvalidCommand(t *testing.T) { URL: "http://foo", } - testKataShimStart(t, pod, params, true) + testKataShimStart(t, sandbox, params, true) } -func startKataShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, Pod, ShimParams, error) { +func startKataShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, Sandbox, ShimParams, error) { saveStdout := os.Stdout rStdout, wStdout, err := os.Pipe() if err != nil { - return nil, nil, nil, Pod{}, ShimParams{}, err + return nil, nil, nil, Sandbox{}, ShimParams{}, err } os.Stdout = wStdout - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{ Path: getMockKataShimBinPath(), @@ -195,11 +195,11 @@ func startKataShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os. Detach: detach, } - return rStdout, wStdout, saveStdout, pod, params, nil + return rStdout, wStdout, saveStdout, sandbox, params, nil } func TestKataShimStartSuccessful(t *testing.T) { - rStdout, wStdout, saveStdout, pod, params, err := startKataShimStartWithoutConsoleSuccessful(t, false) + rStdout, wStdout, saveStdout, sandbox, params, err := startKataShimStartWithoutConsoleSuccessful(t, false) if err != nil { t.Fatal(err) } @@ -210,7 +210,7 @@ func TestKataShimStartSuccessful(t *testing.T) { wStdout.Close() }() - testKataShimStart(t, pod, params, false) + testKataShimStart(t, sandbox, params, false) bufStdout := make([]byte, 1024) if _, err := rStdout.Read(bufStdout); err != nil { @@ -223,7 +223,7 @@ func TestKataShimStartSuccessful(t *testing.T) { } func TestKataShimStartDetachSuccessful(t *testing.T) { - rStdout, wStdout, saveStdout, pod, params, err := startKataShimStartWithoutConsoleSuccessful(t, true) + rStdout, wStdout, saveStdout, sandbox, params, err := startKataShimStartWithoutConsoleSuccessful(t, true) if err != nil { t.Fatal(err) } @@ -234,7 +234,7 @@ func TestKataShimStartDetachSuccessful(t *testing.T) { rStdout.Close() }() - testKataShimStart(t, pod, params, false) + testKataShimStart(t, sandbox, params, false) readCh := make(chan error) go func() { @@ -264,8 +264,8 @@ func TestKataShimStartDetachSuccessful(t *testing.T) { } func TestKataShimStartWithConsoleNonExistingFailure(t *testing.T) { - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{ Path: getMockKataShimBinPath(), @@ -279,7 +279,7 @@ func TestKataShimStartWithConsoleNonExistingFailure(t *testing.T) { Console: testWrongConsolePath, } - testKataShimStart(t, pod, params, true) + testKataShimStart(t, sandbox, params, true) } func TestKataShimStartWithConsoleSuccessful(t *testing.T) { @@ -292,8 +292,8 @@ func TestKataShimStartWithConsoleSuccessful(t *testing.T) { t.Fatal(err) } - pod := Pod{ - config: &PodConfig{ + sandbox := Sandbox{ + config: &SandboxConfig{ ShimType: KataShimType, ShimConfig: ShimConfig{ Path: getMockKataShimBinPath(), @@ -308,6 +308,6 @@ func TestKataShimStartWithConsoleSuccessful(t *testing.T) { Console: console, } - testKataShimStart(t, pod, params, false) + testKataShimStart(t, sandbox, params, false) master.Close() } diff --git a/virtcontainers/mock_hypervisor.go b/virtcontainers/mock_hypervisor.go index 41ee85c27..667d66710 100644 --- a/virtcontainers/mock_hypervisor.go +++ b/virtcontainers/mock_hypervisor.go @@ -19,8 +19,8 @@ package virtcontainers type mockHypervisor struct { } -func (m *mockHypervisor) init(pod *Pod) error { - valid, err := pod.config.HypervisorConfig.valid() +func (m *mockHypervisor) init(sandbox *Sandbox) error { + valid, err := sandbox.config.HypervisorConfig.valid() if valid == false || err != nil { return err } @@ -32,27 +32,27 @@ func (m *mockHypervisor) capabilities() capabilities { return capabilities{} } -func (m *mockHypervisor) createPod(podConfig PodConfig) error { +func (m *mockHypervisor) createSandbox(sandboxConfig SandboxConfig) error { return nil } -func (m *mockHypervisor) startPod() error { +func (m *mockHypervisor) startSandbox() error { return nil } -func (m *mockHypervisor) waitPod(timeout int) error { +func (m *mockHypervisor) waitSandbox(timeout int) error { return nil } -func (m *mockHypervisor) stopPod() error { +func (m *mockHypervisor) stopSandbox() error { return nil } -func (m *mockHypervisor) pausePod() error { +func (m *mockHypervisor) pauseSandbox() error { return nil } -func (m *mockHypervisor) resumePod() error { +func (m *mockHypervisor) resumeSandbox() error { return nil } @@ -68,6 +68,6 @@ func (m *mockHypervisor) hotplugRemoveDevice(devInfo interface{}, devType device return nil } -func (m *mockHypervisor) getPodConsole(podID string) string { +func (m *mockHypervisor) getSandboxConsole(sandboxID string) string { return "" } diff --git a/virtcontainers/mock_hypervisor_test.go b/virtcontainers/mock_hypervisor_test.go index da52cf515..48d6b28e4 100644 --- a/virtcontainers/mock_hypervisor_test.go +++ b/virtcontainers/mock_hypervisor_test.go @@ -24,8 +24,8 @@ import ( func TestMockHypervisorInit(t *testing.T) { var m *mockHypervisor - pod := &Pod{ - config: &PodConfig{ + sandbox := &Sandbox{ + config: &SandboxConfig{ HypervisorConfig: HypervisorConfig{ KernelPath: "", ImagePath: "", @@ -35,52 +35,52 @@ func TestMockHypervisorInit(t *testing.T) { } // wrong config - if err := m.init(pod); err == nil { + if err := m.init(sandbox); err == nil { t.Fatal() } - pod.config.HypervisorConfig = HypervisorConfig{ + sandbox.config.HypervisorConfig = HypervisorConfig{ KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel), ImagePath: fmt.Sprintf("%s/%s", testDir, testImage), HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor), } // right config - if err := m.init(pod); err != nil { + if err := m.init(sandbox); err != nil { t.Fatal(err) } } -func TestMockHypervisorCreatePod(t *testing.T) { +func TestMockHypervisorCreateSandbox(t *testing.T) { var m *mockHypervisor - config := PodConfig{} + config := SandboxConfig{} - if err := m.createPod(config); err != nil { + if err := m.createSandbox(config); err != nil { t.Fatal(err) } } -func TestMockHypervisorStartPod(t *testing.T) { +func TestMockHypervisorStartSandbox(t *testing.T) { var m *mockHypervisor - if err := m.startPod(); err != nil { + if err := m.startSandbox(); err != nil { t.Fatal(err) } } -func TestMockHypervisorWaitPod(t *testing.T) { +func TestMockHypervisorWaitSandbox(t *testing.T) { var m *mockHypervisor - if err := m.waitPod(0); err != nil { + if err := m.waitSandbox(0); err != nil { t.Fatal(err) } } -func TestMockHypervisorStopPod(t *testing.T) { +func TestMockHypervisorStopSandbox(t *testing.T) { var m *mockHypervisor - if err := m.stopPod(); err != nil { + if err := m.stopSandbox(); err != nil { t.Fatal(err) } } @@ -93,12 +93,12 @@ func TestMockHypervisorAddDevice(t *testing.T) { } } -func TestMockHypervisorGetPodConsole(t *testing.T) { +func TestMockHypervisorGetSandboxConsole(t *testing.T) { var m *mockHypervisor expected := "" - if result := m.getPodConsole("testPodID"); result != expected { + if result := m.getSandboxConsole("testSandboxID"); result != expected { t.Fatalf("Got %s\nExpecting %s", result, expected) } } diff --git a/virtcontainers/mount.go b/virtcontainers/mount.go index 9f5b078eb..e348d1b04 100644 --- a/virtcontainers/mount.go +++ b/virtcontainers/mount.go @@ -259,8 +259,8 @@ func bindMount(source, destination string, readonly bool) error { // bindMountContainerRootfs bind mounts a container rootfs into a 9pfs shared // directory between the guest and the host. -func bindMountContainerRootfs(sharedDir, podID, cID, cRootFs string, readonly bool) error { - rootfsDest := filepath.Join(sharedDir, podID, cID, rootfsDir) +func bindMountContainerRootfs(sharedDir, sandboxID, cID, cRootFs string, readonly bool) error { + rootfsDest := filepath.Join(sharedDir, sandboxID, cID, rootfsDir) return bindMount(cRootFs, rootfsDest, readonly) } @@ -288,20 +288,20 @@ type Mount struct { BlockDevice *BlockDevice } -func bindUnmountContainerRootfs(sharedDir, podID, cID string) error { - rootfsDest := filepath.Join(sharedDir, podID, cID, rootfsDir) +func bindUnmountContainerRootfs(sharedDir, sandboxID, cID string) error { + rootfsDest := filepath.Join(sharedDir, sandboxID, cID, rootfsDir) syscall.Unmount(rootfsDest, 0) return nil } -func bindUnmountAllRootfs(sharedDir string, pod Pod) { - for _, c := range pod.containers { +func bindUnmountAllRootfs(sharedDir string, sandbox Sandbox) { + for _, c := range sandbox.containers { c.unmountHostMounts() if c.state.Fstype == "" { // Need to check for error returned by this call. // See: https://github.com/containers/virtcontainers/issues/295 - bindUnmountContainerRootfs(sharedDir, pod.id, c.id) + bindUnmountContainerRootfs(sharedDir, sandbox.id, c.id) } } } diff --git a/virtcontainers/network.go b/virtcontainers/network.go index 45d687bb5..281f47de2 100644 --- a/virtcontainers/network.go +++ b/virtcontainers/network.go @@ -600,10 +600,10 @@ func runNetworkCommon(networkNSPath string, cb func() error) error { }) } -func addNetworkCommon(pod Pod, networkNS *NetworkNamespace) error { +func addNetworkCommon(sandbox Sandbox, networkNS *NetworkNamespace) error { err := doNetNS(networkNS.NetNsPath, func(_ ns.NetNS) error { for _, endpoint := range networkNS.Endpoints { - if err := endpoint.Attach(pod.hypervisor); err != nil { + if err := endpoint.Attach(sandbox.hypervisor); err != nil { return err } } @@ -1376,9 +1376,9 @@ type network interface { run(networkNSPath string, cb func() error) error // add adds all needed interfaces inside the network namespace. - add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) + add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) // remove unbridges and deletes TAP interfaces. It also removes virtual network // interfaces and deletes the network namespace. - remove(pod Pod, networkNS NetworkNamespace) error + remove(sandbox Sandbox, networkNS NetworkNamespace) error } diff --git a/virtcontainers/no_proxy.go b/virtcontainers/no_proxy.go index 3d95565ff..2f4fff284 100644 --- a/virtcontainers/no_proxy.go +++ b/virtcontainers/no_proxy.go @@ -34,7 +34,7 @@ type noProxy struct { } // start is noProxy start implementation for proxy interface. -func (p *noProxy) start(pod Pod, params proxyParams) (int, string, error) { +func (p *noProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { if params.agentURL == "" { return -1, "", fmt.Errorf("AgentURL cannot be empty") } @@ -43,6 +43,6 @@ func (p *noProxy) start(pod Pod, params proxyParams) (int, string, error) { } // stop is noProxy stop implementation for proxy interface. -func (p *noProxy) stop(pod Pod, pid int) error { +func (p *noProxy) stop(sandbox Sandbox, pid int) error { return nil } diff --git a/virtcontainers/no_proxy_test.go b/virtcontainers/no_proxy_test.go index d0df409a0..455c4f663 100644 --- a/virtcontainers/no_proxy_test.go +++ b/virtcontainers/no_proxy_test.go @@ -21,14 +21,14 @@ import ( ) func TestNoProxyStart(t *testing.T) { - pod := Pod{ + sandbox := Sandbox{ agent: newAgent(NoopAgentType), } p := &noProxy{} agentURL := "agentURL" - pid, vmURL, err := p.start(pod, proxyParams{agentURL: agentURL}) + pid, vmURL, err := p.start(sandbox, proxyParams{agentURL: agentURL}) if err != nil { t.Fatal(err) } @@ -45,7 +45,7 @@ func TestNoProxyStart(t *testing.T) { func TestNoProxyStop(t *testing.T) { p := &noProxy{} - if err := p.stop(Pod{}, 0); err != nil { + if err := p.stop(Sandbox{}, 0); err != nil { t.Fatal(err) } } diff --git a/virtcontainers/noop_agent.go b/virtcontainers/noop_agent.go index 13d7a2e78..20f923dc3 100644 --- a/virtcontainers/noop_agent.go +++ b/virtcontainers/noop_agent.go @@ -26,12 +26,12 @@ type noopAgent struct { } // init initializes the Noop agent, i.e. it does nothing. -func (n *noopAgent) init(pod *Pod, config interface{}) error { +func (n *noopAgent) init(sandbox *Sandbox, config interface{}) error { return nil } -// createPod is the Noop agent pod creation implementation. It does nothing. -func (n *noopAgent) createPod(pod *Pod) error { +// createSandbox is the Noop agent sandbox creation implementation. It does nothing. +func (n *noopAgent) createSandbox(sandbox *Sandbox) error { return nil } @@ -41,42 +41,42 @@ func (n *noopAgent) capabilities() capabilities { } // exec is the Noop agent command execution implementation. It does nothing. -func (n *noopAgent) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) { +func (n *noopAgent) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) { return nil, nil } -// startPod is the Noop agent Pod starting implementation. It does nothing. -func (n *noopAgent) startPod(pod Pod) error { +// startSandbox is the Noop agent Sandbox starting implementation. It does nothing. +func (n *noopAgent) startSandbox(sandbox Sandbox) error { return nil } -// stopPod is the Noop agent Pod stopping implementation. It does nothing. -func (n *noopAgent) stopPod(pod Pod) error { +// stopSandbox is the Noop agent Sandbox stopping implementation. It does nothing. +func (n *noopAgent) stopSandbox(sandbox Sandbox) error { return nil } // createContainer is the Noop agent Container creation implementation. It does nothing. -func (n *noopAgent) createContainer(pod *Pod, c *Container) (*Process, error) { +func (n *noopAgent) createContainer(sandbox *Sandbox, c *Container) (*Process, error) { return &Process{}, nil } // startContainer is the Noop agent Container starting implementation. It does nothing. -func (n *noopAgent) startContainer(pod Pod, c *Container) error { +func (n *noopAgent) startContainer(sandbox Sandbox, c *Container) error { return nil } // stopContainer is the Noop agent Container stopping implementation. It does nothing. -func (n *noopAgent) stopContainer(pod Pod, c Container) error { +func (n *noopAgent) stopContainer(sandbox Sandbox, c Container) error { return nil } // killContainer is the Noop agent Container signaling implementation. It does nothing. -func (n *noopAgent) killContainer(pod Pod, c Container, signal syscall.Signal, all bool) error { +func (n *noopAgent) killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error { return nil } // processListContainer is the Noop agent Container ps implementation. It does nothing. -func (n *noopAgent) processListContainer(pod Pod, c Container, options ProcessListOptions) (ProcessList, error) { +func (n *noopAgent) processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) { return nil, nil } diff --git a/virtcontainers/noop_agent_test.go b/virtcontainers/noop_agent_test.go index e495ac55f..f0a5603f3 100644 --- a/virtcontainers/noop_agent_test.go +++ b/virtcontainers/noop_agent_test.go @@ -20,11 +20,11 @@ import ( "testing" ) -func testCreateNoopContainer() (*Pod, *Container, error) { +func testCreateNoopContainer() (*Sandbox, *Container, error) { contID := "100" - config := newTestPodConfigNoop() + config := newTestSandboxConfigNoop() - p, err := CreatePod(config) + p, err := CreateSandbox(config) if err != nil { return nil, nil, err } @@ -36,14 +36,14 @@ func testCreateNoopContainer() (*Pod, *Container, error) { return nil, nil, err } - return p.(*Pod), c.(*Container), nil + return p.(*Sandbox), c.(*Container), nil } func TestNoopAgentInit(t *testing.T) { n := &noopAgent{} - pod := &Pod{} + sandbox := &Sandbox{} - err := n.init(pod, nil) + err := n.init(sandbox, nil) if err != nil { t.Fatal(err) } @@ -52,32 +52,32 @@ func TestNoopAgentInit(t *testing.T) { func TestNoopAgentExec(t *testing.T) { n := &noopAgent{} cmd := Cmd{} - pod, container, err := testCreateNoopContainer() + sandbox, container, err := testCreateNoopContainer() if err != nil { t.Fatal(err) } defer cleanUp() - if _, err = n.exec(pod, *container, cmd); err != nil { + if _, err = n.exec(sandbox, *container, cmd); err != nil { t.Fatal(err) } } -func TestNoopAgentStartPod(t *testing.T) { +func TestNoopAgentStartSandbox(t *testing.T) { n := &noopAgent{} - pod := Pod{} + sandbox := Sandbox{} - err := n.startPod(pod) + err := n.startSandbox(sandbox) if err != nil { t.Fatal(err) } } -func TestNoopAgentStopPod(t *testing.T) { +func TestNoopAgentStopSandbox(t *testing.T) { n := &noopAgent{} - pod := Pod{} + sandbox := Sandbox{} - err := n.stopPod(pod) + err := n.stopSandbox(sandbox) if err != nil { t.Fatal(err) } @@ -85,30 +85,30 @@ func TestNoopAgentStopPod(t *testing.T) { func TestNoopAgentCreateContainer(t *testing.T) { n := &noopAgent{} - pod, container, err := testCreateNoopContainer() + sandbox, container, err := testCreateNoopContainer() if err != nil { t.Fatal(err) } defer cleanUp() - if err := n.startPod(*pod); err != nil { + if err := n.startSandbox(*sandbox); err != nil { t.Fatal(err) } - if _, err := n.createContainer(pod, container); err != nil { + if _, err := n.createContainer(sandbox, container); err != nil { t.Fatal(err) } } func TestNoopAgentStartContainer(t *testing.T) { n := &noopAgent{} - pod, container, err := testCreateNoopContainer() + sandbox, container, err := testCreateNoopContainer() if err != nil { t.Fatal(err) } defer cleanUp() - err = n.startContainer(*pod, container) + err = n.startContainer(*sandbox, container) if err != nil { t.Fatal(err) } @@ -116,13 +116,13 @@ func TestNoopAgentStartContainer(t *testing.T) { func TestNoopAgentStopContainer(t *testing.T) { n := &noopAgent{} - pod, container, err := testCreateNoopContainer() + sandbox, container, err := testCreateNoopContainer() if err != nil { t.Fatal(err) } defer cleanUp() - err = n.stopContainer(*pod, *container) + err = n.stopContainer(*sandbox, *container) if err != nil { t.Fatal(err) } diff --git a/virtcontainers/noop_network.go b/virtcontainers/noop_network.go index dd193cb7a..7caff5d4f 100644 --- a/virtcontainers/noop_network.go +++ b/virtcontainers/noop_network.go @@ -36,13 +36,13 @@ func (n *noopNetwork) run(networkNSPath string, cb func() error) error { // add adds all needed interfaces inside the network namespace the Noop network. // It does nothing. -func (n *noopNetwork) add(pod Pod, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { +func (n *noopNetwork) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { return NetworkNamespace{}, nil } // remove unbridges and deletes TAP interfaces. It also removes virtual network // interfaces and deletes the network namespace for the Noop network. // It does nothing. -func (n *noopNetwork) remove(pod Pod, networkNS NetworkNamespace) error { +func (n *noopNetwork) remove(sandbox Sandbox, networkNS NetworkNamespace) error { return nil } diff --git a/virtcontainers/noop_proxy.go b/virtcontainers/noop_proxy.go index d8310956b..f1bb83b19 100644 --- a/virtcontainers/noop_proxy.go +++ b/virtcontainers/noop_proxy.go @@ -24,12 +24,12 @@ var noopProxyURL = "noopProxyURL" // register is the proxy start implementation for testing purpose. // It does nothing. -func (p *noopProxy) start(pod Pod, params proxyParams) (int, string, error) { +func (p *noopProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { return 0, noopProxyURL, nil } // stop is the proxy stop implementation for testing purpose. // It does nothing. -func (p *noopProxy) stop(pod Pod, pid int) error { +func (p *noopProxy) stop(sandbox Sandbox, pid int) error { return nil } diff --git a/virtcontainers/noop_shim.go b/virtcontainers/noop_shim.go index ae99b363b..ca1426b55 100644 --- a/virtcontainers/noop_shim.go +++ b/virtcontainers/noop_shim.go @@ -20,6 +20,6 @@ type noopShim struct{} // start is the noopShim start implementation for testing purpose. // It does nothing. -func (s *noopShim) start(pod Pod, params ShimParams) (int, error) { +func (s *noopShim) start(sandbox Sandbox, params ShimParams) (int, error) { return 1000, nil } diff --git a/virtcontainers/noop_shim_test.go b/virtcontainers/noop_shim_test.go index 9d527fcdd..fcff148df 100644 --- a/virtcontainers/noop_shim_test.go +++ b/virtcontainers/noop_shim_test.go @@ -22,11 +22,11 @@ import ( func TestNoopShimStart(t *testing.T) { s := &noopShim{} - pod := Pod{} + sandbox := Sandbox{} params := ShimParams{} expected := 1000 - pid, err := s.start(pod, params) + pid, err := s.start(sandbox, params) if err != nil { t.Fatal(err) } diff --git a/virtcontainers/pkg/annotations/annotations.go b/virtcontainers/pkg/annotations/annotations.go index 27baea8dd..7a99b83ba 100644 --- a/virtcontainers/pkg/annotations/annotations.go +++ b/virtcontainers/pkg/annotations/annotations.go @@ -19,34 +19,34 @@ package annotations const ( vcAnnotationsPrefix = "com.github.containers.virtcontainers." - // KernelPath is a pod annotation for passing a per container path pointing at the kernel needed to boot the container VM. + // KernelPath is a sandbox annotation for passing a per container path pointing at the kernel needed to boot the container VM. KernelPath = vcAnnotationsPrefix + "KernelPath" - // ImagePath is a pod annotation for passing a per container path pointing at the guest image that will run in the container VM. + // ImagePath is a sandbox annotation for passing a per container path pointing at the guest image that will run in the container VM. ImagePath = vcAnnotationsPrefix + "ImagePath" - // InitrdPath is a pod annotation for passing a per container path pointing at the guest initrd image that will run in the container VM. + // InitrdPath is a sandbox annotation for passing a per container path pointing at the guest initrd image that will run in the container VM. InitrdPath = vcAnnotationsPrefix + "InitrdPath" - // HypervisorPath is a pod annotation for passing a per container path pointing at the hypervisor that will run the container VM. + // HypervisorPath is a sandbox annotation for passing a per container path pointing at the hypervisor that will run the container VM. HypervisorPath = vcAnnotationsPrefix + "HypervisorPath" - // FirmwarePath is a pod annotation for passing a per container path pointing at the guest firmware that will run the container VM. + // FirmwarePath is a sandbox annotation for passing a per container path pointing at the guest firmware that will run the container VM. FirmwarePath = vcAnnotationsPrefix + "FirmwarePath" - // KernelHash is a pod annotation for passing a container kernel image SHA-512 hash value. + // KernelHash is a sandbox annotation for passing a container kernel image SHA-512 hash value. KernelHash = vcAnnotationsPrefix + "KernelHash" - // ImageHash is an pod annotation for passing a container guest image SHA-512 hash value. + // ImageHash is an sandbox annotation for passing a container guest image SHA-512 hash value. ImageHash = vcAnnotationsPrefix + "ImageHash" - // InitrdHash is an pod annotation for passing a container guest initrd SHA-512 hash value. + // InitrdHash is an sandbox annotation for passing a container guest initrd SHA-512 hash value. InitrdHash = vcAnnotationsPrefix + "InitrdHash" - // HypervisorHash is an pod annotation for passing a container hypervisor binary SHA-512 hash value. + // HypervisorHash is an sandbox annotation for passing a container hypervisor binary SHA-512 hash value. HypervisorHash = vcAnnotationsPrefix + "HypervisorHash" - // FirmwareHash is an pod annotation for passing a container guest firmware SHA-512 hash value. + // FirmwareHash is an sandbox annotation for passing a container guest firmware SHA-512 hash value. FirmwareHash = vcAnnotationsPrefix + "FirmwareHash" // AssetHashType is the hash type used for assets verification diff --git a/virtcontainers/pkg/annotations/dockershim/annotations.go b/virtcontainers/pkg/annotations/dockershim/annotations.go index 3724e193f..ce2d48cf1 100644 --- a/virtcontainers/pkg/annotations/dockershim/annotations.go +++ b/virtcontainers/pkg/annotations/dockershim/annotations.go @@ -25,10 +25,10 @@ const ( // ContainerTypeLabelKey is the container type (podsandbox or container) annotation ContainerTypeLabelKey = "io.kubernetes.docker.type" - // ContainerTypeLabelSandbox represents a pod sandbox container + // ContainerTypeLabelSandbox represents a sandbox sandbox container ContainerTypeLabelSandbox = "podsandbox" - // ContainerTypeLabelContainer represents a container running within a pod + // ContainerTypeLabelContainer represents a container running within a sandbox ContainerTypeLabelContainer = "container" // SandboxIDLabelKey is the sandbox ID annotation diff --git a/virtcontainers/pkg/cni/cni.go b/virtcontainers/pkg/cni/cni.go index 3dc93621a..e180a66a0 100644 --- a/virtcontainers/pkg/cni/cni.go +++ b/virtcontainers/pkg/cni/cni.go @@ -123,17 +123,17 @@ func getDefNetwork(confDir, binDir string) (*cniNetwork, error) { return getNetwork(confDir, binDir, DefNetName, false) } -func buildRuntimeConf(podID, podNetNSPath, ifName string) *libcni.RuntimeConf { +func buildRuntimeConf(sandboxID, sandboxNetNSPath, ifName string) *libcni.RuntimeConf { return &libcni.RuntimeConf{ - ContainerID: podID, - NetNS: podNetNSPath, + ContainerID: sandboxID, + NetNS: sandboxNetNSPath, IfName: ifName, } } // AddNetwork calls the CNI plugin to create a network between the host and the network namespace. -func (plugin *NetworkPlugin) AddNetwork(podID, netNSPath, ifName string) (types.Result, error) { - rt := buildRuntimeConf(podID, netNSPath, ifName) +func (plugin *NetworkPlugin) AddNetwork(sandboxID, netNSPath, ifName string) (types.Result, error) { + rt := buildRuntimeConf(sandboxID, netNSPath, ifName) _, err := plugin.loNetwork.cniConfig.AddNetwork(plugin.loNetwork.networkConfig, rt) if err != nil { @@ -150,8 +150,8 @@ func (plugin *NetworkPlugin) AddNetwork(podID, netNSPath, ifName string) (types. // RemoveNetwork calls the CNI plugin to remove a specific network previously created between // the host and the network namespace. -func (plugin *NetworkPlugin) RemoveNetwork(podID, netNSPath, ifName string) error { - rt := buildRuntimeConf(podID, netNSPath, ifName) +func (plugin *NetworkPlugin) RemoveNetwork(sandboxID, netNSPath, ifName string) error { + rt := buildRuntimeConf(sandboxID, netNSPath, ifName) err := plugin.defNetwork.cniConfig.DelNetwork(plugin.defNetwork.networkConfig, rt) if err != nil { diff --git a/virtcontainers/pkg/cni/cni_test.go b/virtcontainers/pkg/cni/cni_test.go index 3ac2a5ef0..cf2072ddd 100644 --- a/virtcontainers/pkg/cni/cni_test.go +++ b/virtcontainers/pkg/cni/cni_test.go @@ -267,12 +267,12 @@ func TestNewNetworkPluginFailureWrongNetwork(t *testing.T) { func TestBuildRuntimeConf(t *testing.T) { expected := libcni.RuntimeConf{ - ContainerID: "testPodID", - NetNS: "testPodNetNSPath", + ContainerID: "testSandboxID", + NetNS: "testSandboxNetNSPath", IfName: "testIfName", } - runtimeConf := buildRuntimeConf("testPodID", "testPodNetNSPath", "testIfName") + runtimeConf := buildRuntimeConf("testSandboxID", "testSandboxNetNSPath", "testIfName") if reflect.DeepEqual(*runtimeConf, expected) == false { t.Fatal("Runtime configuration different from expected one") @@ -298,7 +298,7 @@ func TestAddNetworkSuccessful(t *testing.T) { t.Fatal(err) } - _, err = netPlugin.AddNetwork("testPodID", testNetNsPath, "testIfName") + _, err = netPlugin.AddNetwork("testSandboxID", testNetNsPath, "testIfName") if err != nil { t.Fatal(err) } @@ -323,7 +323,7 @@ func TestAddNetworkFailureUnknownNetNs(t *testing.T) { t.Fatal(err) } - _, err = netPlugin.AddNetwork("testPodID", invalidNetNsPath, "testIfName") + _, err = netPlugin.AddNetwork("testSandboxID", invalidNetNsPath, "testIfName") if err == nil { t.Fatalf("Should fail because netns %s does not exist", invalidNetNsPath) } @@ -348,12 +348,12 @@ func TestRemoveNetworkSuccessful(t *testing.T) { t.Fatal(err) } - _, err = netPlugin.AddNetwork("testPodID", testNetNsPath, "testIfName") + _, err = netPlugin.AddNetwork("testSandboxID", testNetNsPath, "testIfName") if err != nil { t.Fatal(err) } - err = netPlugin.RemoveNetwork("testPodID", testNetNsPath, "testIfName") + err = netPlugin.RemoveNetwork("testSandboxID", testNetNsPath, "testIfName") if err != nil { t.Fatal(err) } @@ -378,7 +378,7 @@ func TestRemoveNetworkSuccessfulNetworkDoesNotExist(t *testing.T) { t.Fatal(err) } - err = netPlugin.RemoveNetwork("testPodID", testNetNsPath, "testIfName") + err = netPlugin.RemoveNetwork("testSandboxID", testNetNsPath, "testIfName") if err != nil { // CNI specification says that no error should be returned // in case we try to tear down a non-existing network. diff --git a/virtcontainers/pkg/hyperstart/hyperstart.go b/virtcontainers/pkg/hyperstart/hyperstart.go index 52401aa44..57f7c2730 100644 --- a/virtcontainers/pkg/hyperstart/hyperstart.go +++ b/virtcontainers/pkg/hyperstart/hyperstart.go @@ -32,15 +32,15 @@ import ( // Need to be in sync with hyperstart/src/api.h const ( Version = "version" - StartPod = "startpod" - DestroyPod = "destroypod" + StartSandbox = "startsandbox" + DestroySandbox = "destroysandbox" ExecCmd = "execcmd" Ready = "ready" Ack = "ack" Error = "error" WinSize = "winsize" Ping = "ping" - FinishPod = "finishpod" + FinishSandbox = "finishsandbox" Next = "next" WriteFile = "writefile" ReadFile = "readfile" @@ -57,8 +57,8 @@ const ( // and its corresponding code. var CodeList = map[string]uint32{ Version: VersionCode, - StartPod: StartPodCode, - DestroyPod: DestroyPodCode, + StartSandbox: StartSandboxCode, + DestroySandbox: DestroySandboxCode, ExecCmd: ExecCmdCode, Ready: ReadyCode, Ack: AckCode, diff --git a/virtcontainers/pkg/hyperstart/hyperstart_test.go b/virtcontainers/pkg/hyperstart/hyperstart_test.go index 3699d119b..a9c210337 100644 --- a/virtcontainers/pkg/hyperstart/hyperstart_test.go +++ b/virtcontainers/pkg/hyperstart/hyperstart_test.go @@ -394,12 +394,12 @@ func TestCodeFromCmdVersion(t *testing.T) { testCodeFromCmd(t, Version, VersionCode) } -func TestCodeFromCmdStartPod(t *testing.T) { - testCodeFromCmd(t, StartPod, StartPodCode) +func TestCodeFromCmdStartSandbox(t *testing.T) { + testCodeFromCmd(t, StartSandbox, StartSandboxCode) } -func TestCodeFromCmdDestroyPod(t *testing.T) { - testCodeFromCmd(t, DestroyPod, DestroyPodCode) +func TestCodeFromCmdDestroySandbox(t *testing.T) { + testCodeFromCmd(t, DestroySandbox, DestroySandboxCode) } func TestCodeFromCmdExecCmd(t *testing.T) { @@ -541,8 +541,8 @@ func TestWaitForReadyError(t *testing.T) { var cmdList = []string{ Version, - StartPod, - DestroyPod, + StartSandbox, + DestroySandbox, ExecCmd, Ready, Ack, diff --git a/virtcontainers/pkg/hyperstart/mock/hyperstart.go b/virtcontainers/pkg/hyperstart/mock/hyperstart.go index b2df6de94..09177fe7e 100644 --- a/virtcontainers/pkg/hyperstart/mock/hyperstart.go +++ b/virtcontainers/pkg/hyperstart/mock/hyperstart.go @@ -31,15 +31,15 @@ import ( // Control command string IDs const ( Version = "version" - StartPod = "startpod" - DestroyPod = "destroypod" + StartSandbox = "startsandbox" + DestroySandbox = "destroysandbox" ExecCmd = "execcmd" Ready = "ready" Ack = "ack" Error = "error" WinSize = "winsize" Ping = "ping" - FinishPod = "finishpod" + FinishSandbox = "finishsandbox" Next = "next" WriteFile = "writefile" ReadFile = "readfile" @@ -53,8 +53,8 @@ const ( var codeList = map[int]string{ hyper.VersionCode: Version, - hyper.StartPodCode: StartPod, - hyper.DestroyPodCode: DestroyPod, + hyper.StartSandboxCode: StartSandbox, + hyper.DestroySandboxCode: DestroySandbox, hyper.ExecCmdCode: ExecCmd, hyper.ReadyCode: Ready, hyper.AckCode: Ack, diff --git a/virtcontainers/pkg/hyperstart/types.go b/virtcontainers/pkg/hyperstart/types.go index b3f407b83..5c2ccc437 100644 --- a/virtcontainers/pkg/hyperstart/types.go +++ b/virtcontainers/pkg/hyperstart/types.go @@ -23,10 +23,10 @@ import ( // Defines all available commands to communicate with hyperstart agent. const ( VersionCode = iota - StartPodCode - GetPodDeprecatedCode - StopPodDeprecatedCode - DestroyPodCode + StartSandboxCode + GetSandboxDeprecatedCode + StopSandboxDeprecatedCode + DestroySandboxCode RestartContainerDeprecatedCode ExecCmdCode FinishCmdDeprecatedCode @@ -35,7 +35,7 @@ const ( ErrorCode WinsizeCode PingCode - FinishPodDeprecatedCode + FinishSandboxDeprecatedCode NextCode WriteFileCode ReadFileCode @@ -166,7 +166,7 @@ type Capabilities struct { Ambient []string `json:"ambient"` } -// Process describes a process running on a container inside a pod. +// Process describes a process running on a container inside a sandbox. type Process struct { // Args specifies the binary and arguments for the application to execute. Args []string `json:"args"` @@ -221,7 +221,7 @@ type Constraints struct { CPUShares uint64 } -// Container describes a container running on a pod. +// Container describes a container running on a sandbox. type Container struct { ID string `json:"id"` Rootfs string `json:"rootfs"` @@ -260,8 +260,8 @@ type Route struct { Device string `json:"device,omitempty"` } -// Pod describes the pod configuration to start inside the VM. -type Pod struct { +// Sandbox describes the sandbox configuration to start inside the VM. +type Sandbox struct { Hostname string `json:"hostname"` Containers []Container `json:"containers,omitempty"` Interfaces []NetworkIface `json:"interfaces,omitempty"` diff --git a/virtcontainers/pkg/oci/utils.go b/virtcontainers/pkg/oci/utils.go index afb161945..fe53f73bc 100644 --- a/virtcontainers/pkg/oci/utils.go +++ b/virtcontainers/pkg/oci/utils.go @@ -46,7 +46,7 @@ var ( CRIContainerTypeKeyList = []string{criContainerdAnnotations.ContainerType, crioAnnotations.ContainerType, dockershimAnnotations.ContainerTypeLabelKey} // CRISandboxNameKeyList lists all the CRI keys that could define - // the sandbox ID (pod ID) from annotations in the config.json. + // the sandbox ID (sandbox ID) from annotations in the config.json. CRISandboxNameKeyList = []string{criContainerdAnnotations.SandboxID, crioAnnotations.SandboxID, dockershimAnnotations.SandboxIDLabelKey} // CRIContainerTypeList lists all the maps from CRI ContainerTypes annotations @@ -409,17 +409,17 @@ func (spec *CompatOCISpec) ContainerType() (vc.ContainerType, error) { return vc.PodSandbox, nil } -// PodID determines the pod ID related to an OCI configuration. This function +// SandboxID determines the sandbox ID related to an OCI configuration. This function // is expected to be called only when the container type is "PodContainer". -func (spec *CompatOCISpec) PodID() (string, error) { +func (spec *CompatOCISpec) SandboxID() (string, error) { for _, key := range CRISandboxNameKeyList { - podID, ok := spec.Annotations[key] + sandboxID, ok := spec.Annotations[key] if ok { - return podID, nil + return sandboxID, nil } } - return "", fmt.Errorf("Could not find pod ID") + return "", fmt.Errorf("Could not find sandbox ID") } func vmConfig(ocispec CompatOCISpec, config RuntimeConfig) (vc.Resources, error) { @@ -443,7 +443,7 @@ func vmConfig(ocispec CompatOCISpec, config RuntimeConfig) (vc.Resources, error) return resources, nil } -func addAssetAnnotations(ocispec CompatOCISpec, config *vc.PodConfig) { +func addAssetAnnotations(ocispec CompatOCISpec, config *vc.SandboxConfig) { assetAnnotations := []string{ vcAnnotations.KernelPath, vcAnnotations.ImagePath, @@ -463,30 +463,30 @@ func addAssetAnnotations(ocispec CompatOCISpec, config *vc.PodConfig) { } } -// PodConfig converts an OCI compatible runtime configuration file -// to a virtcontainers pod configuration structure. -func PodConfig(ocispec CompatOCISpec, runtime RuntimeConfig, bundlePath, cid, console string, detach bool) (vc.PodConfig, error) { +// SandboxConfig converts an OCI compatible runtime configuration file +// to a virtcontainers sandbox configuration structure. +func SandboxConfig(ocispec CompatOCISpec, runtime RuntimeConfig, bundlePath, cid, console string, detach bool) (vc.SandboxConfig, error) { containerConfig, err := ContainerConfig(ocispec, bundlePath, cid, console, detach) if err != nil { - return vc.PodConfig{}, err + return vc.SandboxConfig{}, err } networkConfig, err := networkConfig(ocispec, runtime) if err != nil { - return vc.PodConfig{}, err + return vc.SandboxConfig{}, err } resources, err := vmConfig(ocispec, runtime) if err != nil { - return vc.PodConfig{}, err + return vc.SandboxConfig{}, err } ociSpecJSON, err := json.Marshal(ocispec) if err != nil { - return vc.PodConfig{}, err + return vc.SandboxConfig{}, err } - podConfig := vc.PodConfig{ + sandboxConfig := vc.SandboxConfig{ ID: cid, Hostname: ocispec.Hostname, @@ -518,9 +518,9 @@ func PodConfig(ocispec CompatOCISpec, runtime RuntimeConfig, bundlePath, cid, co }, } - addAssetAnnotations(ocispec, &podConfig) + addAssetAnnotations(ocispec, &sandboxConfig) - return podConfig, nil + return sandboxConfig, nil } // ContainerConfig converts an OCI compatible runtime configuration diff --git a/virtcontainers/pkg/oci/utils_test.go b/virtcontainers/pkg/oci/utils_test.go index 18653b2d3..7c9f7df3b 100644 --- a/virtcontainers/pkg/oci/utils_test.go +++ b/virtcontainers/pkg/oci/utils_test.go @@ -51,7 +51,7 @@ func createConfig(fileName string, fileData string) (string, error) { return configPath, nil } -func TestMinimalPodConfig(t *testing.T) { +func TestMinimalSandboxConfig(t *testing.T) { configPath, err := createConfig("config.json", minimalConfig) if err != nil { t.Fatal(err) @@ -132,7 +132,7 @@ func TestMinimalPodConfig(t *testing.T) { var minimalOCISpec CompatOCISpec - //Marshal and unmarshall json to compare podConfig and expectedPodConfig + //Marshal and unmarshall json to compare sandboxConfig and expectedSandboxConfig if err := json.Unmarshal([]byte(minimalConfig), &minimalOCISpec); err != nil { t.Fatal(err) } @@ -172,7 +172,7 @@ func TestMinimalPodConfig(t *testing.T) { NumInterfaces: 1, } - expectedPodConfig := vc.PodConfig{ + expectedSandboxConfig := vc.SandboxConfig{ ID: containerID, Hostname: "testHostname", @@ -197,13 +197,13 @@ func TestMinimalPodConfig(t *testing.T) { t.Fatalf("Could not parse config.json: %v", err) } - podConfig, err := PodConfig(ociSpec, runtimeConfig, tempBundlePath, containerID, consolePath, false) + sandboxConfig, err := SandboxConfig(ociSpec, runtimeConfig, tempBundlePath, containerID, consolePath, false) if err != nil { - t.Fatalf("Could not create Pod configuration %v", err) + t.Fatalf("Could not create Sandbox configuration %v", err) } - if reflect.DeepEqual(podConfig, expectedPodConfig) == false { - t.Fatalf("Got %v\n expecting %v", podConfig, expectedPodConfig) + if reflect.DeepEqual(sandboxConfig, expectedSandboxConfig) == false { + t.Fatalf("Got %v\n expecting %v", sandboxConfig, expectedSandboxConfig) } if err := os.Remove(configPath); err != nil { @@ -613,34 +613,34 @@ func TestContainerTypeFailure(t *testing.T) { } } -func TestPodIDSuccessful(t *testing.T) { +func TestSandboxIDSuccessful(t *testing.T) { var ociSpec CompatOCISpec - testPodID := "testPodID" + testSandboxID := "testSandboxID" ociSpec.Annotations = map[string]string{ - annotations.SandboxID: testPodID, + annotations.SandboxID: testSandboxID, } - podID, err := ociSpec.PodID() + sandboxID, err := ociSpec.SandboxID() if err != nil { t.Fatal(err) } - if podID != testPodID { - t.Fatalf("Got %s, Expecting %s", podID, testPodID) + if sandboxID != testSandboxID { + t.Fatalf("Got %s, Expecting %s", sandboxID, testSandboxID) } } -func TestPodIDFailure(t *testing.T) { +func TestSandboxIDFailure(t *testing.T) { var ociSpec CompatOCISpec - podID, err := ociSpec.PodID() + sandboxID, err := ociSpec.SandboxID() if err == nil { t.Fatalf("This test should fail because annotations is empty") } - if podID != "" { - t.Fatalf("Got %s, Expecting empty pod ID", podID) + if sandboxID != "" { + t.Fatalf("Got %s, Expecting empty sandbox ID", sandboxID) } } diff --git a/virtcontainers/pkg/vcmock/container.go b/virtcontainers/pkg/vcmock/container.go index 07432c8c1..8da24bc03 100644 --- a/virtcontainers/pkg/vcmock/container.go +++ b/virtcontainers/pkg/vcmock/container.go @@ -23,9 +23,9 @@ func (c *Container) ID() string { return c.MockID } -// Pod implements the VCContainer function of the same name. -func (c *Container) Pod() vc.VCPod { - return c.MockPod +// Sandbox implements the VCContainer function of the same name. +func (c *Container) Sandbox() vc.VCSandbox { + return c.MockSandbox } // Process implements the VCContainer function of the same name. diff --git a/virtcontainers/pkg/vcmock/mock.go b/virtcontainers/pkg/vcmock/mock.go index b421b8567..0a9814195 100644 --- a/virtcontainers/pkg/vcmock/mock.go +++ b/virtcontainers/pkg/vcmock/mock.go @@ -16,8 +16,8 @@ // for testing. // // This implementation calls the function set in the object that -// corresponds to the name of the method (for example, when CreatePod() -// is called, that method will try to call CreatePodFunc). If no +// corresponds to the name of the method (for example, when CreateSandbox() +// is called, that method will try to call CreateSandboxFunc). If no // function is defined for the method, it will return an error in a // well-known format. Callers can detect this scenario by calling // IsMockError(). @@ -43,155 +43,155 @@ func (m *VCMock) SetLogger(logger logrus.FieldLogger) { } } -// CreatePod implements the VC function of the same name. -func (m *VCMock) CreatePod(podConfig vc.PodConfig) (vc.VCPod, error) { - if m.CreatePodFunc != nil { - return m.CreatePodFunc(podConfig) +// CreateSandbox implements the VC function of the same name. +func (m *VCMock) CreateSandbox(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + if m.CreateSandboxFunc != nil { + return m.CreateSandboxFunc(sandboxConfig) } - return nil, fmt.Errorf("%s: %s (%+v): podConfig: %v", mockErrorPrefix, getSelf(), m, podConfig) + return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig) } -// DeletePod implements the VC function of the same name. -func (m *VCMock) DeletePod(podID string) (vc.VCPod, error) { - if m.DeletePodFunc != nil { - return m.DeletePodFunc(podID) +// DeleteSandbox implements the VC function of the same name. +func (m *VCMock) DeleteSandbox(sandboxID string) (vc.VCSandbox, error) { + if m.DeleteSandboxFunc != nil { + return m.DeleteSandboxFunc(sandboxID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v", mockErrorPrefix, getSelf(), m, podID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID) } -// StartPod implements the VC function of the same name. -func (m *VCMock) StartPod(podID string) (vc.VCPod, error) { - if m.StartPodFunc != nil { - return m.StartPodFunc(podID) +// StartSandbox implements the VC function of the same name. +func (m *VCMock) StartSandbox(sandboxID string) (vc.VCSandbox, error) { + if m.StartSandboxFunc != nil { + return m.StartSandboxFunc(sandboxID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v", mockErrorPrefix, getSelf(), m, podID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID) } -// StopPod implements the VC function of the same name. -func (m *VCMock) StopPod(podID string) (vc.VCPod, error) { - if m.StopPodFunc != nil { - return m.StopPodFunc(podID) +// StopSandbox implements the VC function of the same name. +func (m *VCMock) StopSandbox(sandboxID string) (vc.VCSandbox, error) { + if m.StopSandboxFunc != nil { + return m.StopSandboxFunc(sandboxID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v", mockErrorPrefix, getSelf(), m, podID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID) } -// RunPod implements the VC function of the same name. -func (m *VCMock) RunPod(podConfig vc.PodConfig) (vc.VCPod, error) { - if m.RunPodFunc != nil { - return m.RunPodFunc(podConfig) +// RunSandbox implements the VC function of the same name. +func (m *VCMock) RunSandbox(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + if m.RunSandboxFunc != nil { + return m.RunSandboxFunc(sandboxConfig) } - return nil, fmt.Errorf("%s: %s (%+v): podConfig: %v", mockErrorPrefix, getSelf(), m, podConfig) + return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig) } -// ListPod implements the VC function of the same name. -func (m *VCMock) ListPod() ([]vc.PodStatus, error) { - if m.ListPodFunc != nil { - return m.ListPodFunc() +// ListSandbox implements the VC function of the same name. +func (m *VCMock) ListSandbox() ([]vc.SandboxStatus, error) { + if m.ListSandboxFunc != nil { + return m.ListSandboxFunc() } return nil, fmt.Errorf("%s: %s", mockErrorPrefix, getSelf()) } -// StatusPod implements the VC function of the same name. -func (m *VCMock) StatusPod(podID string) (vc.PodStatus, error) { - if m.StatusPodFunc != nil { - return m.StatusPodFunc(podID) +// StatusSandbox implements the VC function of the same name. +func (m *VCMock) StatusSandbox(sandboxID string) (vc.SandboxStatus, error) { + if m.StatusSandboxFunc != nil { + return m.StatusSandboxFunc(sandboxID) } - return vc.PodStatus{}, fmt.Errorf("%s: %s (%+v): podID: %v", mockErrorPrefix, getSelf(), m, podID) + return vc.SandboxStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID) } -// PausePod implements the VC function of the same name. -func (m *VCMock) PausePod(podID string) (vc.VCPod, error) { - if m.PausePodFunc != nil { - return m.PausePodFunc(podID) +// PauseSandbox implements the VC function of the same name. +func (m *VCMock) PauseSandbox(sandboxID string) (vc.VCSandbox, error) { + if m.PauseSandboxFunc != nil { + return m.PauseSandboxFunc(sandboxID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v", mockErrorPrefix, getSelf(), m, podID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID) } -// ResumePod implements the VC function of the same name. -func (m *VCMock) ResumePod(podID string) (vc.VCPod, error) { - if m.ResumePodFunc != nil { - return m.ResumePodFunc(podID) +// ResumeSandbox implements the VC function of the same name. +func (m *VCMock) ResumeSandbox(sandboxID string) (vc.VCSandbox, error) { + if m.ResumeSandboxFunc != nil { + return m.ResumeSandboxFunc(sandboxID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v", mockErrorPrefix, getSelf(), m, podID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID) } // CreateContainer implements the VC function of the same name. -func (m *VCMock) CreateContainer(podID string, containerConfig vc.ContainerConfig) (vc.VCPod, vc.VCContainer, error) { +func (m *VCMock) CreateContainer(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) { if m.CreateContainerFunc != nil { - return m.CreateContainerFunc(podID, containerConfig) + return m.CreateContainerFunc(sandboxID, containerConfig) } - return nil, nil, fmt.Errorf("%s: %s (%+v): podID: %v, containerConfig: %v", mockErrorPrefix, getSelf(), m, podID, containerConfig) + return nil, nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerConfig: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerConfig) } // DeleteContainer implements the VC function of the same name. -func (m *VCMock) DeleteContainer(podID, containerID string) (vc.VCContainer, error) { +func (m *VCMock) DeleteContainer(sandboxID, containerID string) (vc.VCContainer, error) { if m.DeleteContainerFunc != nil { - return m.DeleteContainerFunc(podID, containerID) + return m.DeleteContainerFunc(sandboxID, containerID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, podID, containerID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID) } // StartContainer implements the VC function of the same name. -func (m *VCMock) StartContainer(podID, containerID string) (vc.VCContainer, error) { +func (m *VCMock) StartContainer(sandboxID, containerID string) (vc.VCContainer, error) { if m.StartContainerFunc != nil { - return m.StartContainerFunc(podID, containerID) + return m.StartContainerFunc(sandboxID, containerID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, podID, containerID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID) } // StopContainer implements the VC function of the same name. -func (m *VCMock) StopContainer(podID, containerID string) (vc.VCContainer, error) { +func (m *VCMock) StopContainer(sandboxID, containerID string) (vc.VCContainer, error) { if m.StopContainerFunc != nil { - return m.StopContainerFunc(podID, containerID) + return m.StopContainerFunc(sandboxID, containerID) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, podID, containerID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID) } // EnterContainer implements the VC function of the same name. -func (m *VCMock) EnterContainer(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) { +func (m *VCMock) EnterContainer(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { if m.EnterContainerFunc != nil { - return m.EnterContainerFunc(podID, containerID, cmd) + return m.EnterContainerFunc(sandboxID, containerID, cmd) } - return nil, nil, nil, fmt.Errorf("%s: %s (%+v): podID: %v, containerID: %v, cmd: %v", mockErrorPrefix, getSelf(), m, podID, containerID, cmd) + return nil, nil, nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v, cmd: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID, cmd) } // StatusContainer implements the VC function of the same name. -func (m *VCMock) StatusContainer(podID, containerID string) (vc.ContainerStatus, error) { +func (m *VCMock) StatusContainer(sandboxID, containerID string) (vc.ContainerStatus, error) { if m.StatusContainerFunc != nil { - return m.StatusContainerFunc(podID, containerID) + return m.StatusContainerFunc(sandboxID, containerID) } - return vc.ContainerStatus{}, fmt.Errorf("%s: %s (%+v): podID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, podID, containerID) + return vc.ContainerStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID) } // KillContainer implements the VC function of the same name. -func (m *VCMock) KillContainer(podID, containerID string, signal syscall.Signal, all bool) error { +func (m *VCMock) KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error { if m.KillContainerFunc != nil { - return m.KillContainerFunc(podID, containerID, signal, all) + return m.KillContainerFunc(sandboxID, containerID, signal, all) } - return fmt.Errorf("%s: %s (%+v): podID: %v, containerID: %v, signal: %v, all: %v", mockErrorPrefix, getSelf(), m, podID, containerID, signal, all) + return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v, signal: %v, all: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID, signal, all) } // ProcessListContainer implements the VC function of the same name. -func (m *VCMock) ProcessListContainer(podID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) { +func (m *VCMock) ProcessListContainer(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) { if m.ProcessListContainerFunc != nil { - return m.ProcessListContainerFunc(podID, containerID, options) + return m.ProcessListContainerFunc(sandboxID, containerID, options) } - return nil, fmt.Errorf("%s: %s (%+v): podID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, podID, containerID) + return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID) } diff --git a/virtcontainers/pkg/vcmock/mock_test.go b/virtcontainers/pkg/vcmock/mock_test.go index 95d6aac33..be3d3759e 100644 --- a/virtcontainers/pkg/vcmock/mock_test.go +++ b/virtcontainers/pkg/vcmock/mock_test.go @@ -25,7 +25,7 @@ import ( ) const ( - testPodID = "testPodID" + testSandboxID = "testSandboxID" testContainerID = "testContainerID" ) @@ -53,14 +53,14 @@ func TestVCImplementations(t *testing.T) { assert.True(t, testImplementsIF) } -func TestVCPodImplementations(t *testing.T) { +func TestVCSandboxImplementations(t *testing.T) { // official implementation - mainImpl := &vc.Pod{} + mainImpl := &vc.Sandbox{} // test implementation - testImpl := &Pod{} + testImpl := &Sandbox{} - var interfaceType vc.VCPod + var interfaceType vc.VCSandbox // check that the official implementation implements the // interface @@ -117,236 +117,236 @@ func TestVCMockSetLogger(t *testing.T) { assert.Equal(loggerTriggered, 1) } -func TestVCMockCreatePod(t *testing.T) { +func TestVCMockCreateSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.CreatePodFunc) + assert.Nil(m.CreateSandboxFunc) - _, err := m.CreatePod(vc.PodConfig{}) + _, err := m.CreateSandbox(vc.SandboxConfig{}) assert.Error(err) assert.True(IsMockError(err)) - m.CreatePodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return &Pod{}, nil + m.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return &Sandbox{}, nil } - pod, err := m.CreatePod(vc.PodConfig{}) + sandbox, err := m.CreateSandbox(vc.SandboxConfig{}) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) // reset - m.CreatePodFunc = nil + m.CreateSandboxFunc = nil - _, err = m.CreatePod(vc.PodConfig{}) + _, err = m.CreateSandbox(vc.SandboxConfig{}) assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockDeletePod(t *testing.T) { +func TestVCMockDeleteSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.DeletePodFunc) + assert.Nil(m.DeleteSandboxFunc) - _, err := m.DeletePod(testPodID) + _, err := m.DeleteSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) - m.DeletePodFunc = func(podID string) (vc.VCPod, error) { - return &Pod{}, nil + m.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return &Sandbox{}, nil } - pod, err := m.DeletePod(testPodID) + sandbox, err := m.DeleteSandbox(testSandboxID) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) // reset - m.DeletePodFunc = nil + m.DeleteSandboxFunc = nil - _, err = m.DeletePod(testPodID) + _, err = m.DeleteSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockListPod(t *testing.T) { +func TestVCMockListSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.ListPodFunc) + assert.Nil(m.ListSandboxFunc) - _, err := m.ListPod() + _, err := m.ListSandbox() assert.Error(err) assert.True(IsMockError(err)) - m.ListPodFunc = func() ([]vc.PodStatus, error) { - return []vc.PodStatus{}, nil + m.ListSandboxFunc = func() ([]vc.SandboxStatus, error) { + return []vc.SandboxStatus{}, nil } - pods, err := m.ListPod() + sandboxes, err := m.ListSandbox() assert.NoError(err) - assert.Equal(pods, []vc.PodStatus{}) + assert.Equal(sandboxes, []vc.SandboxStatus{}) // reset - m.ListPodFunc = nil + m.ListSandboxFunc = nil - _, err = m.ListPod() + _, err = m.ListSandbox() assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockPausePod(t *testing.T) { +func TestVCMockPauseSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.PausePodFunc) + assert.Nil(m.PauseSandboxFunc) - _, err := m.PausePod(testPodID) + _, err := m.PauseSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) - m.PausePodFunc = func(podID string) (vc.VCPod, error) { - return &Pod{}, nil + m.PauseSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return &Sandbox{}, nil } - pod, err := m.PausePod(testPodID) + sandbox, err := m.PauseSandbox(testSandboxID) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) // reset - m.PausePodFunc = nil + m.PauseSandboxFunc = nil - _, err = m.PausePod(testPodID) + _, err = m.PauseSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockResumePod(t *testing.T) { +func TestVCMockResumeSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.ResumePodFunc) + assert.Nil(m.ResumeSandboxFunc) - _, err := m.ResumePod(testPodID) + _, err := m.ResumeSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) - m.ResumePodFunc = func(podID string) (vc.VCPod, error) { - return &Pod{}, nil + m.ResumeSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return &Sandbox{}, nil } - pod, err := m.ResumePod(testPodID) + sandbox, err := m.ResumeSandbox(testSandboxID) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) // reset - m.ResumePodFunc = nil + m.ResumeSandboxFunc = nil - _, err = m.ResumePod(testPodID) + _, err = m.ResumeSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockRunPod(t *testing.T) { +func TestVCMockRunSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.RunPodFunc) + assert.Nil(m.RunSandboxFunc) - _, err := m.RunPod(vc.PodConfig{}) + _, err := m.RunSandbox(vc.SandboxConfig{}) assert.Error(err) assert.True(IsMockError(err)) - m.RunPodFunc = func(podConfig vc.PodConfig) (vc.VCPod, error) { - return &Pod{}, nil + m.RunSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + return &Sandbox{}, nil } - pod, err := m.RunPod(vc.PodConfig{}) + sandbox, err := m.RunSandbox(vc.SandboxConfig{}) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) // reset - m.RunPodFunc = nil + m.RunSandboxFunc = nil - _, err = m.RunPod(vc.PodConfig{}) + _, err = m.RunSandbox(vc.SandboxConfig{}) assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockStartPod(t *testing.T) { +func TestVCMockStartSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.StartPodFunc) + assert.Nil(m.StartSandboxFunc) - _, err := m.StartPod(testPodID) + _, err := m.StartSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) - m.StartPodFunc = func(podID string) (vc.VCPod, error) { - return &Pod{}, nil + m.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return &Sandbox{}, nil } - pod, err := m.StartPod(testPodID) + sandbox, err := m.StartSandbox(testSandboxID) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) // reset - m.StartPodFunc = nil + m.StartSandboxFunc = nil - _, err = m.StartPod(testPodID) + _, err = m.StartSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockStatusPod(t *testing.T) { +func TestVCMockStatusSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.StatusPodFunc) + assert.Nil(m.StatusSandboxFunc) - _, err := m.StatusPod(testPodID) + _, err := m.StatusSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) - m.StatusPodFunc = func(podID string) (vc.PodStatus, error) { - return vc.PodStatus{}, nil + m.StatusSandboxFunc = func(sandboxID string) (vc.SandboxStatus, error) { + return vc.SandboxStatus{}, nil } - pod, err := m.StatusPod(testPodID) + sandbox, err := m.StatusSandbox(testSandboxID) assert.NoError(err) - assert.Equal(pod, vc.PodStatus{}) + assert.Equal(sandbox, vc.SandboxStatus{}) // reset - m.StatusPodFunc = nil + m.StatusSandboxFunc = nil - _, err = m.StatusPod(testPodID) + _, err = m.StatusSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) } -func TestVCMockStopPod(t *testing.T) { +func TestVCMockStopSandbox(t *testing.T) { assert := assert.New(t) m := &VCMock{} - assert.Nil(m.StopPodFunc) + assert.Nil(m.StopSandboxFunc) - _, err := m.StopPod(testPodID) + _, err := m.StopSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) - m.StopPodFunc = func(podID string) (vc.VCPod, error) { - return &Pod{}, nil + m.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) { + return &Sandbox{}, nil } - pod, err := m.StopPod(testPodID) + sandbox, err := m.StopSandbox(testSandboxID) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) // reset - m.StopPodFunc = nil + m.StopSandboxFunc = nil - _, err = m.StopPod(testPodID) + _, err = m.StopSandbox(testSandboxID) assert.Error(err) assert.True(IsMockError(err)) } @@ -358,23 +358,23 @@ func TestVCMockCreateContainer(t *testing.T) { assert.Nil(m.CreateContainerFunc) config := vc.ContainerConfig{} - _, _, err := m.CreateContainer(testPodID, config) + _, _, err := m.CreateContainer(testSandboxID, config) assert.Error(err) assert.True(IsMockError(err)) - m.CreateContainerFunc = func(podID string, containerConfig vc.ContainerConfig) (vc.VCPod, vc.VCContainer, error) { - return &Pod{}, &Container{}, nil + m.CreateContainerFunc = func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) { + return &Sandbox{}, &Container{}, nil } - pod, container, err := m.CreateContainer(testPodID, config) + sandbox, container, err := m.CreateContainer(testSandboxID, config) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) assert.Equal(container, &Container{}) // reset m.CreateContainerFunc = nil - _, _, err = m.CreateContainer(testPodID, config) + _, _, err = m.CreateContainer(testSandboxID, config) assert.Error(err) assert.True(IsMockError(err)) } @@ -385,22 +385,22 @@ func TestVCMockDeleteContainer(t *testing.T) { m := &VCMock{} assert.Nil(m.DeleteContainerFunc) - _, err := m.DeleteContainer(testPodID, testContainerID) + _, err := m.DeleteContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) - m.DeleteContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + m.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { return &Container{}, nil } - container, err := m.DeleteContainer(testPodID, testContainerID) + container, err := m.DeleteContainer(testSandboxID, testContainerID) assert.NoError(err) assert.Equal(container, &Container{}) // reset m.DeleteContainerFunc = nil - _, err = m.DeleteContainer(testPodID, testContainerID) + _, err = m.DeleteContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) } @@ -412,24 +412,24 @@ func TestVCMockEnterContainer(t *testing.T) { assert.Nil(m.EnterContainerFunc) cmd := vc.Cmd{} - _, _, _, err := m.EnterContainer(testPodID, testContainerID, cmd) + _, _, _, err := m.EnterContainer(testSandboxID, testContainerID, cmd) assert.Error(err) assert.True(IsMockError(err)) - m.EnterContainerFunc = func(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) { - return &Pod{}, &Container{}, &vc.Process{}, nil + m.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) { + return &Sandbox{}, &Container{}, &vc.Process{}, nil } - pod, container, process, err := m.EnterContainer(testPodID, testContainerID, cmd) + sandbox, container, process, err := m.EnterContainer(testSandboxID, testContainerID, cmd) assert.NoError(err) - assert.Equal(pod, &Pod{}) + assert.Equal(sandbox, &Sandbox{}) assert.Equal(container, &Container{}) assert.Equal(process, &vc.Process{}) // reset m.EnterContainerFunc = nil - _, _, _, err = m.EnterContainer(testPodID, testContainerID, cmd) + _, _, _, err = m.EnterContainer(testSandboxID, testContainerID, cmd) assert.Error(err) assert.True(IsMockError(err)) } @@ -443,17 +443,17 @@ func TestVCMockKillContainer(t *testing.T) { sig := syscall.SIGTERM for _, all := range []bool{true, false} { - err := m.KillContainer(testPodID, testContainerID, sig, all) + err := m.KillContainer(testSandboxID, testContainerID, sig, all) assert.Error(err) assert.True(IsMockError(err)) } - m.KillContainerFunc = func(podID, containerID string, signal syscall.Signal, all bool) error { + m.KillContainerFunc = func(sandboxID, containerID string, signal syscall.Signal, all bool) error { return nil } for _, all := range []bool{true, false} { - err := m.KillContainer(testPodID, testContainerID, sig, all) + err := m.KillContainer(testSandboxID, testContainerID, sig, all) assert.NoError(err) } @@ -461,7 +461,7 @@ func TestVCMockKillContainer(t *testing.T) { m.KillContainerFunc = nil for _, all := range []bool{true, false} { - err := m.KillContainer(testPodID, testContainerID, sig, all) + err := m.KillContainer(testSandboxID, testContainerID, sig, all) assert.Error(err) assert.True(IsMockError(err)) } @@ -473,22 +473,22 @@ func TestVCMockStartContainer(t *testing.T) { m := &VCMock{} assert.Nil(m.StartContainerFunc) - _, err := m.StartContainer(testPodID, testContainerID) + _, err := m.StartContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) - m.StartContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + m.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { return &Container{}, nil } - container, err := m.StartContainer(testPodID, testContainerID) + container, err := m.StartContainer(testSandboxID, testContainerID) assert.NoError(err) assert.Equal(container, &Container{}) // reset m.StartContainerFunc = nil - _, err = m.StartContainer(testPodID, testContainerID) + _, err = m.StartContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) } @@ -499,22 +499,22 @@ func TestVCMockStatusContainer(t *testing.T) { m := &VCMock{} assert.Nil(m.StatusContainerFunc) - _, err := m.StatusContainer(testPodID, testContainerID) + _, err := m.StatusContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) - m.StatusContainerFunc = func(podID, containerID string) (vc.ContainerStatus, error) { + m.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) { return vc.ContainerStatus{}, nil } - status, err := m.StatusContainer(testPodID, testContainerID) + status, err := m.StatusContainer(testSandboxID, testContainerID) assert.NoError(err) assert.Equal(status, vc.ContainerStatus{}) // reset m.StatusContainerFunc = nil - _, err = m.StatusContainer(testPodID, testContainerID) + _, err = m.StatusContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) } @@ -525,22 +525,22 @@ func TestVCMockStopContainer(t *testing.T) { m := &VCMock{} assert.Nil(m.StopContainerFunc) - _, err := m.StopContainer(testPodID, testContainerID) + _, err := m.StopContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) - m.StopContainerFunc = func(podID, containerID string) (vc.VCContainer, error) { + m.StopContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) { return &Container{}, nil } - container, err := m.StopContainer(testPodID, testContainerID) + container, err := m.StopContainer(testSandboxID, testContainerID) assert.NoError(err) assert.Equal(container, &Container{}) // reset m.StopContainerFunc = nil - _, err = m.StopContainer(testPodID, testContainerID) + _, err = m.StopContainer(testSandboxID, testContainerID) assert.Error(err) assert.True(IsMockError(err)) } @@ -556,24 +556,24 @@ func TestVCMockProcessListContainer(t *testing.T) { Args: []string{"-ef"}, } - _, err := m.ProcessListContainer(testPodID, testContainerID, options) + _, err := m.ProcessListContainer(testSandboxID, testContainerID, options) assert.Error(err) assert.True(IsMockError(err)) processList := vc.ProcessList("hi") - m.ProcessListContainerFunc = func(podID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) { + m.ProcessListContainerFunc = func(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) { return processList, nil } - pList, err := m.ProcessListContainer(testPodID, testContainerID, options) + pList, err := m.ProcessListContainer(testSandboxID, testContainerID, options) assert.NoError(err) assert.Equal(pList, processList) // reset m.ProcessListContainerFunc = nil - _, err = m.ProcessListContainer(testPodID, testContainerID, options) + _, err = m.ProcessListContainer(testSandboxID, testContainerID, options) assert.Error(err) assert.True(IsMockError(err)) } diff --git a/virtcontainers/pkg/vcmock/pod.go b/virtcontainers/pkg/vcmock/sandbox.go similarity index 58% rename from virtcontainers/pkg/vcmock/pod.go rename to virtcontainers/pkg/vcmock/sandbox.go index c05462255..3c7ec68b8 100644 --- a/virtcontainers/pkg/vcmock/pod.go +++ b/virtcontainers/pkg/vcmock/sandbox.go @@ -18,28 +18,28 @@ import ( vc "github.com/kata-containers/runtime/virtcontainers" ) -// ID implements the VCPod function of the same name. -func (p *Pod) ID() string { +// ID implements the VCSandbox function of the same name. +func (p *Sandbox) ID() string { return p.MockID } -// Annotations implements the VCPod function of the same name. -func (p *Pod) Annotations(key string) (string, error) { +// Annotations implements the VCSandbox function of the same name. +func (p *Sandbox) Annotations(key string) (string, error) { return p.MockAnnotations[key], nil } -// SetAnnotations implements the VCPod function of the same name. -func (p *Pod) SetAnnotations(annotations map[string]string) error { +// SetAnnotations implements the VCSandbox function of the same name. +func (p *Sandbox) SetAnnotations(annotations map[string]string) error { return nil } -// GetAnnotations implements the VCPod function of the same name. -func (p *Pod) GetAnnotations() map[string]string { +// GetAnnotations implements the VCSandbox function of the same name. +func (p *Sandbox) GetAnnotations() map[string]string { return p.MockAnnotations } -// GetAllContainers implements the VCPod function of the same name. -func (p *Pod) GetAllContainers() []vc.VCContainer { +// GetAllContainers implements the VCSandbox function of the same name. +func (p *Sandbox) GetAllContainers() []vc.VCContainer { var ifa = make([]vc.VCContainer, len(p.MockContainers)) for i, v := range p.MockContainers { @@ -49,8 +49,8 @@ func (p *Pod) GetAllContainers() []vc.VCContainer { return ifa } -// GetContainer implements the VCPod function of the same name. -func (p *Pod) GetContainer(containerID string) vc.VCContainer { +// GetContainer implements the VCSandbox function of the same name. +func (p *Sandbox) GetContainer(containerID string) vc.VCContainer { for _, c := range p.MockContainers { if c.MockID == containerID { return c diff --git a/virtcontainers/pkg/vcmock/types.go b/virtcontainers/pkg/vcmock/types.go index f38e44108..37df12a7d 100644 --- a/virtcontainers/pkg/vcmock/types.go +++ b/virtcontainers/pkg/vcmock/types.go @@ -21,8 +21,8 @@ import ( "github.com/sirupsen/logrus" ) -// Pod is a fake Pod type used for testing -type Pod struct { +// Sandbox is a fake Sandbox type used for testing +type Sandbox struct { MockID string MockURL string MockAnnotations map[string]string @@ -36,7 +36,7 @@ type Container struct { MockToken string MockProcess vc.Process MockPid int - MockPod *Pod + MockSandbox *Sandbox MockAnnotations map[string]string } @@ -45,22 +45,22 @@ type Container struct { type VCMock struct { SetLoggerFunc func(logger logrus.FieldLogger) - CreatePodFunc func(podConfig vc.PodConfig) (vc.VCPod, error) - DeletePodFunc func(podID string) (vc.VCPod, error) - ListPodFunc func() ([]vc.PodStatus, error) - PausePodFunc func(podID string) (vc.VCPod, error) - ResumePodFunc func(podID string) (vc.VCPod, error) - RunPodFunc func(podConfig vc.PodConfig) (vc.VCPod, error) - StartPodFunc func(podID string) (vc.VCPod, error) - StatusPodFunc func(podID string) (vc.PodStatus, error) - StopPodFunc func(podID string) (vc.VCPod, error) + CreateSandboxFunc func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) + DeleteSandboxFunc func(sandboxID string) (vc.VCSandbox, error) + ListSandboxFunc func() ([]vc.SandboxStatus, error) + PauseSandboxFunc func(sandboxID string) (vc.VCSandbox, error) + ResumeSandboxFunc func(sandboxID string) (vc.VCSandbox, error) + RunSandboxFunc func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) + StartSandboxFunc func(sandboxID string) (vc.VCSandbox, error) + StatusSandboxFunc func(sandboxID string) (vc.SandboxStatus, error) + StopSandboxFunc func(sandboxID string) (vc.VCSandbox, error) - CreateContainerFunc func(podID string, containerConfig vc.ContainerConfig) (vc.VCPod, vc.VCContainer, error) - DeleteContainerFunc func(podID, containerID string) (vc.VCContainer, error) - EnterContainerFunc func(podID, containerID string, cmd vc.Cmd) (vc.VCPod, vc.VCContainer, *vc.Process, error) - KillContainerFunc func(podID, containerID string, signal syscall.Signal, all bool) error - StartContainerFunc func(podID, containerID string) (vc.VCContainer, error) - StatusContainerFunc func(podID, containerID string) (vc.ContainerStatus, error) - StopContainerFunc func(podID, containerID string) (vc.VCContainer, error) - ProcessListContainerFunc func(podID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) + CreateContainerFunc func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) + DeleteContainerFunc func(sandboxID, containerID string) (vc.VCContainer, error) + EnterContainerFunc func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) + KillContainerFunc func(sandboxID, containerID string, signal syscall.Signal, all bool) error + StartContainerFunc func(sandboxID, containerID string) (vc.VCContainer, error) + StatusContainerFunc func(sandboxID, containerID string) (vc.ContainerStatus, error) + StopContainerFunc func(sandboxID, containerID string) (vc.VCContainer, error) + ProcessListContainerFunc func(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) } diff --git a/virtcontainers/proxy.go b/virtcontainers/proxy.go index 45ff4a776..35a7665ba 100644 --- a/virtcontainers/proxy.go +++ b/virtcontainers/proxy.go @@ -131,19 +131,19 @@ func newProxy(pType ProxyType) (proxy, error) { } } -// newProxyConfig returns a proxy config from a generic PodConfig handler, +// newProxyConfig returns a proxy config from a generic SandboxConfig handler, // after it properly checked the configuration was valid. -func newProxyConfig(podConfig *PodConfig) (ProxyConfig, error) { - if podConfig == nil { - return ProxyConfig{}, fmt.Errorf("Pod config cannot be nil") +func newProxyConfig(sandboxConfig *SandboxConfig) (ProxyConfig, error) { + if sandboxConfig == nil { + return ProxyConfig{}, fmt.Errorf("Sandbox config cannot be nil") } var config ProxyConfig - switch podConfig.ProxyType { + switch sandboxConfig.ProxyType { case KataProxyType: fallthrough case CCProxyType: - if err := mapstructure.Decode(podConfig.ProxyConfig, &config); err != nil { + if err := mapstructure.Decode(sandboxConfig.ProxyConfig, &config); err != nil { return ProxyConfig{}, err } } @@ -155,10 +155,10 @@ func newProxyConfig(podConfig *PodConfig) (ProxyConfig, error) { return config, nil } -func defaultProxyURL(pod Pod, socketType string) (string, error) { +func defaultProxyURL(sandbox Sandbox, socketType string) (string, error) { switch socketType { case SocketTypeUNIX: - socketPath := filepath.Join(runStoragePath, pod.id, "proxy.sock") + socketPath := filepath.Join(runStoragePath, sandbox.id, "proxy.sock") return fmt.Sprintf("unix://%s", socketPath), nil case SocketTypeVSOCK: // TODO Build the VSOCK default URL @@ -174,11 +174,11 @@ func isProxyBuiltIn(pType ProxyType) bool { // proxy is the virtcontainers proxy interface. type proxy interface { - // start launches a proxy instance for the specified pod, returning + // start launches a proxy instance for the specified sandbox, returning // the PID of the process and the URL used to connect to it. - start(pod Pod, params proxyParams) (int, string, error) + start(sandbox Sandbox, params proxyParams) (int, string, error) // stop terminates a proxy instance after all communications with the // agent inside the VM have been properly stopped. - stop(pod Pod, pid int) error + stop(sandbox Sandbox, pid int) error } diff --git a/virtcontainers/proxy_test.go b/virtcontainers/proxy_test.go index 2d4fa38fd..768dfa45a 100644 --- a/virtcontainers/proxy_test.go +++ b/virtcontainers/proxy_test.go @@ -161,8 +161,8 @@ func TestNewProxyFromUnknownProxyType(t *testing.T) { } } -func testNewProxyConfigFromPodConfig(t *testing.T, podConfig PodConfig, expected ProxyConfig) { - result, err := newProxyConfig(&podConfig) +func testNewProxyConfigFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfig, expected ProxyConfig) { + result, err := newProxyConfig(&sandboxConfig) if err != nil { t.Fatal(err) } @@ -174,57 +174,57 @@ func testNewProxyConfigFromPodConfig(t *testing.T, podConfig PodConfig, expected var testProxyPath = "proxy-path" -func TestNewProxyConfigFromCCProxyPodConfig(t *testing.T) { +func TestNewProxyConfigFromCCProxySandboxConfig(t *testing.T) { proxyConfig := ProxyConfig{ Path: testProxyPath, } - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ ProxyType: CCProxyType, ProxyConfig: proxyConfig, } - testNewProxyConfigFromPodConfig(t, podConfig, proxyConfig) + testNewProxyConfigFromSandboxConfig(t, sandboxConfig, proxyConfig) } -func TestNewProxyConfigFromKataProxyPodConfig(t *testing.T) { +func TestNewProxyConfigFromKataProxySandboxConfig(t *testing.T) { proxyConfig := ProxyConfig{ Path: testProxyPath, } - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ ProxyType: KataProxyType, ProxyConfig: proxyConfig, } - testNewProxyConfigFromPodConfig(t, podConfig, proxyConfig) + testNewProxyConfigFromSandboxConfig(t, sandboxConfig, proxyConfig) } -func TestNewProxyConfigNilPodConfigFailure(t *testing.T) { +func TestNewProxyConfigNilSandboxConfigFailure(t *testing.T) { if _, err := newProxyConfig(nil); err == nil { - t.Fatal("Should fail because PodConfig provided is nil") + t.Fatal("Should fail because SandboxConfig provided is nil") } } func TestNewProxyConfigNoPathFailure(t *testing.T) { - podConfig := &PodConfig{ + sandboxConfig := &SandboxConfig{ ProxyType: CCProxyType, ProxyConfig: ProxyConfig{}, } - if _, err := newProxyConfig(podConfig); err == nil { + if _, err := newProxyConfig(sandboxConfig); err == nil { t.Fatal("Should fail because ProxyConfig has no Path") } } -const podID = "123456789" +const sandboxID = "123456789" -func testDefaultProxyURL(expectedURL string, socketType string, podID string) error { - pod := &Pod{ - id: podID, +func testDefaultProxyURL(expectedURL string, socketType string, sandboxID string) error { + sandbox := &Sandbox{ + id: sandboxID, } - url, err := defaultProxyURL(*pod, socketType) + url, err := defaultProxyURL(*sandbox, socketType) if err != nil { return err } @@ -237,25 +237,25 @@ func testDefaultProxyURL(expectedURL string, socketType string, podID string) er } func TestDefaultProxyURLUnix(t *testing.T) { - path := filepath.Join(runStoragePath, podID, "proxy.sock") + path := filepath.Join(runStoragePath, sandboxID, "proxy.sock") socketPath := fmt.Sprintf("unix://%s", path) - if err := testDefaultProxyURL(socketPath, SocketTypeUNIX, podID); err != nil { + if err := testDefaultProxyURL(socketPath, SocketTypeUNIX, sandboxID); err != nil { t.Fatal(err) } } func TestDefaultProxyURLVSock(t *testing.T) { - if err := testDefaultProxyURL("", SocketTypeVSOCK, podID); err != nil { + if err := testDefaultProxyURL("", SocketTypeVSOCK, sandboxID); err != nil { t.Fatal(err) } } func TestDefaultProxyURLUnknown(t *testing.T) { - path := filepath.Join(runStoragePath, podID, "proxy.sock") + path := filepath.Join(runStoragePath, sandboxID, "proxy.sock") socketPath := fmt.Sprintf("unix://%s", path) - if err := testDefaultProxyURL(socketPath, "foobar", podID); err == nil { + if err := testDefaultProxyURL(socketPath, "foobar", sandboxID); err == nil { t.Fatal() } } diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 1eca29740..3fd1cbe06 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -58,7 +58,7 @@ type qemu struct { qemuConfig govmmQemu.Config - pod *Pod + sandbox *Sandbox state QemuState @@ -167,24 +167,24 @@ func (q *qemu) qemuPath() (string, error) { } // init intializes the Qemu structure. -func (q *qemu) init(pod *Pod) error { - valid, err := pod.config.HypervisorConfig.valid() +func (q *qemu) init(sandbox *Sandbox) error { + valid, err := sandbox.config.HypervisorConfig.valid() if valid == false || err != nil { return err } - q.config = pod.config.HypervisorConfig - q.pod = pod + q.config = sandbox.config.HypervisorConfig + q.sandbox = sandbox q.arch = newQemuArch(q.config) - if err = pod.storage.fetchHypervisorState(pod.id, &q.state); err != nil { + if err = sandbox.storage.fetchHypervisorState(sandbox.id, &q.state); err != nil { q.Logger().Debug("Creating bridges") q.state.Bridges = q.arch.bridges(q.config.DefaultBridges) q.Logger().Debug("Creating UUID") q.state.UUID = uuid.Generate().String() - if err = pod.storage.storeHypervisorState(pod.id, q.state); err != nil { + if err = sandbox.storage.storeHypervisorState(sandbox.id, q.state); err != nil { return err } } @@ -208,7 +208,7 @@ func (q *qemu) cpuTopology() govmmQemu.SMP { return q.arch.cpuTopology(q.config.DefaultVCPUs) } -func (q *qemu) memoryTopology(podConfig PodConfig) (govmmQemu.Memory, error) { +func (q *qemu) memoryTopology(sandboxConfig SandboxConfig) (govmmQemu.Memory, error) { hostMemKb, err := getHostMemorySizeKb(procMemInfo) if err != nil { return govmmQemu.Memory{}, fmt.Errorf("Unable to read memory info: %s", err) @@ -220,15 +220,15 @@ func (q *qemu) memoryTopology(podConfig PodConfig) (govmmQemu.Memory, error) { hostMemMb := uint64(float64(hostMemKb / 1024)) memMb := uint64(q.config.DefaultMemSz) - if podConfig.VMConfig.Memory > 0 { - memMb = uint64(podConfig.VMConfig.Memory) + if sandboxConfig.VMConfig.Memory > 0 { + memMb = uint64(sandboxConfig.VMConfig.Memory) } return q.arch.memoryTopology(memMb, hostMemMb), nil } func (q *qemu) qmpSocketPath(socketName string) (string, error) { - parentDirPath := filepath.Join(runStoragePath, q.pod.id) + parentDirPath := filepath.Join(runStoragePath, q.sandbox.id) if len(parentDirPath) > qmpSockPathSizeLimit { return "", fmt.Errorf("Parent directory path %q is too long "+ "(%d characters), could not add any path for the QMP socket", @@ -244,13 +244,13 @@ func (q *qemu) qmpSocketPath(socketName string) (string, error) { return path, nil } -func (q *qemu) getQemuMachine(podConfig PodConfig) (govmmQemu.Machine, error) { +func (q *qemu) getQemuMachine(sandboxConfig SandboxConfig) (govmmQemu.Machine, error) { machine, err := q.arch.machine() if err != nil { return govmmQemu.Machine{}, err } - accelerators := podConfig.HypervisorConfig.MachineAccelerators + accelerators := sandboxConfig.HypervisorConfig.MachineAccelerators if accelerators != "" { if !strings.HasPrefix(accelerators, ",") { accelerators = fmt.Sprintf(",%s", accelerators) @@ -277,18 +277,18 @@ func (q *qemu) appendImage(devices []govmmQemu.Device) ([]govmmQemu.Device, erro return devices, nil } -// createPod is the Hypervisor pod creation implementation for govmmQemu. -func (q *qemu) createPod(podConfig PodConfig) error { +// createSandbox is the Hypervisor sandbox creation implementation for govmmQemu. +func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error { var devices []govmmQemu.Device - machine, err := q.getQemuMachine(podConfig) + machine, err := q.getQemuMachine(sandboxConfig) if err != nil { return err } smp := q.cpuTopology() - memory, err := q.memoryTopology(podConfig) + memory, err := q.memoryTopology(sandboxConfig) if err != nil { return err } @@ -364,8 +364,8 @@ func (q *qemu) createPod(podConfig PodConfig) error { }, } - devices = q.arch.append9PVolumes(devices, podConfig.Volumes) - devices = q.arch.appendConsole(devices, q.getPodConsole(podConfig.ID)) + devices = q.arch.append9PVolumes(devices, sandboxConfig.Volumes) + devices = q.arch.appendConsole(devices, q.getSandboxConsole(sandboxConfig.ID)) if initrdPath == "" { devices, err = q.appendImage(devices) @@ -386,7 +386,7 @@ func (q *qemu) createPod(podConfig PodConfig) error { cpuModel := q.arch.cpuModel() - firmwarePath, err := podConfig.HypervisorConfig.FirmwareAssetPath() + firmwarePath, err := sandboxConfig.HypervisorConfig.FirmwareAssetPath() if err != nil { return err } @@ -397,7 +397,7 @@ func (q *qemu) createPod(podConfig PodConfig) error { } qemuConfig := govmmQemu.Config{ - Name: fmt.Sprintf("pod-%s", podConfig.ID), + Name: fmt.Sprintf("sandbox-%s", sandboxConfig.ID), UUID: q.state.UUID, Path: qemuPath, Ctx: q.qmpMonitorCh.ctx, @@ -424,8 +424,8 @@ func (q *qemu) createPod(podConfig PodConfig) error { return nil } -// startPod will start the Pod's VM. -func (q *qemu) startPod() error { +// startSandbox will start the Sandbox's VM. +func (q *qemu) startSandbox() error { if q.config.Debug { params := q.arch.kernelParameters(q.config.Debug) strParams := SerializeParams(params, "=") @@ -446,8 +446,8 @@ func (q *qemu) startPod() error { return nil } -// waitPod will wait for the Pod's VM to be up and running. -func (q *qemu) waitPod(timeout int) error { +// waitSandbox will wait for the Sandbox's VM to be up and running. +func (q *qemu) waitSandbox(timeout int) error { defer func(qemu *qemu) { if q.qmpMonitorCh.qmp != nil { q.qmpMonitorCh.qmp.Shutdown() @@ -496,12 +496,12 @@ func (q *qemu) waitPod(timeout int) error { return nil } -// stopPod will stop the Pod's VM. -func (q *qemu) stopPod() error { +// stopSandbox will stop the Sandbox's VM. +func (q *qemu) stopSandbox() error { cfg := govmmQemu.QMPConfig{Logger: newQMPLogger()} disconnectCh := make(chan struct{}) - q.Logger().Info("Stopping Pod") + q.Logger().Info("Stopping Sandbox") qmp, _, err := govmmQemu.QMPStart(q.qmpControlCh.ctx, q.qmpControlCh.path, cfg, disconnectCh) if err != nil { q.Logger().WithError(err).Error("Failed to connect to QEMU instance") @@ -517,7 +517,7 @@ func (q *qemu) stopPod() error { return qmp.ExecuteQuit(q.qmpMonitorCh.ctx) } -func (q *qemu) togglePausePod(pause bool) error { +func (q *qemu) togglePauseSandbox(pause bool) error { defer func(qemu *qemu) { if q.qmpMonitorCh.qmp != nil { q.qmpMonitorCh.qmp.Shutdown() @@ -730,7 +730,7 @@ func (q *qemu) hotplugAddDevice(devInfo interface{}, devType deviceType) error { return err } - return q.pod.storage.storeHypervisorState(q.pod.id, q.state) + return q.sandbox.storage.storeHypervisorState(q.sandbox.id, q.state) } func (q *qemu) hotplugRemoveDevice(devInfo interface{}, devType deviceType) error { @@ -738,7 +738,7 @@ func (q *qemu) hotplugRemoveDevice(devInfo interface{}, devType deviceType) erro return err } - return q.pod.storage.storeHypervisorState(q.pod.id, q.state) + return q.sandbox.storage.storeHypervisorState(q.sandbox.id, q.state) } func (q *qemu) hotplugCPUs(vcpus uint32, op operation) error { @@ -772,7 +772,7 @@ func (q *qemu) hotplugAddCPUs(amount uint32) error { // Don't exceed the maximum amount of vCPUs if currentVCPUs+amount > q.config.DefaultMaxVCPUs { - return fmt.Errorf("Unable to hotplug %d CPUs, currently this POD has %d CPUs and the maximum amount of CPUs is %d", + return fmt.Errorf("Unable to hotplug %d CPUs, currently this SB has %d CPUs and the maximum amount of CPUs is %d", amount, currentVCPUs, q.config.DefaultMaxVCPUs) } @@ -805,12 +805,12 @@ func (q *qemu) hotplugAddCPUs(amount uint32) error { hotpluggedVCPUs++ if hotpluggedVCPUs == amount { // All vCPUs were hotplugged - return q.pod.storage.storeHypervisorState(q.pod.id, q.state) + return q.sandbox.storage.storeHypervisorState(q.sandbox.id, q.state) } } // All vCPUs were NOT hotplugged - if err := q.pod.storage.storeHypervisorState(q.pod.id, q.state); err != nil { + if err := q.sandbox.storage.storeHypervisorState(q.sandbox.id, q.state); err != nil { q.Logger().Errorf("failed to save hypervisor state after hotplug %d vCPUs: %v", hotpluggedVCPUs, err) } @@ -836,15 +836,15 @@ func (q *qemu) hotplugRemoveCPUs(amount uint32) error { q.state.HotpluggedVCPUs = q.state.HotpluggedVCPUs[:len(q.state.HotpluggedVCPUs)-1] } - return q.pod.storage.storeHypervisorState(q.pod.id, q.state) + return q.sandbox.storage.storeHypervisorState(q.sandbox.id, q.state) } -func (q *qemu) pausePod() error { - return q.togglePausePod(true) +func (q *qemu) pauseSandbox() error { + return q.togglePauseSandbox(true) } -func (q *qemu) resumePod() error { - return q.togglePausePod(false) +func (q *qemu) resumeSandbox() error { + return q.togglePauseSandbox(false) } // addDevice will add extra devices to Qemu command line. @@ -875,8 +875,8 @@ func (q *qemu) addDevice(devInfo interface{}, devType deviceType) error { return nil } -// getPodConsole builds the path of the console where we can read -// logs coming from the pod. -func (q *qemu) getPodConsole(podID string) string { - return filepath.Join(runStoragePath, podID, defaultConsole) +// getSandboxConsole builds the path of the console where we can read +// logs coming from the sandbox. +func (q *qemu) getSandboxConsole(sandboxID string) string { + return filepath.Join(runStoragePath, sandboxID, defaultConsole) } diff --git a/virtcontainers/qemu_arch_base_test.go b/virtcontainers/qemu_arch_base_test.go index 14b4b9f7f..9774d2a4b 100644 --- a/virtcontainers/qemu_arch_base_test.go +++ b/virtcontainers/qemu_arch_base_test.go @@ -269,7 +269,7 @@ func TestQemuArchBaseAppendConsoles(t *testing.T) { assert := assert.New(t) qemuArchBase := newQemuArchBase() - path := filepath.Join(runStoragePath, podID, defaultConsole) + path := filepath.Join(runStoragePath, sandboxID, defaultConsole) expectedOut := []govmmQemu.Device{ govmmQemu.SerialDevice{ diff --git a/virtcontainers/qemu_test.go b/virtcontainers/qemu_test.go index dac4dd4bb..3670f1c62 100644 --- a/virtcontainers/qemu_test.go +++ b/virtcontainers/qemu_test.go @@ -82,21 +82,21 @@ func TestQemuInit(t *testing.T) { qemuConfig := newQemuConfig() q := &qemu{} - pod := &Pod{ - id: "testPod", + sandbox := &Sandbox{ + id: "testSandbox", storage: &filesystem{}, - config: &PodConfig{ + config: &SandboxConfig{ HypervisorConfig: qemuConfig, }, } // Create parent dir path for hypervisor.json - parentDir := filepath.Join(runStoragePath, pod.id) + parentDir := filepath.Join(runStoragePath, sandbox.id) if err := os.MkdirAll(parentDir, dirMode); err != nil { t.Fatalf("Could not create parent directory %s: %v", parentDir, err) } - if err := q.init(pod); err != nil { + if err := q.init(sandbox); err != nil { t.Fatal(err) } @@ -113,21 +113,21 @@ func TestQemuInitMissingParentDirFail(t *testing.T) { qemuConfig := newQemuConfig() q := &qemu{} - pod := &Pod{ - id: "testPod", + sandbox := &Sandbox{ + id: "testSandbox", storage: &filesystem{}, - config: &PodConfig{ + config: &SandboxConfig{ HypervisorConfig: qemuConfig, }, } // Ensure parent dir path for hypervisor.json does not exist. - parentDir := filepath.Join(runStoragePath, pod.id) + parentDir := filepath.Join(runStoragePath, sandbox.id) if err := os.RemoveAll(parentDir); err != nil { t.Fatal(err) } - if err := q.init(pod); err == nil { + if err := q.init(sandbox); err == nil { t.Fatal("Qemu init() expected to fail because of missing parent directory for storage") } } @@ -180,11 +180,11 @@ func TestQemuMemoryTopology(t *testing.T) { Memory: uint(mem), } - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ VMConfig: vmConfig, } - memory, err := q.memoryTopology(podConfig) + memory, err := q.memoryTopology(sandboxConfig) if err != nil { t.Fatal(err) } @@ -259,12 +259,12 @@ func TestQemuAddDeviceSerialPortDev(t *testing.T) { testQemuAddDevice(t, socket, serialPortDev, expectedOut) } -func TestQemuGetPodConsole(t *testing.T) { +func TestQemuGetSandboxConsole(t *testing.T) { q := &qemu{} - podID := "testPodID" - expected := filepath.Join(runStoragePath, podID, defaultConsole) + sandboxID := "testSandboxID" + expected := filepath.Join(runStoragePath, sandboxID, defaultConsole) - if result := q.getPodConsole(podID); result != expected { + if result := q.getSandboxConsole(sandboxID); result != expected { t.Fatalf("Got %s\nExpecting %s", result, expected) } } diff --git a/virtcontainers/pod.go b/virtcontainers/sandbox.go similarity index 65% rename from virtcontainers/pod.go rename to virtcontainers/sandbox.go index 6055d7a7c..96fd0f9d7 100644 --- a/virtcontainers/pod.go +++ b/virtcontainers/sandbox.go @@ -27,39 +27,39 @@ import ( "github.com/sirupsen/logrus" ) -// controlSocket is the pod control socket. +// controlSocket is the sandbox control socket. // It is an hypervisor resource, and for example qemu's control // socket is the QMP one. const controlSocket = "ctl" -// monitorSocket is the pod monitoring socket. +// monitorSocket is the sandbox monitoring socket. // It is an hypervisor resource, and is a qmp socket in the qemu case. // This is a socket that any monitoring entity will listen to in order // to understand if the VM is still alive or not. const monitorSocket = "mon" -// vmStartTimeout represents the time in seconds a pod can wait before +// vmStartTimeout represents the time in seconds a sandbox can wait before // to consider the VM starting operation failed. const vmStartTimeout = 10 -// stateString is a string representing a pod state. +// stateString is a string representing a sandbox state. type stateString string const ( - // StateReady represents a pod/container that's ready to be run + // StateReady represents a sandbox/container that's ready to be run StateReady stateString = "ready" - // StateRunning represents a pod/container that's currently running. + // StateRunning represents a sandbox/container that's currently running. StateRunning stateString = "running" - // StatePaused represents a pod/container that has been paused. + // StatePaused represents a sandbox/container that has been paused. StatePaused stateString = "paused" - // StateStopped represents a pod/container that has been stopped. + // StateStopped represents a sandbox/container that has been stopped. StateStopped stateString = "stopped" ) -// State is a pod state structure. +// State is a sandbox state structure. type State struct { State stateString `json:"state"` @@ -73,7 +73,7 @@ type State struct { HotpluggedDrive bool `json:"hotpluggedDrive"` } -// valid checks that the pod state is valid. +// valid checks that the sandbox state is valid. func (state *State) valid() bool { for _, validState := range []stateString{StateReady, StateRunning, StatePaused, StateStopped} { if state.State == validState { @@ -317,8 +317,8 @@ type Resources struct { Memory uint } -// PodStatus describes a pod status. -type PodStatus struct { +// SandboxStatus describes a sandbox status. +type SandboxStatus struct { ID string State State Hypervisor HypervisorType @@ -332,8 +332,8 @@ type PodStatus struct { Annotations map[string]string } -// PodConfig is a Pod configuration. -type PodConfig struct { +// SandboxConfig is a Sandbox configuration. +type SandboxConfig struct { ID string Hostname string @@ -341,7 +341,7 @@ type PodConfig struct { // Field specific to OCI specs, needed to setup all the hooks Hooks Hooks - // VMConfig is the VM configuration to set for this pod. + // VMConfig is the VM configuration to set for this sandbox. VMConfig Resources HypervisorType HypervisorType @@ -359,12 +359,12 @@ type PodConfig struct { NetworkModel NetworkModel NetworkConfig NetworkConfig - // Volumes is a list of shared volumes between the host and the Pod. + // Volumes is a list of shared volumes between the host and the Sandbox. Volumes []Volume - // Containers describe the list of containers within a Pod. + // Containers describe the list of containers within a Sandbox. // This list can be empty and populated by adding containers - // to the Pod a posteriori. + // to the Sandbox a posteriori. Containers []ContainerConfig // Annotations keys must be unique strings and must be name-spaced @@ -372,14 +372,14 @@ type PodConfig struct { Annotations map[string]string } -// valid checks that the pod configuration is valid. -func (podConfig *PodConfig) valid() bool { - if podConfig.ID == "" { +// valid checks that the sandbox configuration is valid. +func (sandboxConfig *SandboxConfig) valid() bool { + if sandboxConfig.ID == "" { return false } - if _, err := newHypervisor(podConfig.HypervisorType); err != nil { - podConfig.HypervisorType = QemuHypervisor + if _, err := newHypervisor(sandboxConfig.HypervisorType); err != nil { + sandboxConfig.HypervisorType = QemuHypervisor } return true @@ -393,29 +393,29 @@ const ( sharedLock = syscall.LOCK_SH ) -// rLockPod locks the pod with a shared lock. -func rLockPod(podID string) (*os.File, error) { - return lockPod(podID, sharedLock) +// rLockSandbox locks the sandbox with a shared lock. +func rLockSandbox(sandboxID string) (*os.File, error) { + return lockSandbox(sandboxID, sharedLock) } -// rwLockPod locks the pod with an exclusive lock. -func rwLockPod(podID string) (*os.File, error) { - return lockPod(podID, exclusiveLock) +// rwLockSandbox locks the sandbox with an exclusive lock. +func rwLockSandbox(sandboxID string) (*os.File, error) { + return lockSandbox(sandboxID, exclusiveLock) } -// lock locks any pod to prevent it from being accessed by other processes. -func lockPod(podID string, lockType int) (*os.File, error) { - if podID == "" { - return nil, errNeedPodID +// lock locks any sandbox to prevent it from being accessed by other processes. +func lockSandbox(sandboxID string, lockType int) (*os.File, error) { + if sandboxID == "" { + return nil, errNeedSandboxID } fs := filesystem{} - podlockFile, _, err := fs.podURI(podID, lockFileType) + sandboxlockFile, _, err := fs.sandboxURI(sandboxID, lockFileType) if err != nil { return nil, err } - lockFile, err := os.Open(podlockFile) + lockFile, err := os.Open(sandboxlockFile) if err != nil { return nil, err } @@ -427,8 +427,8 @@ func lockPod(podID string, lockType int) (*os.File, error) { return lockFile, nil } -// unlock unlocks any pod to allow it being accessed by other processes. -func unlockPod(lockFile *os.File) error { +// unlock unlocks any sandbox to allow it being accessed by other processes. +func unlockSandbox(lockFile *os.File) error { if lockFile == nil { return fmt.Errorf("lockFile cannot be empty") } @@ -443,9 +443,9 @@ func unlockPod(lockFile *os.File) error { return nil } -// Pod is composed of a set of containers and a runtime environment. -// A Pod can be created, deleted, started, paused, stopped, listed, entered, and restored. -type Pod struct { +// Sandbox is composed of a set of containers and a runtime environment. +// A Sandbox can be created, deleted, started, paused, stopped, listed, entered, and restored. +type Sandbox struct { id string hypervisor hypervisor @@ -453,7 +453,7 @@ type Pod struct { storage resourceStorage network network - config *PodConfig + config *SandboxConfig volumes []Volume @@ -471,21 +471,21 @@ type Pod struct { wg *sync.WaitGroup } -// ID returns the pod identifier string. -func (p *Pod) ID() string { +// ID returns the sandbox identifier string. +func (p *Sandbox) ID() string { return p.id } -// Logger returns a logrus logger appropriate for logging Pod messages -func (p *Pod) Logger() *logrus.Entry { +// Logger returns a logrus logger appropriate for logging Sandbox messages +func (p *Sandbox) Logger() *logrus.Entry { return virtLog.WithFields(logrus.Fields{ - "subsystem": "pod", - "pod-id": p.id, + "subsystem": "sandbox", + "sandbox-id": p.id, }) } -// Annotations returns any annotation that a user could have stored through the pod. -func (p *Pod) Annotations(key string) (string, error) { +// Annotations returns any annotation that a user could have stored through the sandbox. +func (p *Sandbox) Annotations(key string) (string, error) { value, exist := p.config.Annotations[key] if exist == false { return "", fmt.Errorf("Annotations key %s does not exist", key) @@ -495,7 +495,7 @@ func (p *Pod) Annotations(key string) (string, error) { } // SetAnnotations sets or adds an annotations -func (p *Pod) SetAnnotations(annotations map[string]string) error { +func (p *Sandbox) SetAnnotations(annotations map[string]string) error { p.annotationsLock.Lock() defer p.annotationsLock.Unlock() @@ -503,7 +503,7 @@ func (p *Pod) SetAnnotations(annotations map[string]string) error { p.config.Annotations[k] = v } - err := p.storage.storePodResource(p.id, configFileType, *(p.config)) + err := p.storage.storeSandboxResource(p.id, configFileType, *(p.config)) if err != nil { return err } @@ -511,8 +511,8 @@ func (p *Pod) SetAnnotations(annotations map[string]string) error { return nil } -// GetAnnotations returns pod's annotations -func (p *Pod) GetAnnotations() map[string]string { +// GetAnnotations returns sandbox's annotations +func (p *Sandbox) GetAnnotations() map[string]string { p.annotationsLock.RLock() defer p.annotationsLock.RUnlock() @@ -520,7 +520,7 @@ func (p *Pod) GetAnnotations() map[string]string { } // GetAllContainers returns all containers. -func (p *Pod) GetAllContainers() []VCContainer { +func (p *Sandbox) GetAllContainers() []VCContainer { ifa := make([]VCContainer, len(p.containers)) for i, v := range p.containers { @@ -531,7 +531,7 @@ func (p *Pod) GetAllContainers() []VCContainer { } // GetContainer returns the container named by the containerID. -func (p *Pod) GetContainer(containerID string) VCContainer { +func (p *Sandbox) GetContainer(containerID string) VCContainer { for _, c := range p.containers { if c.id == containerID { return c @@ -540,18 +540,18 @@ func (p *Pod) GetContainer(containerID string) VCContainer { return nil } -func createAssets(podConfig *PodConfig) error { - kernel, err := newAsset(podConfig, kernelAsset) +func createAssets(sandboxConfig *SandboxConfig) error { + kernel, err := newAsset(sandboxConfig, kernelAsset) if err != nil { return err } - image, err := newAsset(podConfig, imageAsset) + image, err := newAsset(sandboxConfig, imageAsset) if err != nil { return err } - initrd, err := newAsset(podConfig, initrdAsset) + initrd, err := newAsset(sandboxConfig, initrdAsset) if err != nil { return err } @@ -561,7 +561,7 @@ func createAssets(podConfig *PodConfig) error { } for _, a := range []*asset{kernel, image, initrd} { - if err := podConfig.HypervisorConfig.addCustomAsset(a); err != nil { + if err := sandboxConfig.HypervisorConfig.addCustomAsset(a); err != nil { return err } } @@ -569,87 +569,87 @@ func createAssets(podConfig *PodConfig) error { return nil } -// createPod creates a pod from a pod description, the containers list, the hypervisor +// createSandbox creates a sandbox from a sandbox description, the containers list, the hypervisor // and the agent passed through the Config structure. -// It will create and store the pod structure, and then ask the hypervisor -// to physically create that pod i.e. starts a VM for that pod to eventually +// It will create and store the sandbox structure, and then ask the hypervisor +// to physically create that sandbox i.e. starts a VM for that sandbox to eventually // be started. -func createPod(podConfig PodConfig) (*Pod, error) { - if err := createAssets(&podConfig); err != nil { +func createSandbox(sandboxConfig SandboxConfig) (*Sandbox, error) { + if err := createAssets(&sandboxConfig); err != nil { return nil, err } - p, err := newPod(podConfig) + p, err := newSandbox(sandboxConfig) if err != nil { return nil, err } - // Fetch pod network to be able to access it from the pod structure. - networkNS, err := p.storage.fetchPodNetwork(p.id) + // Fetch sandbox network to be able to access it from the sandbox structure. + networkNS, err := p.storage.fetchSandboxNetwork(p.id) if err == nil { p.networkNS = networkNS } - // We first try to fetch the pod state from storage. + // We first try to fetch the sandbox state from storage. // If it exists, this means this is a re-creation, i.e. // we don't need to talk to the guest's agent, but only - // want to create the pod and its containers in memory. - state, err := p.storage.fetchPodState(p.id) + // want to create the sandbox and its containers in memory. + state, err := p.storage.fetchSandboxState(p.id) if err == nil && state.State != "" { p.state = state return p, nil } // Below code path is called only during create, because of earlier check. - if err := p.agent.createPod(p); err != nil { + if err := p.agent.createSandbox(p); err != nil { return nil, err } - // Set pod state - if err := p.setPodState(StateReady); err != nil { + // Set sandbox state + if err := p.setSandboxState(StateReady); err != nil { return nil, err } return p, nil } -func newPod(podConfig PodConfig) (*Pod, error) { - if podConfig.valid() == false { - return nil, fmt.Errorf("Invalid pod configuration") +func newSandbox(sandboxConfig SandboxConfig) (*Sandbox, error) { + if sandboxConfig.valid() == false { + return nil, fmt.Errorf("Invalid sandbox configuration") } - agent := newAgent(podConfig.AgentType) + agent := newAgent(sandboxConfig.AgentType) - hypervisor, err := newHypervisor(podConfig.HypervisorType) + hypervisor, err := newHypervisor(sandboxConfig.HypervisorType) if err != nil { return nil, err } - network := newNetwork(podConfig.NetworkModel) + network := newNetwork(sandboxConfig.NetworkModel) - p := &Pod{ - id: podConfig.ID, + p := &Sandbox{ + id: sandboxConfig.ID, hypervisor: hypervisor, agent: agent, storage: &filesystem{}, network: network, - config: &podConfig, - volumes: podConfig.Volumes, - runPath: filepath.Join(runStoragePath, podConfig.ID), - configPath: filepath.Join(configStoragePath, podConfig.ID), + config: &sandboxConfig, + volumes: sandboxConfig.Volumes, + runPath: filepath.Join(runStoragePath, sandboxConfig.ID), + configPath: filepath.Join(configStoragePath, sandboxConfig.ID), state: State{}, annotationsLock: &sync.RWMutex{}, wg: &sync.WaitGroup{}, } - if err = globalPodList.addPod(p); err != nil { + if err = globalSandboxList.addSandbox(p); err != nil { return nil, err } defer func() { if err != nil { - p.Logger().WithError(err).WithField("podid", p.id).Error("Create new pod failed") - globalPodList.removePod(p.id) + p.Logger().WithError(err).WithField("sandboxid", p.id).Error("Create new sandbox failed") + globalSandboxList.removeSandbox(p.id) } }() @@ -659,7 +659,7 @@ func newPod(podConfig PodConfig) (*Pod, error) { defer func() { if err != nil { - p.storage.deletePodResources(p.id, nil) + p.storage.deleteSandboxResources(p.id, nil) } }() @@ -667,11 +667,11 @@ func newPod(podConfig PodConfig) (*Pod, error) { return nil, err } - if err = p.hypervisor.createPod(podConfig); err != nil { + if err = p.hypervisor.createSandbox(sandboxConfig); err != nil { return nil, err } - agentConfig := newAgentConfig(podConfig) + agentConfig := newAgentConfig(sandboxConfig) if err = p.agent.init(p, agentConfig); err != nil { return nil, err } @@ -679,9 +679,9 @@ func newPod(podConfig PodConfig) (*Pod, error) { return p, nil } -// storePod stores a pod config. -func (p *Pod) storePod() error { - err := p.storage.storePodResource(p.id, configFileType, *(p.config)) +// storeSandbox stores a sandbox config. +func (p *Sandbox) storeSandbox() error { + err := p.storage.storeSandboxResource(p.id, configFileType, *(p.config)) if err != nil { return err } @@ -696,42 +696,42 @@ func (p *Pod) storePod() error { return nil } -// fetchPod fetches a pod config from a pod ID and returns a pod. -func fetchPod(podID string) (pod *Pod, err error) { - if podID == "" { - return nil, errNeedPodID +// fetchSandbox fetches a sandbox config from a sandbox ID and returns a sandbox. +func fetchSandbox(sandboxID string) (sandbox *Sandbox, err error) { + if sandboxID == "" { + return nil, errNeedSandboxID } - pod, err = globalPodList.lookupPod(podID) - if pod != nil && err == nil { - return pod, err + sandbox, err = globalSandboxList.lookupSandbox(sandboxID) + if sandbox != nil && err == nil { + return sandbox, err } fs := filesystem{} - config, err := fs.fetchPodConfig(podID) + config, err := fs.fetchSandboxConfig(sandboxID) if err != nil { return nil, err } - pod, err = createPod(config) + sandbox, err = createSandbox(config) if err != nil { - return nil, fmt.Errorf("failed to create pod with config %+v: %v", config, err) + return nil, fmt.Errorf("failed to create sandbox with config %+v: %v", config, err) } - // This pod already exists, we don't need to recreate the containers in the guest. + // This sandbox already exists, we don't need to recreate the containers in the guest. // We only need to fetch the containers from storage and create the container structs. - if err := pod.newContainers(); err != nil { + if err := sandbox.newContainers(); err != nil { return nil, err } - return pod, nil + return sandbox, nil } // findContainer returns a container from the containers list held by the -// pod structure, based on a container ID. -func (p *Pod) findContainer(containerID string) (*Container, error) { +// sandbox structure, based on a container ID. +func (p *Sandbox) findContainer(containerID string) (*Container, error) { if p == nil { - return nil, errNeedPod + return nil, errNeedSandbox } if containerID == "" { @@ -744,15 +744,15 @@ func (p *Pod) findContainer(containerID string) (*Container, error) { } } - return nil, fmt.Errorf("Could not find the container %q from the pod %q containers list", + return nil, fmt.Errorf("Could not find the container %q from the sandbox %q containers list", containerID, p.id) } // removeContainer removes a container from the containers list held by the -// pod structure, based on a container ID. -func (p *Pod) removeContainer(containerID string) error { +// sandbox structure, based on a container ID. +func (p *Sandbox) removeContainer(containerID string) error { if p == nil { - return errNeedPod + return errNeedSandbox } if containerID == "" { @@ -766,17 +766,17 @@ func (p *Pod) removeContainer(containerID string) error { } } - return fmt.Errorf("Could not remove the container %q from the pod %q containers list", + return fmt.Errorf("Could not remove the container %q from the sandbox %q containers list", containerID, p.id) } -// delete deletes an already created pod. -// The VM in which the pod is running will be shut down. -func (p *Pod) delete() error { +// delete deletes an already created sandbox. +// The VM in which the sandbox is running will be shut down. +func (p *Sandbox) delete() error { if p.state.State != StateReady && p.state.State != StatePaused && p.state.State != StateStopped { - return fmt.Errorf("Pod not ready, paused or stopped, impossible to delete") + return fmt.Errorf("Sandbox not ready, paused or stopped, impossible to delete") } for _, c := range p.containers { @@ -785,12 +785,12 @@ func (p *Pod) delete() error { } } - globalPodList.removePod(p.id) + globalSandboxList.removeSandbox(p.id) - return p.storage.deletePodResources(p.id, nil) + return p.storage.deleteSandboxResources(p.id, nil) } -func (p *Pod) createNetwork() error { +func (p *Sandbox) createNetwork() error { // Initialize the network. netNsPath, netNsCreated, err := p.network.init(p.config.NetworkConfig) if err != nil { @@ -812,10 +812,10 @@ func (p *Pod) createNetwork() error { p.networkNS = networkNS // Store the network - return p.storage.storePodNetwork(p.id, networkNS) + return p.storage.storeSandboxNetwork(p.id, networkNS) } -func (p *Pod) removeNetwork() error { +func (p *Sandbox) removeNetwork() error { if p.networkNS.NetNsCreated { return p.network.remove(*p, p.networkNS) } @@ -824,38 +824,38 @@ func (p *Pod) removeNetwork() error { } // startVM starts the VM. -func (p *Pod) startVM() error { +func (p *Sandbox) startVM() error { p.Logger().Info("Starting VM") if err := p.network.run(p.networkNS.NetNsPath, func() error { - return p.hypervisor.startPod() + return p.hypervisor.startSandbox() }); err != nil { return err } - if err := p.hypervisor.waitPod(vmStartTimeout); err != nil { + if err := p.hypervisor.waitSandbox(vmStartTimeout); err != nil { return err } p.Logger().Info("VM started") // Once startVM is done, we want to guarantee - // that the pod is manageable. For that we need - // to start the pod inside the VM. - return p.agent.startPod(*p) + // that the sandbox is manageable. For that we need + // to start the sandbox inside the VM. + return p.agent.startSandbox(*p) } -func (p *Pod) addContainer(c *Container) error { +func (p *Sandbox) addContainer(c *Container) error { p.containers = append(p.containers, c) return nil } // newContainers creates new containers structure and -// adds them to the pod. It does not create the containers +// adds them to the sandbox. It does not create the containers // in the guest. This should only be used when fetching a -// pod that already exists. -func (p *Pod) newContainers() error { +// sandbox that already exists. +func (p *Sandbox) newContainers() error { for _, contConfig := range p.config.Containers { c, err := newContainer(p, contConfig) if err != nil { @@ -872,7 +872,7 @@ func (p *Pod) newContainers() error { // createContainers registers all containers to the proxy, create the // containers in the guest and starts one shim per container. -func (p *Pod) createContainers() error { +func (p *Sandbox) createContainers() error { for _, contConfig := range p.config.Containers { newContainer, err := createContainer(p, contConfig) if err != nil { @@ -887,14 +887,14 @@ func (p *Pod) createContainers() error { return nil } -// start starts a pod. The containers that are making the pod +// start starts a sandbox. The containers that are making the sandbox // will be started. -func (p *Pod) start() error { +func (p *Sandbox) start() error { if err := p.state.validTransition(p.state.State, StateRunning); err != nil { return err } - if err := p.setPodState(StateRunning); err != nil { + if err := p.setSandboxState(StateRunning); err != nil { return err } @@ -904,14 +904,14 @@ func (p *Pod) start() error { } } - p.Logger().Info("Pod is started") + p.Logger().Info("Sandbox is started") return nil } -// stop stops a pod. The containers that are making the pod +// stop stops a sandbox. The containers that are making the sandbox // will be destroyed. -func (p *Pod) stop() error { +func (p *Sandbox) stop() error { if err := p.state.validTransition(p.state.State, StateStopped); err != nil { return err } @@ -922,47 +922,47 @@ func (p *Pod) stop() error { } } - if err := p.agent.stopPod(*p); err != nil { + if err := p.agent.stopSandbox(*p); err != nil { return err } p.Logger().Info("Stopping VM") - if err := p.hypervisor.stopPod(); err != nil { + if err := p.hypervisor.stopSandbox(); err != nil { return err } - return p.setPodState(StateStopped) + return p.setSandboxState(StateStopped) } -func (p *Pod) pause() error { - if err := p.hypervisor.pausePod(); err != nil { +func (p *Sandbox) pause() error { + if err := p.hypervisor.pauseSandbox(); err != nil { return err } return p.pauseSetStates() } -func (p *Pod) resume() error { - if err := p.hypervisor.resumePod(); err != nil { +func (p *Sandbox) resume() error { + if err := p.hypervisor.resumeSandbox(); err != nil { return err } return p.resumeSetStates() } -// list lists all pod running on the host. -func (p *Pod) list() ([]Pod, error) { +// list lists all sandbox running on the host. +func (p *Sandbox) list() ([]Sandbox, error) { return nil, nil } -// enter runs an executable within a pod. -func (p *Pod) enter(args []string) error { +// enter runs an executable within a sandbox. +func (p *Sandbox) enter(args []string) error { return nil } -// setPodState sets both the in-memory and on-disk state of the -// pod. -func (p *Pod) setPodState(state stateString) error { +// setSandboxState sets both the in-memory and on-disk state of the +// sandbox. +func (p *Sandbox) setSandboxState(state stateString) error { if state == "" { return errNeedState } @@ -971,40 +971,40 @@ func (p *Pod) setPodState(state stateString) error { p.state.State = state // update on-disk state - return p.storage.storePodResource(p.id, stateFileType, p.state) + return p.storage.storeSandboxResource(p.id, stateFileType, p.state) } -func (p *Pod) pauseSetStates() error { - // XXX: When a pod is paused, all its containers are forcibly +func (p *Sandbox) pauseSetStates() error { + // XXX: When a sandbox is paused, all its containers are forcibly // paused too. if err := p.setContainersState(StatePaused); err != nil { return err } - return p.setPodState(StatePaused) + return p.setSandboxState(StatePaused) } -func (p *Pod) resumeSetStates() error { - // XXX: Resuming a paused pod puts all containers back into the +func (p *Sandbox) resumeSetStates() error { + // XXX: Resuming a paused sandbox puts all containers back into the // running state. if err := p.setContainersState(StateRunning); err != nil { return err } - return p.setPodState(StateRunning) + return p.setSandboxState(StateRunning) } -// getAndSetPodBlockIndex retrieves pod block index and increments it for +// getAndSetSandboxBlockIndex retrieves sandbox block index and increments it for // subsequent accesses. This index is used to maintain the index at which a -// block device is assigned to a container in the pod. -func (p *Pod) getAndSetPodBlockIndex() (int, error) { +// block device is assigned to a container in the sandbox. +func (p *Sandbox) getAndSetSandboxBlockIndex() (int, error) { currentIndex := p.state.BlockIndex // Increment so that container gets incremented block index p.state.BlockIndex++ // update on-disk state - err := p.storage.storePodResource(p.id, stateFileType, p.state) + err := p.storage.storeSandboxResource(p.id, stateFileType, p.state) if err != nil { return -1, err } @@ -1012,13 +1012,13 @@ func (p *Pod) getAndSetPodBlockIndex() (int, error) { return currentIndex, nil } -// decrementPodBlockIndex decrements the current pod block index. +// decrementSandboxBlockIndex decrements the current sandbox block index. // This is used to recover from failure while adding a block device. -func (p *Pod) decrementPodBlockIndex() error { +func (p *Sandbox) decrementSandboxBlockIndex() error { p.state.BlockIndex-- // update on-disk state - err := p.storage.storePodResource(p.id, stateFileType, p.state) + err := p.storage.storeSandboxResource(p.id, stateFileType, p.state) if err != nil { return err } @@ -1026,7 +1026,7 @@ func (p *Pod) decrementPodBlockIndex() error { return nil } -func (p *Pod) setContainersState(state stateString) error { +func (p *Sandbox) setContainersState(state stateString) error { if state == "" { return errNeedState } @@ -1040,12 +1040,12 @@ func (p *Pod) setContainersState(state stateString) error { return nil } -func (p *Pod) deleteContainerState(containerID string) error { +func (p *Sandbox) deleteContainerState(containerID string) error { if containerID == "" { return errNeedContainerID } - err := p.storage.deleteContainerResources(p.id, containerID, []podResource{stateFileType}) + err := p.storage.deleteContainerResources(p.id, containerID, []sandboxResource{stateFileType}) if err != nil { return err } @@ -1053,7 +1053,7 @@ func (p *Pod) deleteContainerState(containerID string) error { return nil } -func (p *Pod) deleteContainersState() error { +func (p *Sandbox) deleteContainersState() error { for _, container := range p.config.Containers { err := p.deleteContainerState(container.ID) if err != nil { @@ -1064,21 +1064,21 @@ func (p *Pod) deleteContainersState() error { return nil } -// togglePausePod pauses a pod if pause is set to true, else it resumes +// togglePauseSandbox pauses a sandbox if pause is set to true, else it resumes // it. -func togglePausePod(podID string, pause bool) (*Pod, error) { - if podID == "" { - return nil, errNeedPod +func togglePauseSandbox(sandboxID string, pause bool) (*Sandbox, error) { + if sandboxID == "" { + return nil, errNeedSandbox } - lockFile, err := rwLockPod(podID) + lockFile, err := rwLockSandbox(sandboxID) if err != nil { return nil, err } - defer unlockPod(lockFile) + defer unlockSandbox(lockFile) - // Fetch the pod from storage and create it. - p, err := fetchPod(podID) + // Fetch the sandbox from storage and create it. + p, err := fetchSandbox(sandboxID) if err != nil { return nil, err } diff --git a/virtcontainers/pod_test.go b/virtcontainers/sandbox_test.go similarity index 63% rename from virtcontainers/pod_test.go rename to virtcontainers/sandbox_test.go index 17229527c..be36b40ac 100644 --- a/virtcontainers/pod_test.go +++ b/virtcontainers/sandbox_test.go @@ -41,12 +41,12 @@ func newHypervisorConfig(kernelParams []Param, hParams []Param) HypervisorConfig } -func testCreatePod(t *testing.T, id string, +func testCreateSandbox(t *testing.T, id string, htype HypervisorType, hconfig HypervisorConfig, atype AgentType, nmodel NetworkModel, nconfig NetworkConfig, containers []ContainerConfig, - volumes []Volume) (*Pod, error) { + volumes []Volume) (*Sandbox, error) { - config := PodConfig{ + config := SandboxConfig{ ID: id, HypervisorType: htype, HypervisorConfig: hconfig, @@ -57,70 +57,70 @@ func testCreatePod(t *testing.T, id string, Containers: containers, } - pod, err := createPod(config) + sandbox, err := createSandbox(config) if err != nil { - return nil, fmt.Errorf("Could not create pod: %s", err) + return nil, fmt.Errorf("Could not create sandbox: %s", err) } - if err := pod.agent.startPod(*pod); err != nil { + if err := sandbox.agent.startSandbox(*sandbox); err != nil { return nil, err } - if err := pod.createContainers(); err != nil { + if err := sandbox.createContainers(); err != nil { return nil, err } - if pod.id == "" { - return pod, fmt.Errorf("Invalid empty pod ID") + if sandbox.id == "" { + return sandbox, fmt.Errorf("Invalid empty sandbox ID") } - if id != "" && pod.id != id { - return pod, fmt.Errorf("Invalid ID %s vs %s", id, pod.id) + if id != "" && sandbox.id != id { + return sandbox, fmt.Errorf("Invalid ID %s vs %s", id, sandbox.id) } - return pod, nil + return sandbox, nil } -func TestCreateEmtpyPod(t *testing.T) { - _, err := testCreatePod(t, testPodID, MockHypervisor, HypervisorConfig{}, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) +func TestCreateEmtpySandbox(t *testing.T) { + _, err := testCreateSandbox(t, testSandboxID, MockHypervisor, HypervisorConfig{}, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) if err == nil { - t.Fatalf("VirtContainers should not allow empty pods") + t.Fatalf("VirtContainers should not allow empty sandboxes") } defer cleanUp() } -func TestCreateEmtpyHypervisorPod(t *testing.T) { - _, err := testCreatePod(t, testPodID, QemuHypervisor, HypervisorConfig{}, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) +func TestCreateEmtpyHypervisorSandbox(t *testing.T) { + _, err := testCreateSandbox(t, testSandboxID, QemuHypervisor, HypervisorConfig{}, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) if err == nil { - t.Fatalf("VirtContainers should not allow pods with empty hypervisors") + t.Fatalf("VirtContainers should not allow sandboxes with empty hypervisors") } defer cleanUp() } -func TestCreateMockPod(t *testing.T) { +func TestCreateMockSandbox(t *testing.T) { hConfig := newHypervisorConfig(nil, nil) - _, err := testCreatePod(t, testPodID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) + _, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) if err != nil { t.Fatal(err) } defer cleanUp() } -func TestCreatePodEmtpyID(t *testing.T) { +func TestCreateSandboxEmtpyID(t *testing.T) { hConfig := newHypervisorConfig(nil, nil) - p, err := testCreatePod(t, "", MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) + p, err := testCreateSandbox(t, "", MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) if err == nil { - t.Fatalf("Expected pod with empty ID to fail, but got pod %v", p) + t.Fatalf("Expected sandbox with empty ID to fail, but got sandbox %v", p) } defer cleanUp() } -func testPodStateTransition(t *testing.T, state stateString, newState stateString) error { +func testSandboxStateTransition(t *testing.T, state stateString, newState stateString) error { hConfig := newHypervisorConfig(nil, nil) - p, err := testCreatePod(t, testPodID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) + p, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) if err != nil { return err } @@ -133,138 +133,138 @@ func testPodStateTransition(t *testing.T, state stateString, newState stateStrin return p.state.validTransition(state, newState) } -func TestPodStateReadyRunning(t *testing.T) { - err := testPodStateTransition(t, StateReady, StateRunning) +func TestSandboxStateReadyRunning(t *testing.T) { + err := testSandboxStateTransition(t, StateReady, StateRunning) if err != nil { t.Fatal(err) } } -func TestPodStateRunningPaused(t *testing.T) { - err := testPodStateTransition(t, StateRunning, StatePaused) +func TestSandboxStateRunningPaused(t *testing.T) { + err := testSandboxStateTransition(t, StateRunning, StatePaused) if err != nil { t.Fatal(err) } } -func TestPodStatePausedRunning(t *testing.T) { - err := testPodStateTransition(t, StatePaused, StateRunning) +func TestSandboxStatePausedRunning(t *testing.T) { + err := testSandboxStateTransition(t, StatePaused, StateRunning) if err != nil { t.Fatal(err) } } -func TestPodStatePausedStopped(t *testing.T) { - err := testPodStateTransition(t, StatePaused, StateStopped) +func TestSandboxStatePausedStopped(t *testing.T) { + err := testSandboxStateTransition(t, StatePaused, StateStopped) if err != nil { t.Fatal(err) } } -func TestPodStateRunningStopped(t *testing.T) { - err := testPodStateTransition(t, StateRunning, StateStopped) +func TestSandboxStateRunningStopped(t *testing.T) { + err := testSandboxStateTransition(t, StateRunning, StateStopped) if err != nil { t.Fatal(err) } } -func TestPodStateReadyPaused(t *testing.T) { - err := testPodStateTransition(t, StateReady, StateStopped) +func TestSandboxStateReadyPaused(t *testing.T) { + err := testSandboxStateTransition(t, StateReady, StateStopped) if err != nil { t.Fatal(err) } } -func TestPodStatePausedReady(t *testing.T) { - err := testPodStateTransition(t, StateStopped, StateReady) +func TestSandboxStatePausedReady(t *testing.T) { + err := testSandboxStateTransition(t, StateStopped, StateReady) if err == nil { t.Fatal("Invalid transition from Ready to Paused") } } -func testPodDir(t *testing.T, resource podResource, expected string) error { +func testSandboxDir(t *testing.T, resource sandboxResource, expected string) error { fs := filesystem{} - _, dir, err := fs.podURI(testPodID, resource) + _, dir, err := fs.sandboxURI(testSandboxID, resource) if err != nil { return err } if dir != expected { - return fmt.Errorf("Unexpected pod directory %s vs %s", dir, expected) + return fmt.Errorf("Unexpected sandbox directory %s vs %s", dir, expected) } return nil } -func testPodFile(t *testing.T, resource podResource, expected string) error { +func testSandboxFile(t *testing.T, resource sandboxResource, expected string) error { fs := filesystem{} - file, _, err := fs.podURI(testPodID, resource) + file, _, err := fs.sandboxURI(testSandboxID, resource) if err != nil { return err } if file != expected { - return fmt.Errorf("Unexpected pod file %s vs %s", file, expected) + return fmt.Errorf("Unexpected sandbox file %s vs %s", file, expected) } return nil } -func TestPodDirConfig(t *testing.T) { - err := testPodDir(t, configFileType, podDirConfig) +func TestSandboxDirConfig(t *testing.T) { + err := testSandboxDir(t, configFileType, sandboxDirConfig) if err != nil { t.Fatal(err) } } -func TestPodDirState(t *testing.T) { - err := testPodDir(t, stateFileType, podDirState) +func TestSandboxDirState(t *testing.T) { + err := testSandboxDir(t, stateFileType, sandboxDirState) if err != nil { t.Fatal(err) } } -func TestPodDirLock(t *testing.T) { - err := testPodDir(t, lockFileType, podDirLock) +func TestSandboxDirLock(t *testing.T) { + err := testSandboxDir(t, lockFileType, sandboxDirLock) if err != nil { t.Fatal(err) } } -func TestPodDirNegative(t *testing.T) { +func TestSandboxDirNegative(t *testing.T) { fs := filesystem{} - _, _, err := fs.podURI("", lockFileType) + _, _, err := fs.sandboxURI("", lockFileType) if err == nil { - t.Fatal("Empty pod IDs should not be allowed") + t.Fatal("Empty sandbox IDs should not be allowed") } } -func TestPodFileConfig(t *testing.T) { - err := testPodFile(t, configFileType, podFileConfig) +func TestSandboxFileConfig(t *testing.T) { + err := testSandboxFile(t, configFileType, sandboxFileConfig) if err != nil { t.Fatal(err) } } -func TestPodFileState(t *testing.T) { - err := testPodFile(t, stateFileType, podFileState) +func TestSandboxFileState(t *testing.T) { + err := testSandboxFile(t, stateFileType, sandboxFileState) if err != nil { t.Fatal(err) } } -func TestPodFileLock(t *testing.T) { - err := testPodFile(t, lockFileType, podFileLock) +func TestSandboxFileLock(t *testing.T) { + err := testSandboxFile(t, lockFileType, sandboxFileLock) if err != nil { t.Fatal(err) } } -func TestPodFileNegative(t *testing.T) { +func TestSandboxFileNegative(t *testing.T) { fs := filesystem{} - _, _, err := fs.podURI("", lockFileType) + _, _, err := fs.sandboxURI("", lockFileType) if err == nil { - t.Fatal("Empty pod IDs should not be allowed") + t.Fatal("Empty sandbox IDs should not be allowed") } } @@ -456,27 +456,27 @@ func TestSocketsStringSuccessful(t *testing.T) { } } -func TestPodListSuccessful(t *testing.T) { - pod := &Pod{} +func TestSandboxListSuccessful(t *testing.T) { + sandbox := &Sandbox{} - podList, err := pod.list() - if podList != nil || err != nil { + sandboxList, err := sandbox.list() + if sandboxList != nil || err != nil { t.Fatal() } } -func TestPodEnterSuccessful(t *testing.T) { - pod := &Pod{} +func TestSandboxEnterSuccessful(t *testing.T) { + sandbox := &Sandbox{} - err := pod.enter([]string{}) + err := sandbox.enter([]string{}) if err != nil { t.Fatal(err) } } -func testCheckInitPodAndContainerStates(p *Pod, initialPodState State, c *Container, initialContainerState State) error { - if p.state.State != initialPodState.State { - return fmt.Errorf("Expected pod state %v, got %v", initialPodState.State, p.state.State) +func testCheckInitSandboxAndContainerStates(p *Sandbox, initialSandboxState State, c *Container, initialContainerState State) error { + if p.state.State != initialSandboxState.State { + return fmt.Errorf("Expected sandbox state %v, got %v", initialSandboxState.State, p.state.State) } if c.state.State != initialContainerState.State { @@ -486,24 +486,24 @@ func testCheckInitPodAndContainerStates(p *Pod, initialPodState State, c *Contai return nil } -func testForcePodStateChangeAndCheck(t *testing.T, p *Pod, newPodState State) error { - // force pod state change - if err := p.setPodState(newPodState.State); err != nil { - t.Fatalf("Unexpected error: %v (pod %+v)", err, p) +func testForceSandboxStateChangeAndCheck(t *testing.T, p *Sandbox, newSandboxState State) error { + // force sandbox state change + if err := p.setSandboxState(newSandboxState.State); err != nil { + t.Fatalf("Unexpected error: %v (sandbox %+v)", err, p) } // check the in-memory state is correct - if p.state.State != newPodState.State { - return fmt.Errorf("Expected state %v, got %v", newPodState.State, p.state.State) + if p.state.State != newSandboxState.State { + return fmt.Errorf("Expected state %v, got %v", newSandboxState.State, p.state.State) } return nil } -func testForceContainerStateChangeAndCheck(t *testing.T, p *Pod, c *Container, newContainerState State) error { +func testForceContainerStateChangeAndCheck(t *testing.T, p *Sandbox, c *Container, newContainerState State) error { // force container state change if err := c.setContainerState(newContainerState.State); err != nil { - t.Fatalf("Unexpected error: %v (pod %+v)", err, p) + t.Fatalf("Unexpected error: %v (sandbox %+v)", err, p) } // check the in-memory state is correct @@ -514,10 +514,10 @@ func testForceContainerStateChangeAndCheck(t *testing.T, p *Pod, c *Container, n return nil } -func testCheckPodOnDiskState(p *Pod, podState State) error { +func testCheckSandboxOnDiskState(p *Sandbox, sandboxState State) error { // check on-disk state is correct - if p.state.State != podState.State { - return fmt.Errorf("Expected state %v, got %v", podState.State, p.state.State) + if p.state.State != sandboxState.State { + return fmt.Errorf("Expected state %v, got %v", sandboxState.State, p.state.State) } return nil @@ -532,13 +532,13 @@ func testCheckContainerOnDiskState(c *Container, containerState State) error { return nil } -func TestPodSetPodAndContainerState(t *testing.T) { +func TestSandboxSetSandboxAndContainerState(t *testing.T) { contID := "505" contConfig := newTestContainerConfigNoop(contID) hConfig := newHypervisorConfig(nil, nil) - // create a pod - p, err := testCreatePod(t, testPodID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, []ContainerConfig{contConfig}, nil) + // create a sandbox + p, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, []ContainerConfig{contConfig}, nil) if err != nil { t.Fatal(err) } @@ -549,11 +549,11 @@ func TestPodSetPodAndContainerState(t *testing.T) { t.Fatalf("Expected 1 container found %v", l) } - initialPodState := State{ + initialSandboxState := State{ State: StateReady, } - // After a pod creation, a container has a READY state + // After a sandbox creation, a container has a READY state initialContainerState := State{ State: StateReady, } @@ -563,22 +563,22 @@ func TestPodSetPodAndContainerState(t *testing.T) { t.Fatalf("Failed to retrieve container %v: %v", contID, err) } - // check initial pod and container states - if err := testCheckInitPodAndContainerStates(p, initialPodState, c, initialContainerState); err != nil { + // check initial sandbox and container states + if err := testCheckInitSandboxAndContainerStates(p, initialSandboxState, c, initialContainerState); err != nil { t.Error(err) } // persist to disk - err = p.storePod() + err = p.storeSandbox() if err != nil { t.Fatal(err) } - newPodState := State{ + newSandboxState := State{ State: StateRunning, } - if err := testForcePodStateChangeAndCheck(t, p, newPodState); err != nil { + if err := testForceSandboxStateChangeAndCheck(t, p, newSandboxState); err != nil { t.Error(err) } @@ -591,12 +591,12 @@ func TestPodSetPodAndContainerState(t *testing.T) { } // force state to be read from disk - p2, err := fetchPod(p.ID()) + p2, err := fetchSandbox(p.ID()) if err != nil { - t.Fatalf("Failed to fetch pod %v: %v", p.ID(), err) + t.Fatalf("Failed to fetch sandbox %v: %v", p.ID(), err) } - if err := testCheckPodOnDiskState(p2, newPodState); err != nil { + if err := testCheckSandboxOnDiskState(p2, newSandboxState); err != nil { t.Error(err) } @@ -609,10 +609,10 @@ func TestPodSetPodAndContainerState(t *testing.T) { t.Error(err) } - // revert pod state to allow it to be deleted - err = p.setPodState(initialPodState.State) + // revert sandbox state to allow it to be deleted + err = p.setSandboxState(initialSandboxState.State) if err != nil { - t.Fatalf("Unexpected error: %v (pod %+v)", err, p) + t.Fatalf("Unexpected error: %v (sandbox %+v)", err, p) } // clean up @@ -622,48 +622,48 @@ func TestPodSetPodAndContainerState(t *testing.T) { } } -func TestPodSetPodStateFailingStorePodResource(t *testing.T) { +func TestSandboxSetSandboxStateFailingStoreSandboxResource(t *testing.T) { fs := &filesystem{} - pod := &Pod{ + sandbox := &Sandbox{ storage: fs, } - err := pod.setPodState(StateReady) + err := sandbox.setSandboxState(StateReady) if err == nil { t.Fatal() } } -func TestPodSetContainersStateFailingEmptyPodID(t *testing.T) { - pod := &Pod{ +func TestSandboxSetContainersStateFailingEmptySandboxID(t *testing.T) { + sandbox := &Sandbox{ storage: &filesystem{}, } containers := []*Container{ { - id: "100", - pod: pod, + id: "100", + sandbox: sandbox, }, } - pod.containers = containers + sandbox.containers = containers - err := pod.setContainersState(StateReady) + err := sandbox.setContainersState(StateReady) if err == nil { t.Fatal() } } -func TestPodDeleteContainerStateSuccessful(t *testing.T) { +func TestSandboxDeleteContainerStateSuccessful(t *testing.T) { contID := "100" fs := &filesystem{} - pod := &Pod{ - id: testPodID, + sandbox := &Sandbox{ + id: testSandboxID, storage: fs, } - path := filepath.Join(runStoragePath, testPodID, contID) + path := filepath.Join(runStoragePath, testSandboxID, contID) err := os.MkdirAll(path, dirMode) if err != nil { t.Fatal(err) @@ -683,7 +683,7 @@ func TestPodDeleteContainerStateSuccessful(t *testing.T) { t.Fatal(err) } - err = pod.deleteContainerState(contID) + err = sandbox.deleteContainerState(contID) if err != nil { t.Fatal(err) } @@ -694,21 +694,21 @@ func TestPodDeleteContainerStateSuccessful(t *testing.T) { } } -func TestPodDeleteContainerStateFailingEmptyPodID(t *testing.T) { +func TestSandboxDeleteContainerStateFailingEmptySandboxID(t *testing.T) { contID := "100" fs := &filesystem{} - pod := &Pod{ + sandbox := &Sandbox{ storage: fs, } - err := pod.deleteContainerState(contID) + err := sandbox.deleteContainerState(contID) if err == nil { t.Fatal() } } -func TestPodDeleteContainersStateSuccessful(t *testing.T) { +func TestSandboxDeleteContainersStateSuccessful(t *testing.T) { var err error containers := []ContainerConfig{ @@ -720,19 +720,19 @@ func TestPodDeleteContainersStateSuccessful(t *testing.T) { }, } - podConfig := &PodConfig{ + sandboxConfig := &SandboxConfig{ Containers: containers, } fs := &filesystem{} - pod := &Pod{ - id: testPodID, - config: podConfig, + sandbox := &Sandbox{ + id: testSandboxID, + config: sandboxConfig, storage: fs, } for _, c := range containers { - path := filepath.Join(runStoragePath, testPodID, c.ID) + path := filepath.Join(runStoragePath, testSandboxID, c.ID) err = os.MkdirAll(path, dirMode) if err != nil { t.Fatal(err) @@ -753,13 +753,13 @@ func TestPodDeleteContainersStateSuccessful(t *testing.T) { } } - err = pod.deleteContainersState() + err = sandbox.deleteContainersState() if err != nil { t.Fatal(err) } for _, c := range containers { - stateFilePath := filepath.Join(runStoragePath, testPodID, c.ID, stateFile) + stateFilePath := filepath.Join(runStoragePath, testSandboxID, c.ID, stateFile) _, err = os.Stat(stateFilePath) if err == nil { t.Fatal() @@ -767,24 +767,24 @@ func TestPodDeleteContainersStateSuccessful(t *testing.T) { } } -func TestPodDeleteContainersStateFailingEmptyPodID(t *testing.T) { +func TestSandboxDeleteContainersStateFailingEmptySandboxID(t *testing.T) { containers := []ContainerConfig{ { ID: "100", }, } - podConfig := &PodConfig{ + sandboxConfig := &SandboxConfig{ Containers: containers, } fs := &filesystem{} - pod := &Pod{ - config: podConfig, + sandbox := &Sandbox{ + config: sandboxConfig, storage: fs, } - err := pod.deleteContainersState() + err := sandbox.deleteContainersState() if err == nil { t.Fatal() } @@ -799,17 +799,17 @@ func TestGetContainer(t *testing.T) { containers = append(containers, &c) } - pod := Pod{ + sandbox := Sandbox{ containers: containers, } - c := pod.GetContainer("noid") + c := sandbox.GetContainer("noid") if c != nil { t.Fatal() } for _, id := range containerIDs { - c = pod.GetContainer(id) + c = sandbox.GetContainer(id) if c == nil { t.Fatal() } @@ -825,11 +825,11 @@ func TestGetAllContainers(t *testing.T) { containers = append(containers, &c) } - pod := Pod{ + sandbox := Sandbox{ containers: containers, } - list := pod.GetAllContainers() + list := sandbox.GetAllContainers() for i, c := range list { if c.ID() != containerIDs[i] { @@ -839,11 +839,11 @@ func TestGetAllContainers(t *testing.T) { } func TestSetAnnotations(t *testing.T) { - pod := Pod{ + sandbox := Sandbox{ id: "abcxyz123", storage: &filesystem{}, annotationsLock: &sync.RWMutex{}, - config: &PodConfig{ + config: &SandboxConfig{ Annotations: map[string]string{ "annotation1": "abc", }, @@ -857,9 +857,9 @@ func TestSetAnnotations(t *testing.T) { } // Add a new annotation - pod.SetAnnotations(newAnnotations) + sandbox.SetAnnotations(newAnnotations) - v, err := pod.Annotations(keyAnnotation) + v, err := sandbox.Annotations(keyAnnotation) if err != nil { t.Fatal() } @@ -872,9 +872,9 @@ func TestSetAnnotations(t *testing.T) { valueAnnotation = "123" newAnnotations[keyAnnotation] = valueAnnotation - pod.SetAnnotations(newAnnotations) + sandbox.SetAnnotations(newAnnotations) - v, err = pod.Annotations(keyAnnotation) + v, err = sandbox.Annotations(keyAnnotation) if err != nil { t.Fatal() } @@ -884,21 +884,21 @@ func TestSetAnnotations(t *testing.T) { } } -func TestPodGetContainer(t *testing.T) { +func TestSandboxGetContainer(t *testing.T) { - emptyPod := Pod{} - _, err := emptyPod.findContainer("") + emptySandbox := Sandbox{} + _, err := emptySandbox.findContainer("") if err == nil { - t.Fatal("Expected error for containerless pod") + t.Fatal("Expected error for containerless sandbox") } - _, err = emptyPod.findContainer("foo") + _, err = emptySandbox.findContainer("foo") if err == nil { - t.Fatal("Expected error for containerless pod and invalid containerID") + t.Fatal("Expected error for containerless sandbox and invalid containerID") } hConfig := newHypervisorConfig(nil, nil) - p, err := testCreatePod(t, testPodID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) + p, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil) if err != nil { t.Fatal(err) } @@ -908,11 +908,11 @@ func TestPodGetContainer(t *testing.T) { contConfig := newTestContainerConfigNoop(contID) newContainer, err := createContainer(p, contConfig) if err != nil { - t.Fatalf("Failed to create container %+v in pod %+v: %v", contConfig, p, err) + t.Fatalf("Failed to create container %+v in sandbox %+v: %v", contConfig, p, err) } if err := p.addContainer(newContainer); err != nil { - t.Fatalf("Could not add container to pod %v", err) + t.Fatalf("Could not add container to sandbox %v", err) } got := false @@ -944,21 +944,21 @@ func TestContainerSetStateBlockIndex(t *testing.T) { } hConfig := newHypervisorConfig(nil, nil) - pod, err := testCreatePod(t, testPodID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, containers, nil) + sandbox, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, containers, nil) if err != nil { t.Fatal(err) } defer cleanUp() fs := &filesystem{} - pod.storage = fs + sandbox.storage = fs - c := pod.GetContainer("100") + c := sandbox.GetContainer("100") if c == nil { t.Fatal() } - path := filepath.Join(runStoragePath, testPodID, c.ID()) + path := filepath.Join(runStoragePath, testSandboxID, c.ID()) err = os.MkdirAll(path, dirMode) if err != nil { t.Fatal(err) @@ -1043,21 +1043,21 @@ func TestContainerStateSetFstype(t *testing.T) { } hConfig := newHypervisorConfig(nil, nil) - pod, err := testCreatePod(t, testPodID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, containers, nil) + sandbox, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NoopNetworkModel, NetworkConfig{}, containers, nil) if err != nil { t.Fatal(err) } defer cleanUp() fs := &filesystem{} - pod.storage = fs + sandbox.storage = fs - c := pod.GetContainer("100") + c := sandbox.GetContainer("100") if c == nil { t.Fatal() } - path := filepath.Join(runStoragePath, testPodID, c.ID()) + path := filepath.Join(runStoragePath, testSandboxID, c.ID()) err = os.MkdirAll(path, dirMode) if err != nil { t.Fatal(err) @@ -1133,7 +1133,7 @@ func TestContainerStateSetFstype(t *testing.T) { } } -func TestPodAttachDevicesVFIO(t *testing.T) { +func TestSandboxAttachDevicesVFIO(t *testing.T) { tmpDir, err := ioutil.TempDir("", "") assert.Nil(t, err) os.RemoveAll(tmpDir) @@ -1173,12 +1173,12 @@ func TestPodAttachDevicesVFIO(t *testing.T) { containers := []*Container{c} - pod := Pod{ + sandbox := Sandbox{ containers: containers, hypervisor: &mockHypervisor{}, } - containers[0].pod = &pod + containers[0].sandbox = &sandbox err = containers[0].attachDevices() assert.Nil(t, err, "Error while attaching devices %s", err) @@ -1187,7 +1187,7 @@ func TestPodAttachDevicesVFIO(t *testing.T) { assert.Nil(t, err, "Error while detaching devices %s", err) } -func TestPodCreateAssets(t *testing.T) { +func TestSandboxCreateAssets(t *testing.T) { assert := assert.New(t) tmpfile, err := ioutil.TempFile("", "virtcontainers-test-") @@ -1208,7 +1208,7 @@ func TestPodCreateAssets(t *testing.T) { ImagePath: filepath.Join(testDir, testImage), } - p := &PodConfig{ + p := &SandboxConfig{ Annotations: map[string]string{ annotations.KernelPath: tmpfile.Name(), annotations.KernelHash: assetContentHash, @@ -1224,7 +1224,7 @@ func TestPodCreateAssets(t *testing.T) { assert.True(ok) assert.Equal(a.path, tmpfile.Name()) - p = &PodConfig{ + p = &SandboxConfig{ Annotations: map[string]string{ annotations.KernelPath: tmpfile.Name(), annotations.KernelHash: assetContentWrongHash, @@ -1237,65 +1237,65 @@ func TestPodCreateAssets(t *testing.T) { assert.NotNil(err) } -func testFindContainerFailure(t *testing.T, pod *Pod, cid string) { - c, err := pod.findContainer(cid) +func testFindContainerFailure(t *testing.T, sandbox *Sandbox, cid string) { + c, err := sandbox.findContainer(cid) assert.Nil(t, c, "Container pointer should be nil") assert.NotNil(t, err, "Should have returned an error") } -func TestFindContainerPodNilFailure(t *testing.T) { +func TestFindContainerSandboxNilFailure(t *testing.T) { testFindContainerFailure(t, nil, testContainerID) } func TestFindContainerContainerIDEmptyFailure(t *testing.T) { - pod := &Pod{} - testFindContainerFailure(t, pod, "") + sandbox := &Sandbox{} + testFindContainerFailure(t, sandbox, "") } func TestFindContainerNoContainerMatchFailure(t *testing.T) { - pod := &Pod{} - testFindContainerFailure(t, pod, testContainerID) + sandbox := &Sandbox{} + testFindContainerFailure(t, sandbox, testContainerID) } func TestFindContainerSuccess(t *testing.T) { - pod := &Pod{ + sandbox := &Sandbox{ containers: []*Container{ { id: testContainerID, }, }, } - c, err := pod.findContainer(testContainerID) + c, err := sandbox.findContainer(testContainerID) assert.NotNil(t, c, "Container pointer should not be nil") assert.Nil(t, err, "Should not have returned an error: %v", err) - assert.True(t, c == pod.containers[0], "Container pointers should point to the same address") + assert.True(t, c == sandbox.containers[0], "Container pointers should point to the same address") } -func TestRemoveContainerPodNilFailure(t *testing.T) { +func TestRemoveContainerSandboxNilFailure(t *testing.T) { testFindContainerFailure(t, nil, testContainerID) } func TestRemoveContainerContainerIDEmptyFailure(t *testing.T) { - pod := &Pod{} - testFindContainerFailure(t, pod, "") + sandbox := &Sandbox{} + testFindContainerFailure(t, sandbox, "") } func TestRemoveContainerNoContainerMatchFailure(t *testing.T) { - pod := &Pod{} - testFindContainerFailure(t, pod, testContainerID) + sandbox := &Sandbox{} + testFindContainerFailure(t, sandbox, testContainerID) } func TestRemoveContainerSuccess(t *testing.T) { - pod := &Pod{ + sandbox := &Sandbox{ containers: []*Container{ { id: testContainerID, }, }, } - err := pod.removeContainer(testContainerID) + err := sandbox.removeContainer(testContainerID) assert.Nil(t, err, "Should not have returned an error: %v", err) - assert.Equal(t, len(pod.containers), 0, "Containers list from pod structure should be empty") + assert.Equal(t, len(sandbox.containers), 0, "Containers list from sandbox structure should be empty") } diff --git a/virtcontainers/podlist.go b/virtcontainers/sandboxlist.go similarity index 55% rename from virtcontainers/podlist.go rename to virtcontainers/sandboxlist.go index 14e8eb436..d6b73c5f2 100644 --- a/virtcontainers/podlist.go +++ b/virtcontainers/sandboxlist.go @@ -21,40 +21,40 @@ import ( "sync" ) -type podList struct { - lock sync.RWMutex - pods map[string]*Pod +type sandboxList struct { + lock sync.RWMutex + sandboxes map[string]*Sandbox } -// globalPodList tracks pods globally -var globalPodList = &podList{pods: make(map[string]*Pod)} +// globalSandboxList tracks sandboxes globally +var globalSandboxList = &sandboxList{sandboxes: make(map[string]*Sandbox)} -func (p *podList) addPod(pod *Pod) (err error) { - if pod == nil { +func (p *sandboxList) addSandbox(sandbox *Sandbox) (err error) { + if sandbox == nil { return nil } p.lock.Lock() defer p.lock.Unlock() - if p.pods[pod.id] == nil { - p.pods[pod.id] = pod + if p.sandboxes[sandbox.id] == nil { + p.sandboxes[sandbox.id] = sandbox } else { - err = fmt.Errorf("pod %s exists", pod.id) + err = fmt.Errorf("sandbox %s exists", sandbox.id) } return err } -func (p *podList) removePod(id string) { +func (p *sandboxList) removeSandbox(id string) { p.lock.Lock() defer p.lock.Unlock() - delete(p.pods, id) + delete(p.sandboxes, id) } -func (p *podList) lookupPod(id string) (*Pod, error) { +func (p *sandboxList) lookupSandbox(id string) (*Sandbox, error) { p.lock.RLock() defer p.lock.RUnlock() - if p.pods[id] != nil { - return p.pods[id], nil + if p.sandboxes[id] != nil { + return p.sandboxes[id], nil } - return nil, fmt.Errorf("pod %s does not exist", id) + return nil, fmt.Errorf("sandbox %s does not exist", id) } diff --git a/virtcontainers/podlist_test.go b/virtcontainers/sandboxlist_test.go similarity index 53% rename from virtcontainers/podlist_test.go rename to virtcontainers/sandboxlist_test.go index 2fc0d27ff..6cfbd733b 100644 --- a/virtcontainers/podlist_test.go +++ b/virtcontainers/sandboxlist_test.go @@ -22,21 +22,21 @@ import ( "github.com/stretchr/testify/assert" ) -func TestPodListOperations(t *testing.T) { - p := &Pod{id: "testpodListpod"} - l := &podList{pods: make(map[string]*Pod)} - err := l.addPod(p) - assert.Nil(t, err, "addPod failed") +func TestSandboxListOperations(t *testing.T) { + p := &Sandbox{id: "testsandboxListsandbox"} + l := &sandboxList{sandboxes: make(map[string]*Sandbox)} + err := l.addSandbox(p) + assert.Nil(t, err, "addSandbox failed") - err = l.addPod(p) - assert.NotNil(t, err, "add same pod should fail") + err = l.addSandbox(p) + assert.NotNil(t, err, "add same sandbox should fail") - np, err := l.lookupPod(p.id) - assert.Nil(t, err, "lookupPod failed") - assert.Equal(t, np, p, "lookupPod returns different pod %v:%v", np, p) + np, err := l.lookupSandbox(p.id) + assert.Nil(t, err, "lookupSandbox failed") + assert.Equal(t, np, p, "lookupSandbox returns different sandbox %v:%v", np, p) - _, err = l.lookupPod("some-non-existing-pod-name") - assert.NotNil(t, err, "lookupPod for non-existing pod should fail") + _, err = l.lookupSandbox("some-non-existing-sandbox-name") + assert.NotNil(t, err, "lookupSandbox for non-existing sandbox should fail") - l.removePod(p.id) + l.removeSandbox(p.id) } diff --git a/virtcontainers/shim.go b/virtcontainers/shim.go index f2777d5d4..cbbdcfd20 100644 --- a/virtcontainers/shim.go +++ b/virtcontainers/shim.go @@ -118,8 +118,8 @@ func newShim(pType ShimType) (shim, error) { } } -// newShimConfig returns a shim config from a generic PodConfig interface. -func newShimConfig(config PodConfig) interface{} { +// newShimConfig returns a shim config from a generic SandboxConfig interface. +func newShimConfig(config SandboxConfig) interface{} { switch config.ShimType { case NoopShimType, KataBuiltInShimType: return nil @@ -165,7 +165,7 @@ func stopShim(pid int) error { return nil } -func prepareAndStartShim(pod *Pod, shim shim, cid, token, url string, cmd Cmd, +func prepareAndStartShim(sandbox *Sandbox, shim shim, cid, token, url string, cmd Cmd, createNSList []ns.NSType, enterNSList []ns.Namespace) (*Process, error) { process := &Process{ Token: token, @@ -183,7 +183,7 @@ func prepareAndStartShim(pod *Pod, shim shim, cid, token, url string, cmd Cmd, EnterNS: enterNSList, } - pid, err := shim.start(*pod, shimParams) + pid, err := shim.start(*sandbox, shimParams) if err != nil { return nil, err } @@ -293,5 +293,5 @@ func waitForShim(pid int) error { type shim interface { // start starts the shim relying on its configuration and on // parameters provided. - start(pod Pod, params ShimParams) (int, error) + start(sandbox Sandbox, params ShimParams) (int, error) } diff --git a/virtcontainers/shim_test.go b/virtcontainers/shim_test.go index 73c21cd59..c620675c3 100644 --- a/virtcontainers/shim_test.go +++ b/virtcontainers/shim_test.go @@ -143,60 +143,60 @@ func TestNewShimFromUnknownShimType(t *testing.T) { } } -func testNewShimConfigFromPodConfig(t *testing.T, podConfig PodConfig, expected interface{}) { - result := newShimConfig(podConfig) +func testNewShimConfigFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfig, expected interface{}) { + result := newShimConfig(sandboxConfig) if reflect.DeepEqual(result, expected) == false { t.Fatalf("Got %+v\nExpecting %+v", result, expected) } } -func TestNewShimConfigFromCCShimPodConfig(t *testing.T) { +func TestNewShimConfigFromCCShimSandboxConfig(t *testing.T) { shimConfig := ShimConfig{} - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ ShimType: CCShimType, ShimConfig: shimConfig, } - testNewShimConfigFromPodConfig(t, podConfig, shimConfig) + testNewShimConfigFromSandboxConfig(t, sandboxConfig, shimConfig) } -func TestNewShimConfigFromKataShimPodConfig(t *testing.T) { +func TestNewShimConfigFromKataShimSandboxConfig(t *testing.T) { shimConfig := ShimConfig{} - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ ShimType: KataShimType, ShimConfig: shimConfig, } - testNewShimConfigFromPodConfig(t, podConfig, shimConfig) + testNewShimConfigFromSandboxConfig(t, sandboxConfig, shimConfig) } -func TestNewShimConfigFromNoopShimPodConfig(t *testing.T) { - podConfig := PodConfig{ +func TestNewShimConfigFromNoopShimSandboxConfig(t *testing.T) { + sandboxConfig := SandboxConfig{ ShimType: NoopShimType, } - testNewShimConfigFromPodConfig(t, podConfig, nil) + testNewShimConfigFromSandboxConfig(t, sandboxConfig, nil) } -func TestNewShimConfigFromKataBuiltInShimPodConfig(t *testing.T) { - podConfig := PodConfig{ +func TestNewShimConfigFromKataBuiltInShimSandboxConfig(t *testing.T) { + sandboxConfig := SandboxConfig{ ShimType: KataBuiltInShimType, } - testNewShimConfigFromPodConfig(t, podConfig, nil) + testNewShimConfigFromSandboxConfig(t, sandboxConfig, nil) } -func TestNewShimConfigFromUnknownShimPodConfig(t *testing.T) { +func TestNewShimConfigFromUnknownShimSandboxConfig(t *testing.T) { var shimType ShimType - podConfig := PodConfig{ + sandboxConfig := SandboxConfig{ ShimType: shimType, } - testNewShimConfigFromPodConfig(t, podConfig, nil) + testNewShimConfigFromSandboxConfig(t, sandboxConfig, nil) } func testRunSleep0AndGetPid(t *testing.T) int { diff --git a/virtcontainers/spawner.go b/virtcontainers/spawner.go index 84e8e3119..020fc9a3f 100644 --- a/virtcontainers/spawner.go +++ b/virtcontainers/spawner.go @@ -20,7 +20,7 @@ import ( "fmt" ) -// SpawnerType describes the type of guest agent a Pod should run. +// SpawnerType describes the type of guest agent a Sandbox should run. type SpawnerType string const ( diff --git a/virtcontainers/types.go b/virtcontainers/types.go index 3d99fd27f..3020c5f71 100644 --- a/virtcontainers/types.go +++ b/virtcontainers/types.go @@ -24,9 +24,9 @@ var ( UnknownContainerType ContainerType = "unknown_container_type" ) -// IsPod determines if the container type can be considered as a pod. -// We can consider a pod in case we have a PodSandbox or a RegularContainer. -func (cType ContainerType) IsPod() bool { +// IsSandbox determines if the container type can be considered as a sandbox. +// We can consider a sandbox in case we have a PodSandbox or a RegularContainer. +func (cType ContainerType) IsSandbox() bool { if cType == PodSandbox { return true } diff --git a/virtcontainers/types_test.go b/virtcontainers/types_test.go index dad1b1145..a3cac0205 100644 --- a/virtcontainers/types_test.go +++ b/virtcontainers/types_test.go @@ -18,20 +18,20 @@ import ( "testing" ) -func testIsPod(t *testing.T, cType ContainerType, expected bool) { - if result := cType.IsPod(); result != expected { +func testIsSandbox(t *testing.T, cType ContainerType, expected bool) { + if result := cType.IsSandbox(); result != expected { t.Fatalf("Got %t, Expecting %t", result, expected) } } -func TestIsPodPodSandboxTrue(t *testing.T) { - testIsPod(t, PodSandbox, true) +func TestIsPodSandboxTrue(t *testing.T) { + testIsSandbox(t, PodSandbox, true) } -func TestIsPodPodContainerFalse(t *testing.T) { - testIsPod(t, PodContainer, false) +func TestIsPodContainerFalse(t *testing.T) { + testIsSandbox(t, PodContainer, false) } -func TestIsPodUnknownContainerTypeFalse(t *testing.T) { - testIsPod(t, UnknownContainerType, false) +func TestIsSandboxUnknownContainerTypeFalse(t *testing.T) { + testIsSandbox(t, UnknownContainerType, false) } diff --git a/virtcontainers/virtcontainers_test.go b/virtcontainers/virtcontainers_test.go index 3b5cbc6bf..7aead3244 100644 --- a/virtcontainers/virtcontainers_test.go +++ b/virtcontainers/virtcontainers_test.go @@ -27,7 +27,7 @@ import ( "github.com/sirupsen/logrus" ) -const testPodID = "7f49d00d-1995-4156-8c79-5f5ab24ce138" +const testSandboxID = "7f49d00d-1995-4156-8c79-5f5ab24ce138" const testContainerID = "containerID" const testKernel = "kernel" const testInitrd = "initrd" @@ -39,12 +39,12 @@ const testDisabledAsNonRoot = "Test disabled as requires root privileges" // package variables set in TestMain var testDir = "" -var podDirConfig = "" -var podFileConfig = "" -var podDirState = "" -var podDirLock = "" -var podFileState = "" -var podFileLock = "" +var sandboxDirConfig = "" +var sandboxFileConfig = "" +var sandboxDirState = "" +var sandboxDirLock = "" +var sandboxFileState = "" +var sandboxFileLock = "" var testQemuKernelPath = "" var testQemuInitrdPath = "" var testQemuImagePath = "" @@ -52,10 +52,10 @@ var testQemuPath = "" var testHyperstartCtlSocket = "" var testHyperstartTtySocket = "" -// cleanUp Removes any stale pod/container state that can affect +// cleanUp Removes any stale sandbox/container state that can affect // the next test to run. func cleanUp() { - globalPodList.removePod(testPodID) + globalSandboxList.removeSandbox(testSandboxID) for _, dir := range []string{testDir, defaultSharedDir} { os.RemoveAll(dir) os.MkdirAll(dir, dirMode) @@ -130,12 +130,12 @@ func TestMain(m *testing.M) { runStoragePath = filepath.Join(testDir, storagePathSuffix, "run") // set now that configStoragePath has been overridden. - podDirConfig = filepath.Join(configStoragePath, testPodID) - podFileConfig = filepath.Join(configStoragePath, testPodID, configFile) - podDirState = filepath.Join(runStoragePath, testPodID) - podDirLock = filepath.Join(runStoragePath, testPodID) - podFileState = filepath.Join(runStoragePath, testPodID, stateFile) - podFileLock = filepath.Join(runStoragePath, testPodID, lockFileName) + sandboxDirConfig = filepath.Join(configStoragePath, testSandboxID) + sandboxFileConfig = filepath.Join(configStoragePath, testSandboxID, configFile) + sandboxDirState = filepath.Join(runStoragePath, testSandboxID) + sandboxDirLock = filepath.Join(runStoragePath, testSandboxID) + sandboxFileState = filepath.Join(runStoragePath, testSandboxID, stateFile) + sandboxFileLock = filepath.Join(runStoragePath, testSandboxID, lockFileName) testQemuKernelPath = filepath.Join(testDir, testKernel) testQemuInitrdPath = filepath.Join(testDir, testInitrd)