Skip to content

Commit

Permalink
Merge pull request #27 from ak1ra24/add-docker-run-extraargs
Browse files Browse the repository at this point in the history
support docker-run-extra-args
  • Loading branch information
slankdev committed Feb 6, 2020
2 parents e9bf903 + 1f46411 commit 1966bd4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Node struct {
Mounts []string `yaml:"mounts,flow" mapstructure:"mounts,flow"`
HostNameIgnore bool `yaml:"hostname_ignore" mapstructure:"hostname_ignore"`
EntryPoint string `yaml:"entrypoint" mapstructure:"entrypoint"`
ExtraArgs string `yaml:"docker_run_extra_args" mapstructure:"docker_run_extra_args"`
}

// Interface
Expand Down Expand Up @@ -424,6 +425,10 @@ func (node *Node) CreateNode() []string {
}
}

if node.ExtraArgs != "" {
createNodeCmd += fmt.Sprintf("%s ", node.ExtraArgs)
}

createNodeCmd += node.Image
} else if node.Type == "netns" {
createNodeCmd = fmt.Sprintf("ip netns add %s", node.Name)
Expand Down
24 changes: 24 additions & 0 deletions internal/pkg/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestNode_DeleteNode(t *testing.T) {
Mounts []string
HostNameIgnore bool
EntryPoint string
ExtraArgs string
}
tests := []struct {
name string
Expand Down Expand Up @@ -183,6 +184,7 @@ func TestNode_DeleteNode(t *testing.T) {
Mounts: tt.fields.Mounts,
HostNameIgnore: tt.fields.HostNameIgnore,
EntryPoint: tt.fields.EntryPoint,
ExtraArgs: tt.fields.ExtraArgs,
}
if got := node.DeleteNode(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Node.DeleteNode() = %v, want %v", got, tt.want)
Expand Down Expand Up @@ -485,6 +487,7 @@ func TestNode_CreateNode(t *testing.T) {
Mounts []string
HostNameIgnore bool
EntryPoint string
ExtraArgs string
}
tests := []struct {
name string
Expand Down Expand Up @@ -670,6 +673,22 @@ func TestNode_CreateNode(t *testing.T) {
},
want: []string{"docker run -td --net none --name T1 --rm --privileged --hostname T1 --entrypoint bash -v /tmp/ak1ra24:/tinet slankdev/frr"},
},
{
name: "create node with extra args",
fields: fields{
Name: "T1",
Image: "nginx",
Interfaces: []Interface{
Interface{
Name: "net0",
Type: "direct",
Args: "T2#net0",
},
},
ExtraArgs: "-p 8080:80",
},
want: []string{"docker run -td --net none --name T1 --rm --privileged --hostname T1 -v /tmp/tinet:/tinet -p 8080:80 nginx"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -684,6 +703,7 @@ func TestNode_CreateNode(t *testing.T) {
Mounts: tt.fields.Mounts,
HostNameIgnore: tt.fields.HostNameIgnore,
EntryPoint: tt.fields.EntryPoint,
ExtraArgs: tt.fields.ExtraArgs,
}
if got := node.CreateNode(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Node.CreateNode() = %v, want %v", got, tt.want)
Expand Down Expand Up @@ -989,6 +1009,7 @@ func TestNode_Mount_docker_netns(t *testing.T) {
Mounts []string
HostNameIgnore bool
EntryPoint string
ExtraArgs string
}
tests := []struct {
name string
Expand Down Expand Up @@ -1024,6 +1045,7 @@ func TestNode_Mount_docker_netns(t *testing.T) {
Mounts: tt.fields.Mounts,
HostNameIgnore: tt.fields.HostNameIgnore,
EntryPoint: tt.fields.EntryPoint,
ExtraArgs: tt.fields.ExtraArgs,
}
if got := node.Mount_docker_netns(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Node.Mount_docker_netns() = %v, want %v", got, tt.want)
Expand Down Expand Up @@ -1069,6 +1091,7 @@ func TestNode_DelNsCmd(t *testing.T) {
Mounts []string
HostNameIgnore bool
EntryPoint string
ExtraArgs string
}
tests := []struct {
name string
Expand Down Expand Up @@ -1104,6 +1127,7 @@ func TestNode_DelNsCmd(t *testing.T) {
Mounts: tt.fields.Mounts,
HostNameIgnore: tt.fields.HostNameIgnore,
EntryPoint: tt.fields.EntryPoint,
ExtraArgs: tt.fields.ExtraArgs,
}
if got := node.DelNsCmd(); got != tt.want {
t.Errorf("Node.DelNsCmd() = %v, want %v", got, tt.want)
Expand Down

0 comments on commit 1966bd4

Please sign in to comment.