Skip to content

Commit

Permalink
Merge pull request #2171 from fuweid/bugfix_support_comma_in_env_and_…
Browse files Browse the repository at this point in the history
…label

bugfix: cli should not split args by comma for env/labels
  • Loading branch information
allencloud authored Aug 30, 2018
2 parents 3311b05 + edff9b8 commit f27e5c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cli/common_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func addCommonFlags(flagSet *pflag.FlagSet) *container {

flagSet.BoolVar(&c.enableLxcfs, "enableLxcfs", false, "Enable lxcfs for the container, only effective when enable-lxcfs switched on in Pouchd")
flagSet.StringVar(&c.entrypoint, "entrypoint", "", "Overwrite the default ENTRYPOINT of the image")
flagSet.StringSliceVarP(&c.env, "env", "e", nil, "Set environment variables for container")
flagSet.StringArrayVarP(&c.env, "env", "e", nil, "Set environment variables for container")
flagSet.StringVar(&c.hostname, "hostname", "", "Set container's hostname")
flagSet.BoolVar(&c.disableNetworkFiles, "disable-network-files", false, "Disable the generation of network files(/etc/hostname, /etc/hosts and /etc/resolv.conf) for container. If true, no network files will be generated. Default false")

// Intel RDT
flagSet.StringVar(&c.IntelRdtL3Cbm, "intel-rdt-l3-cbm", "", "Limit container resource for Intel RDT/CAT which introduced in Linux 4.10 kernel")

flagSet.StringVar(&c.ipcMode, "ipc", "", "IPC namespace to use")
flagSet.StringSliceVarP(&c.labels, "label", "l", nil, "Set labels for a container")
flagSet.StringArrayVarP(&c.labels, "label", "l", nil, "Set labels for a container")

// log driver and log options
flagSet.StringVar(&c.logDriver, "log-driver", types.LogConfigLogDriverJSONFile, "Logging driver for the container")
Expand Down
23 changes: 17 additions & 6 deletions test/cli_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"reflect"
"runtime"
"strings"

Expand Down Expand Up @@ -140,10 +141,20 @@ func (suite *PouchCreateSuite) TestCreateInWrongWay(c *check.C) {

// TestCreateWithLabels tries to test create a container with label.
func (suite *PouchCreateSuite) TestCreateWithLabels(c *check.C) {
label := "abc=123"
name := "create-label"
name := "test-create-with-labels"

expectedLabels := map[string]string{
"abc": "123",
"ABC": "123,456,789",
}

res := command.PouchRun("create",
"--name", name,
"-l", "abc=123",
"-l", "ABC=123,456,789",
busyboxImage,
)

res := command.PouchRun("create", "--name", name, "-l", label, busyboxImage)
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)

Expand All @@ -153,10 +164,10 @@ func (suite *PouchCreateSuite) TestCreateWithLabels(c *check.C) {
if err := json.Unmarshal([]byte(output), &result); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
c.Assert(result[0].Config.Labels, check.NotNil)

if result[0].Config.Labels["abc"] != "123" {
c.Errorf("failed to set label: %s", label)
c.Assert(result[0].Config.Labels, check.NotNil)
if !reflect.DeepEqual(result[0].Config.Labels, expectedLabels) {
c.Fatalf("expected %v, but got %v", expectedLabels, result[0].Config.Labels)
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,14 @@ func (suite *PouchRunSuite) TestRunWithMtab(c *check.C) {
}
c.Assert(found, check.Equals, true)
}

func (suite *PouchRunSuite) TestRunWithEnv(c *check.C) {
res := command.PouchRun("run", "--rm",
"--env", "A=a,b,c", // should not split args by comma
"--env", "B=b1",
"docker.io/library/alpine",
"sh", "-c", "echo ${A}-${B}",
)
res.Assert(c, icmd.Success)
c.Assert(strings.TrimSpace(res.Stdout()), check.Equals, "a,b,c-b1")
}

0 comments on commit f27e5c0

Please sign in to comment.