rkt: Support ENTRYPOINT/CMD substitution.
This commit is contained in:
@@ -717,7 +717,7 @@ func generateMemoryIsolator(t *testing.T, request, limit string) appctypes.Isola
|
||||
|
||||
func baseApp(t *testing.T) *appctypes.App {
|
||||
return &appctypes.App{
|
||||
Exec: appctypes.Exec{"/bin/foo"},
|
||||
Exec: appctypes.Exec{"/bin/foo", "bar"},
|
||||
SupplementaryGIDs: []int{4, 5, 6},
|
||||
WorkingDirectory: "/foo",
|
||||
Environment: []appctypes.EnvironmentVariable{
|
||||
@@ -738,6 +738,13 @@ func baseApp(t *testing.T) *appctypes.App {
|
||||
}
|
||||
}
|
||||
|
||||
func baseImageManifest(t *testing.T) *appcschema.ImageManifest {
|
||||
img := &appcschema.ImageManifest{App: baseApp(t)}
|
||||
img.Annotations.Set(*appctypes.MustACIdentifier(appcDockerEntrypoint), "/bin/foo")
|
||||
img.Annotations.Set(*appctypes.MustACIdentifier(appcDockerCmd), "bar")
|
||||
return img
|
||||
}
|
||||
|
||||
func baseAppWithRootUserGroup(t *testing.T) *appctypes.App {
|
||||
app := baseApp(t)
|
||||
app.User, app.Group = "0", "0"
|
||||
@@ -818,11 +825,43 @@ func TestSetApp(t *testing.T) {
|
||||
err: fmt.Errorf("container has no runAsUser and image will run as root"),
|
||||
},
|
||||
|
||||
// app's args should be changed.
|
||||
{
|
||||
container: &api.Container{
|
||||
Args: []string{"foo"},
|
||||
},
|
||||
opts: &kubecontainer.RunContainerOptions{},
|
||||
ctx: nil,
|
||||
podCtx: nil,
|
||||
expect: &appctypes.App{
|
||||
Exec: appctypes.Exec{"/bin/foo", "foo"},
|
||||
User: "0",
|
||||
Group: "0",
|
||||
SupplementaryGIDs: []int{4, 5, 6},
|
||||
WorkingDirectory: "/foo",
|
||||
Environment: []appctypes.EnvironmentVariable{
|
||||
{"env-foo", "bar"},
|
||||
},
|
||||
MountPoints: []appctypes.MountPoint{
|
||||
{Name: *appctypes.MustACName("mnt-foo"), Path: "/mnt-foo", ReadOnly: false},
|
||||
},
|
||||
Ports: []appctypes.Port{
|
||||
{Name: *appctypes.MustACName("port-foo"), Protocol: "TCP", Port: 4242},
|
||||
},
|
||||
Isolators: []appctypes.Isolator{
|
||||
generateCapRetainIsolator(t, "CAP_SYS_ADMIN"),
|
||||
generateCapRevokeIsolator(t, "CAP_NET_ADMIN"),
|
||||
generateCPUIsolator(t, "100m", "200m"),
|
||||
generateMemoryIsolator(t, "10M", "20M"),
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
|
||||
// app should be changed.
|
||||
{
|
||||
container: &api.Container{
|
||||
Command: []string{"/bin/bar"},
|
||||
Args: []string{"hello", "world"},
|
||||
Command: []string{"/bin/bar", "$(env-bar)"},
|
||||
WorkingDir: tmpDir,
|
||||
Resources: api.ResourceRequirements{
|
||||
Limits: api.ResourceList{"cpu": resource.MustParse("50m"), "memory": resource.MustParse("50M")},
|
||||
@@ -853,7 +892,7 @@ func TestSetApp(t *testing.T) {
|
||||
FSGroup: &fsgid,
|
||||
},
|
||||
expect: &appctypes.App{
|
||||
Exec: appctypes.Exec{"/bin/bar", "hello", "world"},
|
||||
Exec: appctypes.Exec{"/bin/bar", "foo"},
|
||||
User: "42",
|
||||
Group: "0",
|
||||
SupplementaryGIDs: []int{1, 2, 3},
|
||||
@@ -883,7 +922,7 @@ func TestSetApp(t *testing.T) {
|
||||
{
|
||||
container: &api.Container{
|
||||
Name: "hello-world",
|
||||
Command: []string{"/bin/bar", "$(env-foo)"},
|
||||
Command: []string{"/bin/hello", "$(env-foo)"},
|
||||
Args: []string{"hello", "world", "$(env-bar)"},
|
||||
WorkingDir: tmpDir,
|
||||
Resources: api.ResourceRequirements{
|
||||
@@ -916,7 +955,7 @@ func TestSetApp(t *testing.T) {
|
||||
FSGroup: &fsgid,
|
||||
},
|
||||
expect: &appctypes.App{
|
||||
Exec: appctypes.Exec{"/bin/bar", "foo", "hello", "world", "bar"},
|
||||
Exec: appctypes.Exec{"/bin/hello", "foo", "hello", "world", "bar"},
|
||||
User: "42",
|
||||
Group: "0",
|
||||
SupplementaryGIDs: []int{1, 2, 3},
|
||||
@@ -943,15 +982,15 @@ func TestSetApp(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
testCaseHint := fmt.Sprintf("test case #%d", i)
|
||||
app := baseApp(t)
|
||||
err := setApp(app, tt.container, tt.opts, tt.ctx, tt.podCtx)
|
||||
img := baseImageManifest(t)
|
||||
err := setApp(img, tt.container, tt.opts, tt.ctx, tt.podCtx)
|
||||
if err == nil && tt.err != nil || err != nil && tt.err == nil {
|
||||
t.Errorf("%s: expect %v, saw %v", testCaseHint, tt.err, err)
|
||||
}
|
||||
if err == nil {
|
||||
sortAppFields(tt.expect)
|
||||
sortAppFields(app)
|
||||
assert.Equal(t, tt.expect, app, testCaseHint)
|
||||
sortAppFields(img.App)
|
||||
assert.Equal(t, tt.expect, img.App, testCaseHint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user