Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add lxcfs flag to cli #534

Merged
merged 1 commit into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is a little bit in mess, and we need to make it more clear.

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually currently pouchd has enabled lxcfs by default, right? @CodeJuan @Letty5411
Then it seems these test setting enablelxcfs does not work as expected, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's causeed by the environment.
The output of pouch run --enableLxcfs=true docker.io/library/busybox:latest cat /proc/uptime was 0.0 0.0 on my machine, so I set the expected value=0.0 0.0, but the output of CI was 0.00 0.00

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")
}
}