1
0
mirror of https://github.com/rancher/types.git synced 2025-09-25 04:12:02 +00:00

Do not drop source port

This commit is contained in:
Alena Prokharchyk
2019-12-12 13:33:43 -08:00
parent 7f4ca1e45e
commit d438ea193c
2 changed files with 3 additions and 8 deletions

View File

@@ -66,14 +66,13 @@ func (n ContainerPorts) FromInternal(data map[string]interface{}) {
if annotationPort, ok := portMap[convert.ToString(portName)]; ok {
containerPorts = append(containerPorts, annotationPort)
} else {
hostPort, _ := values.GetValue(asMap, "sourcePort")
hostPort, _ := values.GetValue(asMap, "hostPort")
if hostPort == nil {
asMap["kind"] = "ClusterIP"
} else {
asMap["sourcePort"] = hostPort
asMap["kind"] = "HostPort"
}
delete(asMap, "hostPort")
containerPorts = append(containerPorts, asMap)
}
}
@@ -98,11 +97,9 @@ func (n ContainerPorts) ToInternal(data map[string]interface{}) error {
logrus.Warnf("Failed to encode port: %v", err)
return obj
}
if !strings.EqualFold(convert.ToString(mapped["kind"]), "HostPort") {
// delete the source port so it doesn't get converted to the host port by default mapper
delete(mapped, "sourcePort")
if strings.EqualFold(convert.ToString(mapped["kind"]), "HostPort") {
mapped["hostPort"] = mapped["sourcePort"]
}
}
ports = append(ports, l)
}