Skip to content

Commit

Permalink
Fix port binds (#184)
Browse files Browse the repository at this point in the history
* renamed variable to match its data type

* fixed missing exposed ports configuration
  • Loading branch information
hellt committed Dec 1, 2020
1 parent eaa45e1 commit 840ecaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Node struct {
Env []string
Binds []string // Bind mounts strings (src:dest:options)
PortBindings nat.PortMap // PortBindings define the bindings between the container ports and host ports
PortSet nat.PortSet // PortSet define the ports that should be exposed on a container

TLSCert string
TLSKey string
Expand Down Expand Up @@ -190,15 +191,15 @@ func (c *cLab) bindsInit(nodeCfg *NodeConfig) []string {
}

// portsInit produces the nat.PortMap out of the slice of string representation of port bindings
func (c *cLab) portsInit(nodeCfg *NodeConfig) (nat.PortMap, error) {
func (c *cLab) portsInit(nodeCfg *NodeConfig) (nat.PortSet, nat.PortMap, error) {
if len(nodeCfg.Ports) != 0 {
_, pm, err := nat.ParsePortSpecs(nodeCfg.Ports)
ps, pb, err := nat.ParsePortSpecs(nodeCfg.Ports)
if err != nil {
return nil, err
return nil, nil, err
}
return pm, nil
return ps, pb, nil
}
return nil, nil
return nil, nil, nil
}

func (c *cLab) groupInitialization(nodeCfg *NodeConfig, kind string) string {
Expand Down Expand Up @@ -302,11 +303,12 @@ func (c *cLab) NewNode(nodeName string, nodeCfg NodeConfig, idx int) error {
node.Kind = strings.ToLower(c.kindInitialization(&nodeCfg))
node.Binds = c.bindsInit(&nodeCfg)

pb, err := c.portsInit(&nodeCfg)
ps, pb, err := c.portsInit(&nodeCfg)
if err != nil {
return err
}
node.PortBindings = pb
node.PortSet = ps

switch node.Kind {
case "ceos":
Expand Down
1 change: 1 addition & 0 deletions clab/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (c *cLab) CreateContainer(ctx context.Context, node *Node) (err error) {
Tty: true,
User: node.User,
Labels: labels,
ExposedPorts: node.PortSet,
}, &container.HostConfig{
Binds: node.Binds,
PortBindings: node.PortBindings,
Expand Down

0 comments on commit 840ecaa

Please sign in to comment.