Add local volume support to container filters

This commit is contained in:
Jonathan Wong
2019-11-21 12:16:09 -08:00
parent ff60138efd
commit a7cff1c75b
3 changed files with 43 additions and 58 deletions

View File

@@ -33,6 +33,9 @@ type ContainerFilter struct {
// Network is the container network to use.
Network string `yaml:"network,omitempty"`
// LocalVolume is the volume the container uses.
LocalVolume string `yaml:"localVolume,omitempty"`
// Config is the API configuration for the container and passed through the
// API_CONFIG env var to the container.
// Typically a Kubernetes style Resource Config.
@@ -110,6 +113,10 @@ func (c *ContainerFilter) getArgs() []string {
args = append(args, "-v", fmt.Sprintf("%s:/local/:ro", c.mountPath))
}
if c.LocalVolume != "" {
args = append(args, "--mount", fmt.Sprintf("'type=volume,src=%s,dst=/local/'", c.LocalVolume))
}
// export the local environment vars to the container
for _, pair := range os.Environ() {
args = append(args, "-e", strings.Split(pair, "=")[0])

View File

@@ -99,6 +99,42 @@ metadata:
assert.Equal(t, expected, cmd.Args)
}
func TestFilter_command_LocalVolume(t *testing.T) {
cfg, err := yaml.Parse(`apiversion: apps/v1
kind: Deployment
metadata:
name: foo
`)
if !assert.NoError(t, err) {
return
}
instance := &ContainerFilter{
Image: "example.com:version",
Config: cfg,
LocalVolume: "myvol",
}
cmd, err := instance.getCommand()
if !assert.NoError(t, err) {
return
}
expected := []string{
"docker", "run",
"--rm",
"-i", "-a", "STDIN", "-a", "STDOUT", "-a", "STDERR",
"--network", "none",
"--user", "nobody",
"--security-opt=no-new-privileges",
"--mount", fmt.Sprintf("'type=volume,src=%s,dst=/local/'", "myvol"),
}
for _, e := range os.Environ() {
// the process env
expected = append(expected, "-e", strings.Split(e, "=")[0])
}
expected = append(expected, "example.com:version")
assert.Equal(t, expected, cmd.Args)
}
func TestFilter_command_network(t *testing.T) {
cfg, err := yaml.Parse(`apiversion: apps/v1
kind: Deployment