1
0
mirror of https://github.com/rancher/types.git synced 2025-04-27 02:10:48 +00:00

Do not drop source port

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

View File

@ -514,8 +514,6 @@ func podTypes(schemas *types.Schemas) *types.Schemas {
).
AddMapperForType(&Version, v1.ContainerPort{},
m.Move{From: "hostIP", To: "hostIp"},
m.Copy{From: "hostPort", To: "sourcePort"},
m.Drop{Field: "hostPort"},
).
AddMapperForType(&Version, v1.Handler{},
mapper.ContainerProbeHandler{}).

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)
}