Skip to content

Commit

Permalink
Merge pull request #2647 from adshmh/add-exec-option-to-tmpfs
Browse files Browse the repository at this point in the history
add exec option to tmpfs
  • Loading branch information
dperny committed Nov 5, 2018
2 parents 3973628 + 0c73108 commit bc032e2
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 323 deletions.
12 changes: 12 additions & 0 deletions agent/exec/dockerapi/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ func getMountMask(m *api.Mount) string {

maskOpts = append(maskOpts, fmt.Sprintf("size=%d%s", size, suffix))
}

if opts := m.TmpfsOptions.Options; opts != "" {
validOpts := map[string]bool{
"exec": true,
"noexec": true,
}
for _, opt := range strings.Split(strings.ToLower(opts), ",") {
if _, ok := validOpts[opt]; ok {
maskOpts = append(maskOpts, opt)
}
}
}
}

return strings.Join(maskOpts, ",")
Expand Down
36 changes: 36 additions & 0 deletions agent/exec/dockerapi/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@ func TestVolumesAndBinds(t *testing.T) {
}
}

func TestTmpfsOptions(t *testing.T) {
type testCase struct {
explain string
config api.Mount
x string
}

cases := []testCase{
{"Tmpfs mount with exec option", api.Mount{Type: api.MountTypeTmpfs, Target: "/kerfluffle", TmpfsOptions: &api.Mount_TmpfsOptions{Options: "exec"}}, "exec"},
{"Tmpfs mount with noexec option", api.Mount{Type: api.MountTypeTmpfs, Target: "/kerfluffle", TmpfsOptions: &api.Mount_TmpfsOptions{Options: "noexec"}}, "noexec"},
}

for _, c := range cases {
cfg := containerConfig{
task: &api.Task{
Spec: api.TaskSpec{Runtime: &api.TaskSpec_Container{
Container: &api.ContainerSpec{
Mounts: []api.Mount{c.config},
},
}},
},
}

mountOpts, ok := cfg.hostConfig().Tmpfs["/kerfluffle"]
if !ok {
t.Fatalf("expected 1 mount, found none")
}

if mountOpts != c.x {
t.Log(c.explain)
t.Logf("expected Tmpfs opts: %+v, got: %+v", c.x, mountOpts)
t.Fail()
}
}
}

func TestHealthcheck(t *testing.T) {
c := containerConfig{
task: &api.Task{
Expand Down
7 changes: 7 additions & 0 deletions api/api.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,13 @@ file {
}
json_name: "mode"
}
field {
name: "options"
number: 3
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "options"
}
}
enum_type {
name: "Type"
Expand Down
Loading

0 comments on commit bc032e2

Please sign in to comment.