diff --git a/pkg/proxy/winkernel/BUILD b/pkg/proxy/winkernel/BUILD index d470652ecea..0e86edc9627 100644 --- a/pkg/proxy/winkernel/BUILD +++ b/pkg/proxy/winkernel/BUILD @@ -25,6 +25,7 @@ go_library( "//pkg/util/async:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//staging/src/k8s.io/apiserver/pkg/features:go_default_library", diff --git a/pkg/proxy/winkernel/proxier.go b/pkg/proxy/winkernel/proxier.go index d3423612c0e..feef8490c68 100644 --- a/pkg/proxy/winkernel/proxier.go +++ b/pkg/proxy/winkernel/proxier.go @@ -36,6 +36,7 @@ import ( "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" genericfeatures "k8s.io/apiserver/pkg/features" @@ -234,14 +235,18 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *v1.ServicePort, ser if err != nil { preserveDIP = false } + // targetPort is zero if it is specified as a name in port.TargetPort. + // Its real value would be got later from endpoints. + targetPort := 0 + if port.TargetPort.Type == intstr.Int { + targetPort = port.TargetPort.IntValue() + } info := &serviceInfo{ - clusterIP: net.ParseIP(service.Spec.ClusterIP), - port: int(port.Port), - protocol: port.Protocol, - 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(), + clusterIP: net.ParseIP(service.Spec.ClusterIP), + port: int(port.Port), + protocol: port.Protocol, + nodePort: int(port.NodePort), + targetPort: targetPort, // Deep-copy in case the service instance changes loadBalancerStatus: *service.Status.LoadBalancer.DeepCopy(), sessionAffinityType: service.Spec.SessionAffinity, diff --git a/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go b/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go index 2df62955538..cb974dcf7c9 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go @@ -97,7 +97,8 @@ func (intstr *IntOrString) String() string { } // IntValue returns the IntVal if type Int, or if -// it is a String, will attempt a conversion to int. +// it is a String, will attempt a conversion to int, +// returning 0 if a parsing error occurs. func (intstr *IntOrString) IntValue() int { if intstr.Type == String { i, _ := strconv.Atoi(intstr.StrVal)