Skip to content

Commit

Permalink
Start default network automatically
Browse files Browse the repository at this point in the history
It was not setup properly because Networks() did not return the default
network config, it only added it on the fly to connect.
  • Loading branch information
michaelsauter committed Dec 2, 2017
1 parent 3a23997 commit ad3aa2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* [Bugfix] Create default network automatically

## 3.3.2 (2017-11-21)

* Remove broken flag `crane start --attach`. This flag was introduced in 3.3.0 but did not work properly, and doesn't add much value anyway. It would make more sense to have this flag on `crane run`, but that is left for another version.
Expand Down
11 changes: 6 additions & 5 deletions crane/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,12 @@ func (c *container) Networks() map[string]NetworkParameters {
panic(StatusError{fmt.Errorf("unknown type: %v", value), 65})
}
}

if cfg.Network("default") != nil {
if _, ok := c.networks["default"]; !ok {
c.networks["default"] = NetworkParameters{}
}
}
}
return c.networks
}
Expand Down Expand Up @@ -973,11 +979,6 @@ func (c *container) Run(cmds []string, targeted bool, detachFlag bool) {
// using the non-prefixed name as an alias
func (c *container) connectWithNetworks(adHoc bool) {
containerNetworks := c.Networks()
if cfg.Network("default") != nil {
if _, ok := containerNetworks["default"]; !ok {
containerNetworks["default"] = NetworkParameters{}
}
}
for name, params := range containerNetworks {
networkName := cfg.Network(name).ActualName()
args := []string{"network", "connect"}
Expand Down
11 changes: 11 additions & 0 deletions crane/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ func TestActualNet(t *testing.T) {
assert.Equal(t, "qux_bar", c.ActualNet())
}

func TestNetworks(t *testing.T) {
var c *container
// automatically has default network configured for every container
c = &container{RawName: "foo"}
cfg = &config{
containerMap: map[string]Container{"foo": c},
networkMap: map[string]Network{"default": &network{RawName: "default"}},
}
assert.Contains(t, c.Networks(), "default")
}

func TestCmd(t *testing.T) {
var c *container
// String
Expand Down

0 comments on commit ad3aa2d

Please sign in to comment.