Fix service targetPort with string for Windows

pull/58/head
Pengfei Ni 2018-10-22 15:17:27 +08:00
parent 7cbb999518
commit 4b7a502c07
1 changed files with 14 additions and 4 deletions

View File

@ -180,10 +180,12 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *v1.ServicePort, ser
stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds) stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds)
} }
info := &serviceInfo{ info := &serviceInfo{
clusterIP: net.ParseIP(service.Spec.ClusterIP), clusterIP: net.ParseIP(service.Spec.ClusterIP),
port: int(port.Port), port: int(port.Port),
protocol: port.Protocol, protocol: port.Protocol,
nodePort: int(port.NodePort), nodePort: int(port.NodePort),
// targetPort is zero if it is specified as a name in port.TargetPort.
// Its real value would be got later from endpoints.
targetPort: port.TargetPort.IntValue(), targetPort: port.TargetPort.IntValue(),
// Deep-copy in case the service instance changes // Deep-copy in case the service instance changes
loadBalancerStatus: *service.Status.LoadBalancer.DeepCopy(), loadBalancerStatus: *service.Status.LoadBalancer.DeepCopy(),
@ -977,6 +979,14 @@ func (proxier *Proxier) syncProxyRules() {
var newHnsEndpoint *hcsshim.HNSEndpoint var newHnsEndpoint *hcsshim.HNSEndpoint
hnsNetworkName := proxier.network.name hnsNetworkName := proxier.network.name
var err error var err error
// targetPort is zero if it is specified as a name in port.TargetPort, so the real port should be got from endpoints.
// Note that hcsshim.AddLoadBalancer() doesn't support endpoints with different ports, so only port from first endpoint is used.
// TODO(feiskyer): add support of different endpoint ports after hcsshim.AddLoadBalancer() add that.
if svcInfo.targetPort == 0 {
svcInfo.targetPort = int(ep.port)
}
if len(ep.hnsID) > 0 { if len(ep.hnsID) > 0 {
newHnsEndpoint, err = hcsshim.GetHNSEndpointByID(ep.hnsID) newHnsEndpoint, err = hcsshim.GetHNSEndpointByID(ep.hnsID)
} }