1
0
mirror of https://github.com/rancher/types.git synced 2025-07-15 14:11:36 +00:00

Merge pull request #269 from alena1108/mar1

Set hostPort for port kind=hostPort
This commit is contained in:
Alena Prokharchyk 2018-03-01 10:50:53 -08:00 committed by GitHub
commit b04b5a8fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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