Skip to content

Commit

Permalink
Merge pull request #767 from wangforthinker/dev-rich-container-v1
Browse files Browse the repository at this point in the history
feature: add rich container mode
  • Loading branch information
Letty5411 committed Feb 27, 2018
2 parents de4297b + 18937f6 commit de8b526
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 1 deletion.
30 changes: 29 additions & 1 deletion apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,21 @@ definitions:
type: "array"
items:
type: "string"

Rich:
type: "boolean"
description: "Whether to start container in rich container mode. (default false)"
x-nullable: false
RichMode:
type: "string"
description: "Choose one rich container mode.(default dumb-init)"
enum:
- "dumb-init"
- "sbin-init"
- "systemd"
InitScript:
type: "string"
description: "Initial script executed in container. The script will be executed before entrypoint or command"

ContainerCreateResp:
description: "response returned by daemon when container create successfully"
type: "object"
Expand Down Expand Up @@ -1313,6 +1327,20 @@ definitions:
description: "Whether to enable lxcfs."
type: "boolean"
x-nullable: false
Rich:
type: "boolean"
description: "Whether to start container in rich container mode. (default false)"
x-nullable: false
RichMode:
type: "string"
description: "Choose one rich container mode.(default dumb-init)"
enum:
- "dumb-init"
- "sbin-init"
- "systemd"
InitScript:
type: "string"
description: "Initial script executed in container. The script will be executed before entrypoint or command"
- $ref: "#/definitions/Resources"

UpdateConfig:
Expand Down
63 changes: 63 additions & 0 deletions apis/types/container_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions apis/types/host_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cli/common_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,9 @@ func addCommonFlags(flagSet *pflag.FlagSet) *container {

flagSet.StringVarP(&c.workdir, "workdir", "w", "", "Set the working directory in a container")

flagSet.BoolVar(&c.rich, "rich", false, "Start container in rich container mode. (default false)")
flagSet.StringVar(&c.richMode, "rich-mode", "", "Choose one rich container mode. dumb-init(default), systemd, sbin-init")
flagSet.StringVar(&c.initScript, "initscript", "", "Initial script executed in container")

return c
}
8 changes: 8 additions & 0 deletions cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type container struct {
blkioDeviceReadIOps ThrottleIOpsDevice
blkioDeviceWriteIOps ThrottleIOpsDevice
IntelRdtL3Cbm string

//add for rich container mode
rich bool
richMode string
initScript string
}

func (c *container) config() (*types.ContainerCreateConfig, error) {
Expand Down Expand Up @@ -135,6 +140,9 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {
User: c.user,
Hostname: strfmt.Hostname(c.hostname),
Labels: labels,
Rich: c.rich,
RichMode: c.richMode,
InitScript: c.initScript,
},

HostConfig: &types.HostConfig{
Expand Down
53 changes: 53 additions & 0 deletions daemon/mgr/container_rich_mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package mgr

import (
"fmt"

"github.com/alibaba/pouch/apis/types"
)

const (
richModeEnv = "rich_mode=true"
richModeLaunchEnv = "rich_mode_launch_manner"

//for ali internal
interRichModeEnv = "ali_run_mode=common_vm"
)

func richContainerModeEnv(c *ContainerMeta) []string {
var (
ret = []string{}
setRichMode = false
richMode = ""
)

envs := c.Config.Env

//if set inter_rich_mode_env, you can also run in rich container mode
for _, e := range envs {
if e == interRichModeEnv {
setRichMode = true
richMode = types.ContainerConfigRichModeSystemd
break
}
}

if c.Config.Rich {
setRichMode = true
}

if c.Config.RichMode != "" {
richMode = c.Config.RichMode
}

//if not set rich mode manner, default set dumb-init
if richMode == "" {
richMode = types.ContainerConfigRichModeDumbInit
}

if setRichMode {
ret = append(ret, richModeEnv, fmt.Sprintf("%s=%s", richModeLaunchEnv, richMode))
}

return ret
}

0 comments on commit de8b526

Please sign in to comment.