Skip to content

Commit

Permalink
Config Changes (#31)
Browse files Browse the repository at this point in the history
* Remove duplicate input fields

* Updated tests

Removed godotenv, made it use the podman version in path instead of hard-coded path, and disabled a test when not on linux

* Fixed test, and add note for Mac OS users

* Update to arcalot-owned, stable image

---------

Signed-off-by: Dustin Black <[email protected]>
Co-authored-by: Dustin Black <[email protected]>
  • Loading branch information
jaredoconnell and dustinblack authored Nov 21, 2023
1 parent 099427e commit 88b8a20
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 110 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ FROM quay.io/centos/centos:stream8@sha256:ce6ec049788dd34c9fd99cf6c319a1cc695799
COPY tests/test_script.sh /
RUN dnf install net-tools -y

ENTRYPOINT [ "bash", "test_script.sh" ]
ENTRYPOINT [ "bash", "test_script.sh" ]
5 changes: 1 addition & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ type Podman struct {
Path string `json:"path"`
// Constant prefix prepended to the randomized container name string.
ContainerNamePrefix string `json:"containerNamePrefix"`
CgroupNs string `json:"cgroupNs"`
NetworkMode string `json:"networkMode"`
ImageArchitecture string `json:"imageArchitecture"`
ImageOS string `json:"imageOS"`
// The initial integer that is the starting point for a
// Random Number Generator's algorithm.
RngSeed int64 `json:"rngSeed"`
Expand All @@ -48,6 +44,7 @@ type Deployment struct {
ContainerConfig *container.Config `json:"container"`
HostConfig *container.HostConfig `json:"host"`
ImagePullPolicy ImagePullPolicy `json:"imagePullPolicy"`
ImagePlatform *string `json:"imagePlatform"`
}

// Timeouts drive the timeouts for various interactions in relation to Docker.
Expand Down
12 changes: 4 additions & 8 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (c *Connector) Deploy(ctx context.Context, image string) (deployer.Plugin,
SetContainerName(containerName).
SetEnv(containerConfig.Env).
SetVolumes(hostConfig.Binds).
SetCgroupNs(c.config.Podman.CgroupNs).
SetNetworkMode(c.config.Podman.NetworkMode)
SetCgroupNs(string(hostConfig.CgroupnsMode)).
SetNetworkMode(string(hostConfig.NetworkMode))

stdin, stdout, err := c.podmanCliWrapper.Deploy(image, commandArgs, []string{"--atp"})

Expand All @@ -74,19 +74,15 @@ func (c *Connector) pullImage(_ context.Context, image string) error {
}
if c.config.Deployment.ImagePullPolicy == ImagePullPolicyIfNotPresent {
imageExists, err := c.podmanCliWrapper.ImageExists(image)
podmanPlatform := c.config.Podman.ImageOS + "/" + c.config.Podman.ImageArchitecture
if err != nil {
return err
}

if *imageExists {
c.logger.Debugf("%s: image already present skipping pull", image)
return nil
}
// TODO:fix default values in configuration

c.logger.Debugf("Pulling image: %s", image)
if err := c.podmanCliWrapper.PullImage(image, &podmanPlatform); err != nil {
c.logger.Debugf("Pulling image '%s'", image)
if err := c.podmanCliWrapper.PullImage(image, c.config.Deployment.ImagePlatform); err != nil {
return err
}
}
Expand Down
81 changes: 50 additions & 31 deletions connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"os/exec"
"runtime"
"strings"
"sync"
"testing"
Expand All @@ -29,13 +30,17 @@ func getConnector(t *testing.T, configJSON string) (deployer.Connector, *Config)
assert.NoError(t, err)
connector, err := factory.Create(unserializedConfig, log.NewTestLogger(t))
assert.NoError(t, err)
unserializedConfig.Podman.Path, err = binaryCheck(unserializedConfig.Podman.Path)
if err != nil {
t.Fatalf("Error checking Podman path (%s)", err)
}
return connector, unserializedConfig
}

var inOutConfig = `
{
"podman":{
"path":"/usr/bin/podman"
"path":"podman"
}
}
`
Expand All @@ -48,7 +53,7 @@ func TestSimpleInOut(t *testing.T) {
connector, _ := getConnector(t, inOutConfig)
plugin, err := connector.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var containerInput = []byte("ping abc\n")
Expand All @@ -74,30 +79,29 @@ var envConfig = `
{
"deployment":{
"container":{
"NetworkDisabled":true,
"Env":[
"DEPLOYER_PODMAN_TEST_1=TEST1",
"DEPLOYER_PODMAN_TEST_2=TEST2"
]
}
},
"podman":{
"path":"/usr/bin/podman"
"path":"podman"
}
}
`

func TestEnv(t *testing.T) {
envVars := "DEPLOYER_PODMAN_TEST_1=TEST1\nDEPLOYER_PODMAN_TEST_2=TEST2"
connector, _ := getConnector(t, envConfig)
container, err := connector.Deploy(context.Background(), "quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
container, err := connector.Deploy(context.Background(), "quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var containerInput = []byte("env\n")
assert.NoErrorR[int](t)(container.Write(containerInput))

readBuffer := readOutputUntil(t, container, envVars)
assert.Equals(t, len(readBuffer) > 0, true)
assert.GreaterThan(t, len(readBuffer), 0)

t.Cleanup(func() {
assert.NoError(t, container.Close())
Expand All @@ -114,7 +118,7 @@ var volumeConfig = `
}
},
"podman":{
"path":"/usr/bin/podman"
"path":"podman"
}
}
`
Expand All @@ -131,20 +135,21 @@ func TestSimpleVolume(t *testing.T) {
cmd := exec.Command("chcon", "-Rt", "svirt_sandbox_file_t", fmt.Sprintf("%s/tests/volume", cwd)) //nolint:gosec
err = cmd.Run()
if err != nil {
logger.Warningf("failed to set SELinux permissions on folder, chcon error: %s, this may cause test failure, let's see...", err.Error())
logger.Warningf("failed to set SELinux permissions on folder, chcon error: %s, this may cause test failure if SELinux is enabled.", err.Error())
}

container, err := connector.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var containerInput = []byte("volume\n")
_, err = container.Write(containerInput)
assert.NoError(t, err)

// Note: If it ends up with length zero buffer, restarting the VM may help:
// https://stackoverflow.com/questions/71977532/podman-mount-host-volume-return-error-statfs-no-such-file-or-directory-in-ma
readBuffer := readOutputUntil(t, container, string(fileContent))
assert.Equals(t, len(readBuffer) > 0, true)
assert.GreaterThan(t, len(readBuffer), 0)

t.Cleanup(func() {
assert.NoError(t, container.Close())
Expand All @@ -154,7 +159,7 @@ func TestSimpleVolume(t *testing.T) {
var nameTemplate = `
{
"podman":{
"path":"/usr/bin/podman",
"path":"podman",
"containerNamePrefix":"%s"
}
}
Expand All @@ -171,12 +176,12 @@ func TestContainerName(t *testing.T) {

container1, err := connector1.Deploy(
ctx,
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

container2, err := connector2.Deploy(
ctx,
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var wg sync.WaitGroup
Expand Down Expand Up @@ -207,9 +212,13 @@ func TestContainerName(t *testing.T) {
var cgroupTemplate = `
{
"podman":{
"path":"/usr/bin/podman",
"containerNamePrefix":"%s",
"cgroupNs":"%s"
"path":"podman",
"containerNamePrefix":"%s"
},
"deployment":{
"host":{
"CgroupnsMode":"%s"
}
}
}
`
Expand All @@ -226,7 +235,7 @@ func TestCgroupNsByContainerName(t *testing.T) {
connector1, config := getConnector(t, configtemplate1)
container1, err := connector1.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

containerNamePrefix2 := "test_2"
Expand All @@ -235,7 +244,7 @@ func TestCgroupNsByContainerName(t *testing.T) {
connector2, _ := getConnector(t, configtemplate2)
container2, err := connector2.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var wg sync.WaitGroup
Expand Down Expand Up @@ -271,7 +280,8 @@ func TestPrivateCgroupNs(t *testing.T) {
logger := log.NewTestLogger(t)

var wg sync.WaitGroup
userCgroupNs := tests.GetCommmandCgroupNs(logger, "/usr/bin/sleep", []string{"3"})
// Assume sleep is in the path. Because it's not in the same location for every user.
userCgroupNs := tests.GetCommmandCgroupNs(logger, "sleep", []string{"3"})
assert.NotNil(t, userCgroupNs)
logger.Debugf("Detected cgroup namespace for user: %s", userCgroupNs)

Expand All @@ -281,7 +291,7 @@ func TestPrivateCgroupNs(t *testing.T) {
connector, config := getConnector(t, configtemplate)
container, err := connector.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

wg.Add(1)
Expand All @@ -304,10 +314,15 @@ func TestPrivateCgroupNs(t *testing.T) {
}

func TestHostCgroupNs(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skipf("Not running on Linux. Skipping cgroup test.")
return
}
logger := log.NewTestLogger(t)
var wg sync.WaitGroup

userCgroupNs := tests.GetCommmandCgroupNs(logger, "/usr/bin/sleep", []string{"3"})
// Assume sleep is in the path. Because it's not in the same location for every user.
userCgroupNs := tests.GetCommmandCgroupNs(logger, "sleep", []string{"3"})
assert.NotNil(t, userCgroupNs)

logger.Debugf("Detected cgroup namespace for user: %s", userCgroupNs)
Expand All @@ -317,7 +332,7 @@ func TestHostCgroupNs(t *testing.T) {
connector, config := getConnector(t, configtemplate)
container, err := connector.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

wg.Add(1)
Expand All @@ -334,7 +349,7 @@ func TestHostCgroupNs(t *testing.T) {
assert.NotNil(t, podmanCgroupNs)
wg.Wait()

assert.Equals(t, userCgroupNs == podmanCgroupNs, true)
assert.Equals(t, userCgroupNs, podmanCgroupNs)

t.Cleanup(func() {
assert.NoError(t, container.Close())
Expand All @@ -350,7 +365,7 @@ func TestCgroupNsByNamespacePath(t *testing.T) {
// The first container will run with a private namespace that will be created at startup
configtemplate1 := fmt.Sprintf(cgroupTemplate, containerNamePrefix1, "private")
connector1, config := getConnector(t, configtemplate1)
container1, err := connector1.Deploy(context.Background(), "quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
container1, err := connector1.Deploy(context.Background(), "quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var wg sync.WaitGroup
Expand All @@ -374,7 +389,7 @@ func TestCgroupNsByNamespacePath(t *testing.T) {

container2, err := connector2.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

wg.Add(1)
Expand All @@ -400,8 +415,12 @@ var networkTemplate = `
{
"podman":{
"containerNamePrefix":"%s",
"path":"/usr/bin/podman",
"networkMode":"%s"
"path":"podman"
},
"deployment":{
"host":{
"NetworkMode":"%s"
}
}
}
`
Expand All @@ -414,7 +433,7 @@ func TestNetworkHost(t *testing.T) {
connector, _ := getConnector(t, configtemplate)
plugin, err := connector.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var containerInput = []byte("network host\n")
Expand Down Expand Up @@ -475,7 +494,7 @@ func TestClose(t *testing.T) {

container, err := connector.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var wg sync.WaitGroup
Expand Down Expand Up @@ -532,7 +551,7 @@ func testNetworking(t *testing.T, podmanNetworking string, containerTest string,
connector, _ := getConnector(t, configtemplate)
plugin, err := connector.Deploy(
context.Background(),
"quay.io/tsebastiani/arcaflow-engine-deployer-podman-test:latest")
"quay.io/arcalot/podman-deployer-test-helper:0.1.0")
assert.NoError(t, err)

var containerInput = []byte(containerTest)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.18
require (
github.com/docker/docker v24.0.7+incompatible
github.com/docker/go-connections v0.4.0
github.com/joho/godotenv v1.5.1
go.arcalot.io/assert v1.6.0
go.arcalot.io/lang v1.0.0
go.flow.arcalot.io/deployer v0.4.0
Expand Down
Loading

0 comments on commit 88b8a20

Please sign in to comment.