diff --git a/apis/project.cattle.io/v3/schema/schema.go b/apis/project.cattle.io/v3/schema/schema.go index ad179ed0..bfc3b6de 100644 --- a/apis/project.cattle.io/v3/schema/schema.go +++ b/apis/project.cattle.io/v3/schema/schema.go @@ -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{}). diff --git a/mapper/container_ports.go b/mapper/container_ports.go index 5ae8e990..8b2209e4 100644 --- a/mapper/container_ports.go +++ b/mapper/container_ports.go @@ -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) }