Skip to content

Commit

Permalink
Merge pull request moby#2350 from AliyunContainerService/init-support
Browse files Browse the repository at this point in the history
Suppor the init for container spec
  • Loading branch information
nishanttotla authored Aug 17, 2017
2 parents 6716ddf + fe60f09 commit 3882d21
Show file tree
Hide file tree
Showing 4 changed files with 356 additions and 159 deletions.
10 changes: 10 additions & 0 deletions agent/exec/dockerapi/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig {
Tmpfs: c.tmpfs(),
GroupAdd: c.spec().Groups,
PortBindings: c.portBindings(),
Init: c.init(),
}

// The format of extra hosts on swarmkit is specified in:
Expand Down Expand Up @@ -531,3 +532,12 @@ func (c containerConfig) eventFilter() filters.Args {
filter.Add("label", fmt.Sprintf("%v.task.id=%v", systemLabelPrefix, c.task.ID))
return filter
}

func (c *containerConfig) init() *bool {
init := c.spec().GetInit()
if init != nil {
value := c.spec().GetInitValue()
return &value
}
return nil
}
24 changes: 24 additions & 0 deletions agent/exec/dockerapi/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,27 @@ func TestStopSignal(t *testing.T) {
t.Fatalf("expected %s, got %s", expected, actual)
}
}

func TestInit(t *testing.T) {
c := containerConfig{
task: &api.Task{
Spec: api.TaskSpec{Runtime: &api.TaskSpec_Container{
Container: &api.ContainerSpec{
StopSignal: "SIGWINCH",
},
}},
},
}
expected := (*bool)(nil)
actual := c.hostConfig().Init
if actual != expected {
t.Fatalf("expected %v, got %v", expected, actual)
}
c.task.Spec.GetContainer().Init = &api.ContainerSpec_InitValue{
InitValue: true,
}
actual = c.hostConfig().Init
if actual == nil || !*actual {
t.Fatalf("expected &true, got %v", actual)
}
}
Loading

0 comments on commit 3882d21

Please sign in to comment.