1
0
mirror of https://github.com/rancher/types.git synced 2025-08-31 21:00:16 +00:00

Set hostPort for port kind=hostPort

This commit is contained in:
Alena Prokharchyk
2018-03-01 10:46:25 -08:00
parent ad54152d72
commit 773c8f572a

View File

@@ -4,6 +4,8 @@ import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/mapper"
"github.com/sirupsen/logrus"
"strings"
)
type ContainerPorts struct {
@@ -37,6 +39,18 @@ func (n ContainerPorts) ToInternal(data map[string]interface{}) {
path := []string{"containers", "{ARRAY}", "ports"}
convert.Transform(data, path, func(obj interface{}) interface{} {
if l, ok := obj.([]interface{}); ok {
for _, p := range l {
mapped, err := convert.EncodeToMap(p)
if err != nil {
logrus.Warnf("Failed to encode port: %v", err)
return obj
}
if strings.EqualFold(convert.ToString(mapped["kind"]), "HostPort") {
if _, ok := mapped["sourcePort"]; ok {
mapped["hostPort"] = mapped["sourcePort"]
}
}
}
ports = append(ports, l)
}
return obj