Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Add Init field
Browse files Browse the repository at this point in the history
  • Loading branch information
imikushin authored and Denise Schannon committed Jul 11, 2017
1 parent 0da770e commit d368cbb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/compute/compute_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ func setupFieldsHostConfig(fields model.InstanceFields, hostConfig *container.Ho

hostConfig.Sysctls = fields.Sysctls

hostConfig.Init = fields.Init

hostConfig.StorageOpt = fields.StorageOpt

hostConfig.PidsLimit = fields.PidsLimit
Expand Down
51 changes: 51 additions & 0 deletions handlers/compute_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,57 @@ func (s *ComputeTestSuite) TestNewFieldsExtra(c *check.C) {
}
}

// need docker daemon with version 1.13.1
func (s *ComputeTestSuite) TestNewFieldsExtra_1_13(c *check.C) {
dockerClient := docker.GetClient(docker.DefaultVersion)
version, err := dockerClient.ServerVersion(context.Background())
if err != nil {
c.Fatal(err)
}
if version.Version == "1.13.1" {
deleteContainer("/c861f990-4472-4fa1-960f-65171b544c28")
rawEvent := loadEvent("./test_events/instance_activate_basic", c)
event, _, fields := unmarshalEventAndInstanceFields(rawEvent, c)
fields["sysctls"] = map[string]string{
"net.ipv4.ip_forward": "1",
}
fields["init"] = true
fields["tmpfs"] = map[string]string{
"/run": "rw,noexec,nosuid,size=65536k",
}
fields["healthCmd"] = []string{
"ls",
}
fields["usernsMode"] = "host"
fields["healthInterval"] = 5
fields["healthRetries"] = 3
fields["healthTimeout"] = 60
rawEvent = marshalEvent(event, c)
reply := testEvent(rawEvent, c)
cont, ok := utils.GetFieldsIfExist(reply.Data, "instanceHostMap", "instance", "+data", "dockerContainer")
if !ok {
c.Fatal("No id found")
}
inspect, err := dockerClient.ContainerInspect(context.Background(), cont.(types.Container).ID)
if err != nil {
c.Fatal("Inspect Err")
}
c.Assert(inspect.HostConfig.Sysctls, check.DeepEquals, map[string]string{
"net.ipv4.ip_forward": "1",
})
c.Assert(inspect.Config.Healthcheck.Test, check.DeepEquals, []string{"ls"})
c.Assert(inspect.Config.Healthcheck.Retries, check.Equals, 3)
c.Assert(inspect.Config.Healthcheck.Timeout, check.Equals, time.Duration(60)*time.Second)
c.Assert(inspect.Config.Healthcheck.Interval, check.Equals, time.Duration(5)*time.Second)
c.Assert(inspect.HostConfig.Tmpfs, check.DeepEquals, map[string]string{
"/run": "rw,noexec,nosuid,size=65536k",
})
c.Assert(inspect.HostConfig.UsernsMode, check.Equals, container.UsernsMode("host"))
c.Assert(inspect.HostConfig.Init, check.NotNil)
c.Assert(*inspect.HostConfig.Init, check.Equals, true)
}
}

func (s *ComputeTestSuite) TestInstanceActivateAgent(c *check.C) {
constants.ConfigOverride["CONFIG_URL"] = "https://localhost:1234/a/path"
deleteContainer("/c861f990-4472-4fa1-960f-65171b544c28")
Expand Down
2 changes: 2 additions & 0 deletions model/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type HostConfig struct {
UsernsMode container.UsernsMode // The user namespace to use for the container
ShmSize int64 // Total shm memory usage
Sysctls map[string]string `json:",omitempty"` // List of Namespaced sysctls used for the container
Init *bool `json:",omitempty"` // Should init be run in the container
Runtime string `json:",omitempty"` // Runtime to use with this container

// Applicable to Windows
Expand Down Expand Up @@ -229,6 +230,7 @@ type InstanceFields struct {
StopSignal string
User string
Sysctls map[string]string
Init *bool
HealthCmd []string
HealthTimeout int
HealthInterval int
Expand Down

0 comments on commit d368cbb

Please sign in to comment.