diff --git a/tests/e2e/common.go b/tests/e2e/common.go index 7953d71c..96e3ef5a 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -52,6 +52,26 @@ type containerVolume struct { Dest string } +type sideContainerNetMode string + +const ( + // sideContainerNetModeNetwork joins the same named/user-defined + // network as the primary container (docker/nerdctl --network ). + sideContainerNetModeNetwork sideContainerNetMode = "network" + // sideContainerNetModeShared joins the primary container's network + // namespace directly, similar to containers sharing a namespace + // inside a Kubernetes pod (docker/nerdctl --network container:). + sideContainerNetModeShared sideContainerNetMode = "shared" +) + +type sideContainer struct { + Name string + Image string + Cli string + Volumes []containerVolume + NetMode sideContainerNetMode +} + type containerTestArgs struct { Name string Image string @@ -63,8 +83,9 @@ type containerTestArgs struct { Memory string Cli string Volumes []containerVolume + Network string StaticNet bool - SideContainers []string + SideContainers []sideContainer Skippable bool TestFunc testMethod ExpectOut string @@ -90,6 +111,9 @@ func commonNewContainerCmd(a containerTestArgs) string { if a.Memory != "" { cmdBase += fmt.Sprintf("-m %s ", a.Memory) } + if a.Network != "" { + cmdBase += fmt.Sprintf("--network %s ", a.Network) + } if a.UID != 0 && a.GID != 0 { cmdBase += fmt.Sprintf("-u %d:%d ", a.UID, a.GID) } @@ -136,6 +160,72 @@ func commonCmdExecStderr(command string) (string, string, error) { return output, errorOut, err } +func commonSideContainerCmd(sc sideContainer, netArg string) string { + cmdBase := "" + if netArg != "" { + cmdBase += fmt.Sprintf("--network %s ", netArg) + } + for _, vol := range sc.Volumes { + cmdBase += fmt.Sprintf("--mount type=bind,src=%s,dst=%s ", vol.Source, vol.Dest) + } + cmdBase += "--name " + cmdBase += sc.Name + " " + cmdBase += sc.Image + " " + cmdBase += sc.Cli + return cmdBase +} + +func commonRunSideContainer(tool string, sc sideContainer, netArg string) (output string, err error) { + cmdBase := tool + " run -d " + cmdBase += commonSideContainerCmd(sc, netArg) + return commonCmdExec(cmdBase) +} + +// commonStartSideContainers starts every side container defined and +// joining each one of them int the primary container's network per its NetMode, +// and returns their container IDs for later cleanup. +func commonStartSideContainers(tool string, a containerTestArgs, primaryID string) ([]string, error) { + var ids []string + for _, sc := range a.SideContainers { + var netArg string + switch sc.NetMode { + case sideContainerNetModeNetwork: + // a.Network may be "": docker/nerdctl both attach a + // container to the default "bridge" network when + // --network is omitted. + netArg = a.Network + case sideContainerNetModeShared: + netArg = "container:" + primaryID + default: + return ids, fmt.Errorf("side container %s has unknown network mode %q", sc.Name, sc.NetMode) + } + cID, err := commonRunSideContainer(tool, sc, netArg) + if err != nil { + return ids, fmt.Errorf("failed to start side container %s: %s -- %v", sc.Name, cID, err) + } + ids = append(ids, cID) + } + return ids, nil +} + +func commonStopSideContainers(tool string, ids []string) error { + for _, cID := range ids { + if _, err := commonStopContainer(tool, cID); err != nil { + return fmt.Errorf("failed to stop side container %s: %v", cID, err) + } + } + return nil +} + +func commonRmSideContainers(tool string, ids []string) error { + for _, cID := range ids { + if _, err := commonRmContainer(tool, cID); err != nil { + return fmt.Errorf("failed to remove side container %s: %v", cID, err) + } + } + return nil +} + func commonPull(tool string, image string) error { pullCmd := tool + " image pull " + image diff --git a/tests/e2e/crictl.go b/tests/e2e/crictl.go index 05ed0f05..80e52571 100644 --- a/tests/e2e/crictl.go +++ b/tests/e2e/crictl.go @@ -30,9 +30,10 @@ const podConfigFilename = "pod.json" const cntrConfigFilename = "container.json" type crictlInfo struct { - testArgs containerTestArgs - podID string - containerID string + testArgs containerTestArgs + podID string + containerID string + sideContainerIDs []string } func newCrictlTool(args containerTestArgs) *crictlInfo { @@ -133,6 +134,39 @@ func crictlNewContainerConfig(path string, a containerTestArgs) (string, error) return absContConf, nil } +// crictlNewSideContainerConfig writes a container config for a side container, +// named after it so multiple side containers don't collide on disk. +func crictlNewSideContainerConfig(path string, sc sideContainer) (string, error) { + var mounts []*criruntimeapi.Mount + for _, vol := range sc.Volumes { + mounts = append(mounts, &criruntimeapi.Mount{ + ContainerPath: vol.Dest, + HostPath: vol.Source, + Readonly: false, + }) + } + containerConfig := criruntimeapi.ContainerConfig{ + Metadata: &criruntimeapi.ContainerMetadata{ + Name: sc.Name, + }, + Image: &criruntimeapi.ImageSpec{ + Image: sc.Image, + }, + Command: strings.Fields(sc.Cli), + Mounts: mounts, + } + cc, err := json.MarshalIndent(&containerConfig, "", " ") + if err != nil { + return "", fmt.Errorf("Failed to marshal side container config: %v", err) + } + absConf := filepath.Join(path, sc.Name+".json") + err = writeToFile(absConf, string(cc)) + if err != nil { + return "", fmt.Errorf("Failed to write side container config: %v", err) + } + return absConf, nil +} + func (i *crictlInfo) Name() string { return crictlName } @@ -201,7 +235,46 @@ func (i *crictlInfo) createContainer() (string, error) { return commonCmdExec(cmdBase) } +// startSideContainers starts every side container declared on the test +// case as an extra container in the SAME pod as the primary container. +func (i *crictlInfo) startSideContainers() error { + if len(i.testArgs.SideContainers) == 0 { + return nil + } + + cwd, err := os.Getwd() + if err != nil { + return fmt.Errorf("Failed to get CWD to write side container configs: %v", err) + } + absPodConf := filepath.Join(cwd, podConfigFilename) + + for _, sc := range i.testArgs.SideContainers { + if sc.NetMode != sideContainerNetModeShared { + return fmt.Errorf("crictl does not support side container network mode %q: crictl has no named/user-defined network, only pod-shared networking (sideContainerNetModeShared)", sc.NetMode) + } + + absSideConf, err := crictlNewSideContainerConfig(cwd, sc) + if err != nil { + return err + } + + cmdBase := crictlName + " create " + i.podID + " " + absSideConf + " " + absPodConf + cID, err := commonCmdExec(cmdBase) + if err != nil { + return fmt.Errorf("failed to create side container %s: %s -- %v", sc.Name, cID, err) + } + if output, err := commonCmdExec(crictlName + " start " + cID); err != nil { + return fmt.Errorf("failed to start side container %s: %s -- %v", sc.Name, output, err) + } + i.sideContainerIDs = append(i.sideContainerIDs, cID) + } + return nil +} + func (i *crictlInfo) startContainer(bool) (string, error) { + if err := i.startSideContainers(); err != nil { + return "", err + } cmdBase := crictlName cmdBase += " start " cmdBase += i.containerID @@ -209,6 +282,9 @@ func (i *crictlInfo) startContainer(bool) (string, error) { } func (i *crictlInfo) runContainer(bool) (string, error) { + if err := i.startSideContainers(); err != nil { + return "", err + } cwd, err := os.Getwd() if err != nil { return "", fmt.Errorf("Failed to get CWD to write Container/Pod config: %v", err) @@ -234,6 +310,10 @@ func (i *crictlInfo) runContainer(bool) (string, error) { } func (i *crictlInfo) stopContainer() error { + if err := commonStopSideContainers(crictlName, i.sideContainerIDs); err != nil { + return err + } + output, err := commonStopContainer(crictlName, i.containerID) err = checkExpectedOut(i.containerID, output, err) if err != nil { @@ -257,6 +337,10 @@ func (i *crictlInfo) stopPod() error { } func (i *crictlInfo) rmContainer() error { + if err := commonRmSideContainers(crictlName, i.sideContainerIDs); err != nil { + return err + } + output, err := commonRmContainer(crictlName, i.containerID) err = checkExpectedOut(i.containerID, output, err) if err != nil { @@ -272,6 +356,13 @@ func (i *crictlInfo) rmContainer() error { if err != nil { return fmt.Errorf("Could not remove container config file: %v", err) } + + for _, sc := range i.testArgs.SideContainers { + absSideConf := filepath.Join(cwd, sc.Name+".json") + if err := os.Remove(absSideConf); err != nil { + return fmt.Errorf("Could not remove side container %s config file: %v", sc.Name, err) + } + } return nil } diff --git a/tests/e2e/crictl_test.go b/tests/e2e/crictl_test.go index 8973f870..6a109b8f 100644 --- a/tests/e2e/crictl_test.go +++ b/tests/e2e/crictl_test.go @@ -66,6 +66,10 @@ var _ = Describe("Crictl", Ordered, ContinueOnFailure, func() { } }) + if len(tc.SideContainers) > 0 { + runDetachedSideContainerTest(tool, tc) + return + } runDetachedTest(tool, tc) }, toTableEntries(crictlTestCases()), diff --git a/tests/e2e/ctr.go b/tests/e2e/ctr.go index b510259d..3f70988e 100644 --- a/tests/e2e/ctr.go +++ b/tests/e2e/ctr.go @@ -103,7 +103,18 @@ func (i *ctrInfo) startPod() (string, error) { return "", errToolDoesNotSupport } +func (i *ctrInfo) startSideContainers() error { + if len(i.testArgs.SideContainers) == 0 { + return nil + } + // Not supported by ctr + return errToolDoesNotSupport +} + func (i *ctrInfo) startContainer(detach bool) (string, error) { + if err := i.startSideContainers(); err != nil { + return "", err + } if detach { i.detached = true } @@ -111,6 +122,9 @@ func (i *ctrInfo) startContainer(detach bool) (string, error) { } func (i *ctrInfo) runContainer(detach bool) (string, error) { + if err := i.startSideContainers(); err != nil { + return "", err + } cmdBase := ctrName cmdBase += " run " if detach { diff --git a/tests/e2e/docker.go b/tests/e2e/docker.go index 9c0982a9..04f3f027 100644 --- a/tests/e2e/docker.go +++ b/tests/e2e/docker.go @@ -21,8 +21,9 @@ import ( const dockerName = "docker" type dockerInfo struct { - testArgs containerTestArgs - containerID string + testArgs containerTestArgs + containerID string + sideContainerIDs []string } func newDockerTool(args containerTestArgs) *dockerInfo { @@ -73,7 +74,20 @@ func (i *dockerInfo) startPod() (string, error) { } func (i *dockerInfo) startContainer(detach bool) (string, error) { - return commonStart(dockerName, i.containerID, detach) + output, err := commonStart(dockerName, i.containerID, detach) + if err != nil { + return output, err + } + if err := i.startSideContainers(); err != nil { + return output, err + } + return output, nil +} + +func (i *dockerInfo) startSideContainers() error { + ids, err := commonStartSideContainers(dockerName, i.testArgs, i.containerID) + i.sideContainerIDs = ids + return err } func (i *dockerInfo) runContainer(detach bool) (string, error) { @@ -81,6 +95,9 @@ func (i *dockerInfo) runContainer(detach bool) (string, error) { } func (i *dockerInfo) stopContainer() error { + if err := commonStopSideContainers(dockerName, i.sideContainerIDs); err != nil { + return err + } output, err := commonStopContainer(dockerName, i.containerID) err = checkExpectedOut(i.containerID, output, err) if err != nil { @@ -95,6 +112,9 @@ func (i *dockerInfo) stopPod() error { } func (i *dockerInfo) rmContainer() error { + if err := commonRmSideContainers(dockerName, i.sideContainerIDs); err != nil { + return err + } output, err := commonRmContainer(dockerName, i.containerID) err = checkExpectedOut(i.containerID, output, err) if err != nil { diff --git a/tests/e2e/docker_test.go b/tests/e2e/docker_test.go index 4d61ba07..84ccb4d2 100644 --- a/tests/e2e/docker_test.go +++ b/tests/e2e/docker_test.go @@ -47,6 +47,10 @@ var _ = Describe("Docker", Ordered, ContinueOnFailure, func() { func(tc containerTestArgs) { skipMissingVolumes(tc) tool = newDockerTool(tc) + if len(tc.SideContainers) > 0 { + runDetachedSideContainerTest(tool, tc) + return + } runDetachedTest(tool, tc) }, toTableEntries(dockerTestCases()), diff --git a/tests/e2e/nerdctl.go b/tests/e2e/nerdctl.go index 024e8379..c84643e4 100644 --- a/tests/e2e/nerdctl.go +++ b/tests/e2e/nerdctl.go @@ -21,8 +21,9 @@ import ( const nerdctlName = "nerdctl" type nerdctlInfo struct { - testArgs containerTestArgs - containerID string + testArgs containerTestArgs + containerID string + sideContainerIDs []string } func newNerdctlTool(args containerTestArgs) *nerdctlInfo { @@ -73,7 +74,20 @@ func (i *nerdctlInfo) startPod() (string, error) { } func (i *nerdctlInfo) startContainer(detach bool) (string, error) { - return commonStart(nerdctlName, i.containerID, detach) + output, err := commonStart(nerdctlName, i.containerID, detach) + if err != nil { + return output, err + } + if err := i.startSideContainers(); err != nil { + return output, err + } + return output, nil +} + +func (i *nerdctlInfo) startSideContainers() error { + ids, err := commonStartSideContainers(nerdctlName, i.testArgs, i.containerID) + i.sideContainerIDs = ids + return err } func (i *nerdctlInfo) runContainer(detach bool) (string, error) { @@ -81,6 +95,9 @@ func (i *nerdctlInfo) runContainer(detach bool) (string, error) { } func (i *nerdctlInfo) stopContainer() error { + if err := commonStopSideContainers(nerdctlName, i.sideContainerIDs); err != nil { + return err + } output, err := commonStopContainer(nerdctlName, i.containerID) err = checkExpectedOut(i.containerID, output, err) if err != nil { @@ -95,6 +112,9 @@ func (i *nerdctlInfo) stopPod() error { } func (i *nerdctlInfo) rmContainer() error { + if err := commonRmSideContainers(nerdctlName, i.sideContainerIDs); err != nil { + return err + } output, err := commonRmContainer(nerdctlName, i.containerID) err = checkExpectedOut(i.containerID, output, err) if err != nil { diff --git a/tests/e2e/nerdctl_test.go b/tests/e2e/nerdctl_test.go index 55431fd3..3a62f69b 100644 --- a/tests/e2e/nerdctl_test.go +++ b/tests/e2e/nerdctl_test.go @@ -59,6 +59,10 @@ var _ = Describe("Nerdctl", Ordered, ContinueOnFailure, func() { func(tc containerTestArgs) { skipMissingVolumes(tc) tool = newNerdctlTool(tc) + if len(tc.SideContainers) > 0 { + runDetachedSideContainerTest(tool, tc) + return + } runDetachedTest(tool, tc) }, toTableEntries(selectTestCases(nerdctlTestCases(), true)), diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go index 03d7db82..1a35a353 100644 --- a/tests/e2e/suite_test.go +++ b/tests/e2e/suite_test.go @@ -132,6 +132,42 @@ func runDetachedTest(tool testTool, tc containerTestArgs) { }, defaultTimeout, defaultInterval).Should(Succeed()) } +func runDetachedSideContainerTest(tool testTool, tc containerTestArgs) { + By("Creating container") + cID, err := tool.createContainer() + Expect(err).NotTo(HaveOccurred(), "Failed to create container: %s", cID) + tool.setContainerID(cID) + + DeferCleanup(func() { + if tool.getContainerID() != "" { + if CurrentSpecReport().Failed() { + captureContainerLogs(tool) + } + By("Stopping container") + if err := tool.stopContainer(); err != nil { + GinkgoLogr.Error(err, "Failed to stop container") + } + By("Removing container") + if err := tool.rmContainer(); err != nil { + GinkgoLogr.Error(err, "Failed to remove container") + } + By("Verifying container removal") + if err := testVerifyRm(tool); err != nil { + GinkgoLogr.Error(err, "Failed to verify removal") + } + } + }) + + By("Starting container") + output, err := tool.startContainer(true) + Expect(err).NotTo(HaveOccurred(), "Failed to start container: %s", output) + + By("Running test function") + Eventually(func() error { + return tc.TestFunc(tool) + }, defaultTimeout, defaultInterval).Should(Succeed()) +} + // runForegroundTest runs a container in the foreground and verifies the // output contains the expected string. func runForegroundTest(tool testTool, tc containerTestArgs) { diff --git a/tests/e2e/test_cases.go b/tests/e2e/test_cases.go index 3b90a381..fcd8213f 100644 --- a/tests/e2e/test_cases.go +++ b/tests/e2e/test_cases.go @@ -28,7 +28,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Hello world", TestFunc: matchTest, @@ -45,7 +45,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Hello world", TestFunc: matchTest, @@ -62,7 +62,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -78,7 +78,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -94,7 +94,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -110,7 +110,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -126,7 +126,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -142,7 +142,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: userGroupTest, }, @@ -158,7 +158,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -174,7 +174,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -190,7 +190,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: userGroupTest, }, @@ -206,7 +206,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -222,7 +222,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -238,7 +238,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -254,7 +254,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -270,7 +270,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -286,7 +286,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -302,7 +302,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -318,7 +318,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -334,7 +334,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -350,7 +350,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -366,7 +366,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: namespaceTest, }, @@ -384,7 +384,7 @@ func nerdctlTestCases() []containerTestArgs { {Source: "/tmp/test_mountpoint", Dest: "/mnt/data/mp"}, }, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "", TestFunc: blockMountTest, @@ -403,7 +403,7 @@ func nerdctlTestCases() []containerTestArgs { {Source: "/tmp/test_mountpoint", Dest: "/mnt/data/mp"}, }, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "", TestFunc: blockMountTest, @@ -420,7 +420,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -436,7 +436,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "/bin/busybox tail -f /dev/null", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -452,7 +452,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -468,7 +468,7 @@ func nerdctlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -489,7 +489,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Hello world", TestFunc: matchTest, @@ -506,7 +506,7 @@ func ctrTestCases() []containerTestArgs { Cli: "--hello=holaHola", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "holaHola", TestFunc: matchTest, @@ -523,7 +523,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Total tests passed: 10", TestFunc: matchTest, @@ -540,7 +540,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Hello world", TestFunc: matchTest, @@ -557,7 +557,7 @@ func ctrTestCases() []containerTestArgs { Cli: "--hello=Holahola", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Holahola", TestFunc: matchTest, @@ -574,7 +574,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Total tests passed: 10", TestFunc: matchTest, @@ -591,7 +591,7 @@ func ctrTestCases() []containerTestArgs { Cli: "hello Unikraft Qemu urunc", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "\"Unikraft\" \"Qemu\" \"urunc\"", TestFunc: matchTest, @@ -608,7 +608,7 @@ func ctrTestCases() []containerTestArgs { Cli: "hello Unikraft FC urunc", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "\"Unikraft\" \"FC\" \"urunc\"", TestFunc: matchTest, @@ -625,7 +625,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Hello from C on Hyperlight!", TestFunc: matchTest, @@ -642,7 +642,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "URUNC=urunc", TestFunc: matchTest, @@ -659,7 +659,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Once upon a time", TestFunc: matchTest, @@ -676,7 +676,7 @@ func ctrTestCases() []containerTestArgs { Cli: "/urunit /clis Linux Qemu urunc", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Linux Qemu urunc", TestFunc: matchTest, @@ -693,7 +693,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Once upon a time", TestFunc: matchTest, @@ -710,7 +710,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "UID: 0 GID: 17 WD: /test_dir URUNC: urunc", TestFunc: matchTest, @@ -727,7 +727,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "URUNC=urunc", TestFunc: matchTest, @@ -744,7 +744,7 @@ func ctrTestCases() []containerTestArgs { Cli: "/urunit /clis Linux FC urunc", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Linux FC urunc", TestFunc: matchTest, @@ -761,7 +761,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "UID: 0 GID: 42 WD: /test_dir URUNC: urunc", TestFunc: matchTest, @@ -778,7 +778,7 @@ func ctrTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, ExpectOut: "Hello, world!", TestFunc: matchTest, @@ -800,7 +800,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -816,7 +816,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -832,7 +832,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -848,7 +848,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -864,7 +864,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: userGroupTest, }, @@ -880,7 +880,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -896,7 +896,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -912,7 +912,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -928,7 +928,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -944,7 +944,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -960,7 +960,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: true, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: httpStaticNetTest, }, @@ -976,7 +976,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: namespaceTest, }, @@ -992,7 +992,7 @@ func crictlTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: userGroupTest, }, @@ -1013,7 +1013,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1029,7 +1029,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: userGroupTest, }, @@ -1045,7 +1045,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1061,7 +1061,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1077,7 +1077,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1093,7 +1093,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1109,7 +1109,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1125,7 +1125,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -1141,7 +1141,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -1157,7 +1157,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: userGroupTest, }, @@ -1173,7 +1173,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1189,7 +1189,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: pingTest, }, @@ -1205,7 +1205,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -1221,7 +1221,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: seccompTest, }, @@ -1237,7 +1237,7 @@ func dockerTestCases() []containerTestArgs { Cli: "", Volumes: []containerVolume{}, StaticNet: false, - SideContainers: []string{}, + SideContainers: []sideContainer{}, Skippable: false, TestFunc: namespaceTest, }, diff --git a/tests/e2e/utils.go b/tests/e2e/utils.go index b8372557..706d6fbe 100644 --- a/tests/e2e/utils.go +++ b/tests/e2e/utils.go @@ -36,6 +36,9 @@ func getTestImages(cases []containerTestArgs) []string { unique := make(map[string]struct{}) for _, tc := range cases { unique[tc.Image] = struct{}{} + for _, sc := range tc.SideContainers { + unique[sc.Image] = struct{}{} + } } images := make([]string, 0, len(unique))