Skip to content

Commit

Permalink
add lxcfs flag to cli
Browse files Browse the repository at this point in the history
Signed-off-by: codejuan <[email protected]>
  • Loading branch information
CodeJuan committed Jan 10, 2018
1 parent a45d30d commit f0465d0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type container struct {
memorySwap string
memorySwappiness int64
devices []string
enableLxcfs bool
}

func (c *container) config() (*types.ContainerCreateConfig, error) {
Expand Down Expand Up @@ -106,5 +107,7 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {
}
config.HostConfig.Devices = deviceMappings

config.EnableLxcfs = c.enableLxcfs

return config, nil
}
1 change: 1 addition & 0 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (cc *CreateCommand) addFlags() {
flagSet.StringVarP(&cc.memory, "memory", "m", "", "Container memory limit")
flagSet.StringVar(&cc.memorySwap, "memory-swap", "", "Container swap limit")
flagSet.StringSliceVarP(&cc.devices, "device", "", nil, "Add a host device to the container")
flagSet.BoolVar(&cc.enableLxcfs, "enableLxcfs", false, "Enable lxcfs")
}

// runCreate is the entry of create command.
Expand Down
1 change: 1 addition & 0 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (rc *RunCommand) addFlags() {
flagSet.StringVarP(&rc.memory, "memory", "m", "", "Container memory limit")
flagSet.StringVar(&rc.memorySwap, "memory-swap", "", "Container swap limit")
flagSet.StringSliceVarP(&rc.devices, "device", "", nil, "Add a host device to the container")
flagSet.BoolVar(&rc.enableLxcfs, "enableLxcfs", false, "Enable lxcfs")
}

// runRun is the entry of run command.
Expand Down
20 changes: 20 additions & 0 deletions test/cli_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,23 @@ func (suite *PouchCreateSuite) TestCreateWithLabels(c *check.C) {
c.Errorf("failed to set label: %s", label)
}
}

// TestCreateEnableLxcfs tries to test create a container with lxcfs.
func (suite *PouchCreateSuite) TestCreateEnableLxcfs(c *check.C) {
name := "create-lxcfs"

res := command.PouchRun("create", "--name", name, "--enableLxcfs=true", busyboxImage)
res.Assert(c, icmd.Success)

output := command.PouchRun("inspect", name).Stdout()

result := &types.ContainerJSON{}
if err := json.Unmarshal([]byte(output), result); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
c.Assert(result.Config.EnableLxcfs, check.NotNil)

if result.Config.EnableLxcfs != true {
c.Errorf("failed to set EnableLxcfs")
}
}
12 changes: 12 additions & 0 deletions test/cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,15 @@ func (suite *PouchRunSuite) TestRunInWrongWay(c *check.C) {
c.Assert(res.Error, check.NotNil, check.Commentf(tc.name))
}
}

// TestRunEnableLxcfs is to verify run container with lxcfs.
func (suite *PouchRunSuite) TestRunEnableLxcfs(c *check.C) {
name := "test-run-lxcfs"

res := command.PouchRun("run", "--name", name, "--enableLxcfs=true", busyboxImage, "cat", "/proc/uptime")
res.Assert(c, icmd.Success)

if out := res.Combined(); !strings.Contains(out, " 0.0") {
c.Fatalf("upexpected output %s expected %s\n", out, " 0.0")
}
}

0 comments on commit f0465d0

Please sign in to comment.