mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Add local volume support to container filters
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user