Fix port ordering
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -101,7 +100,7 @@ func SetInstanceSwarmPorts(i *Instance) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetUsedPorts(i *Instance) ([]int, error) {
|
||||
func GetUsedPorts(i *Instance) ([]uint16, error) {
|
||||
if i.dockerClient == nil {
|
||||
return nil, fmt.Errorf("Docker client for DinD (%s) is not ready", i.IP)
|
||||
}
|
||||
@@ -111,16 +110,15 @@ func GetUsedPorts(i *Instance) ([]int, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
openPorts := sort.IntSlice{}
|
||||
openPorts := []uint16{}
|
||||
for _, c := range containers {
|
||||
for _, p := range c.Ports {
|
||||
// When port is not published on the host docker return public port as 0, so we need to avoid it
|
||||
if p.PublicPort != 0 {
|
||||
openPorts = append(openPorts, int(p.PublicPort))
|
||||
openPorts = append(openPorts, p.PublicPort)
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(openPorts)
|
||||
|
||||
return openPorts, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user