rkt: Expand environment variables in Command and Args.

This commit is contained in:
Yifan Gu 2016-01-27 23:14:50 -08:00
parent eb2c2d1af4
commit dcee692d64
2 changed files with 11 additions and 9 deletions

View File

@ -417,12 +417,12 @@ func setSupplementaryGIDs(app *appctypes.App, podCtx *api.PodSecurityContext) {
// setApp merges the container spec with the image's manifest. // setApp merges the container spec with the image's manifest.
func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContainerOptions, ctx *api.SecurityContext, podCtx *api.PodSecurityContext) error { func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContainerOptions, ctx *api.SecurityContext, podCtx *api.PodSecurityContext) error {
// Override the exec. // TODO(yifan): If ENTRYPOINT and CMD are both specified in the image,
if len(c.Command) > 0 { // we cannot override just one of these at this point as they are already mixed.
app.Exec = c.Command command, args := kubecontainer.ExpandContainerCommandAndArgs(c, opts.Envs)
} exec := append(command, args...)
if len(c.Args) > 0 { if len(exec) > 0 {
app.Exec = append(app.Exec, c.Args...) app.Exec = exec
} }
// Set UID and GIDs. // Set UID and GIDs.

View File

@ -863,8 +863,8 @@ func TestSetApp(t *testing.T) {
// app should be changed. (env, mounts, ports, are overrided). // app should be changed. (env, mounts, ports, are overrided).
{ {
container: &api.Container{ container: &api.Container{
Command: []string{"/bin/bar"}, Command: []string{"/bin/bar", "$(env-foo)"},
Args: []string{"hello", "world"}, Args: []string{"hello", "world", "$(env-bar)"},
WorkingDir: tmpDir, WorkingDir: tmpDir,
Resources: api.ResourceRequirements{ Resources: api.ResourceRequirements{
Limits: api.ResourceList{"cpu": resource.MustParse("50m"), "memory": resource.MustParse("50M")}, Limits: api.ResourceList{"cpu": resource.MustParse("50m"), "memory": resource.MustParse("50M")},
@ -874,6 +874,7 @@ func TestSetApp(t *testing.T) {
opts: &kubecontainer.RunContainerOptions{ opts: &kubecontainer.RunContainerOptions{
Envs: []kubecontainer.EnvVar{ Envs: []kubecontainer.EnvVar{
{Name: "env-foo", Value: "foo"}, {Name: "env-foo", Value: "foo"},
{Name: "env-bar", Value: "bar"},
}, },
Mounts: []kubecontainer.Mount{ Mounts: []kubecontainer.Mount{
{Name: "mnt-foo", ContainerPath: "/mnt-bar", ReadOnly: true}, {Name: "mnt-foo", ContainerPath: "/mnt-bar", ReadOnly: true},
@ -895,13 +896,14 @@ func TestSetApp(t *testing.T) {
FSGroup: &fsgid, FSGroup: &fsgid,
}, },
expect: &appctypes.App{ expect: &appctypes.App{
Exec: appctypes.Exec{"/bin/bar", "hello", "world"}, Exec: appctypes.Exec{"/bin/bar", "foo", "hello", "world", "bar"},
User: "42", User: "42",
Group: "22", Group: "22",
SupplementaryGIDs: []int{1, 2, 3}, SupplementaryGIDs: []int{1, 2, 3},
WorkingDirectory: tmpDir, WorkingDirectory: tmpDir,
Environment: []appctypes.EnvironmentVariable{ Environment: []appctypes.EnvironmentVariable{
{"env-foo", "foo"}, {"env-foo", "foo"},
{"env-bar", "bar"},
}, },
MountPoints: []appctypes.MountPoint{ MountPoints: []appctypes.MountPoint{
{Name: *appctypes.MustACName("mnt-foo"), Path: "/mnt-bar", ReadOnly: true}, {Name: *appctypes.MustACName("mnt-foo"), Path: "/mnt-bar", ReadOnly: true},