mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #86172 from liggitt/intstr
Clarify intstr.IntValue() behavior
This commit is contained in:
commit
97d68d014c
@ -25,6 +25,7 @@ go_library(
|
|||||||
"//pkg/util/async:go_default_library",
|
"//pkg/util/async:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1: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/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/sets:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/features:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/features:go_default_library",
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
genericfeatures "k8s.io/apiserver/pkg/features"
|
genericfeatures "k8s.io/apiserver/pkg/features"
|
||||||
@ -234,14 +235,18 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *v1.ServicePort, ser
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
preserveDIP = false
|
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{
|
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.
|
targetPort: targetPort,
|
||||||
// Its real value would be got later from endpoints.
|
|
||||||
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(),
|
||||||
sessionAffinityType: service.Spec.SessionAffinity,
|
sessionAffinityType: service.Spec.SessionAffinity,
|
||||||
|
@ -97,7 +97,8 @@ func (intstr *IntOrString) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IntValue returns the IntVal if type Int, or if
|
// 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 {
|
func (intstr *IntOrString) IntValue() int {
|
||||||
if intstr.Type == String {
|
if intstr.Type == String {
|
||||||
i, _ := strconv.Atoi(intstr.StrVal)
|
i, _ := strconv.Atoi(intstr.StrVal)
|
||||||
|
Loading…
Reference in New Issue
Block a user