From cfd2169f888300e816c836a5177b6ef0463b1739 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Tue, 14 Mar 2023 16:17:48 +0100 Subject: [PATCH] cli: replace intstr.FromInt with intstr.FromInt32 This touches cases where FromInt() is used on numeric constants, or values which are already int32s, or int variables which are defined close by and can be changed to int32s with little impact. Signed-off-by: Stephen Kitt Kubernetes-commit: 45836971f27ca70cd7742e8ee66e99e3c648cf9f --- pkg/cmd/create/create_service.go | 11 +-- pkg/cmd/expose/expose.go | 2 +- pkg/cmd/expose/expose_test.go | 112 ++++++++++++------------ pkg/cmd/portforward/portforward_test.go | 18 ++-- pkg/cmd/run/run_test.go | 4 +- pkg/describe/describe_test.go | 20 ++--- pkg/generate/versioned/service.go | 2 +- pkg/generate/versioned/service_test.go | 58 ++++++------ pkg/util/deployment/deployment.go | 4 +- pkg/util/service_port_test.go | 4 +- 10 files changed, 118 insertions(+), 117 deletions(-) diff --git a/pkg/cmd/create/create_service.go b/pkg/cmd/create/create_service.go index e44c8d95f..54b164b35 100644 --- a/pkg/cmd/create/create_service.go +++ b/pkg/cmd/create/create_service.go @@ -388,24 +388,25 @@ func parsePorts(portString string) (int32, intstr.IntOrString, error) { port, err := utilsnet.ParsePort(portStringSlice[0], true) if err != nil { - return 0, intstr.FromInt(0), err + return 0, intstr.FromInt32(0), err } if len(portStringSlice) == 1 { - return int32(port), intstr.FromInt(int(port)), nil + port32 := int32(port) + return port32, intstr.FromInt32(port32), nil } var targetPort intstr.IntOrString if portNum, err := strconv.Atoi(portStringSlice[1]); err != nil { if errs := validation.IsValidPortName(portStringSlice[1]); len(errs) != 0 { - return 0, intstr.FromInt(0), fmt.Errorf(strings.Join(errs, ",")) + return 0, intstr.FromInt32(0), fmt.Errorf(strings.Join(errs, ",")) } targetPort = intstr.FromString(portStringSlice[1]) } else { if errs := validation.IsValidPortNum(portNum); len(errs) != 0 { - return 0, intstr.FromInt(0), fmt.Errorf(strings.Join(errs, ",")) + return 0, intstr.FromInt32(0), fmt.Errorf(strings.Join(errs, ",")) } - targetPort = intstr.FromInt(portNum) + targetPort = intstr.FromInt32(int32(portNum)) } return int32(port), targetPort, nil } diff --git a/pkg/cmd/expose/expose.go b/pkg/cmd/expose/expose.go index 0351cd560..81e47c1c5 100644 --- a/pkg/cmd/expose/expose.go +++ b/pkg/cmd/expose/expose.go @@ -482,7 +482,7 @@ func (o *ExposeServiceOptions) createService() (*corev1.Service, error) { // should be the same as Port for i := range service.Spec.Ports { port := service.Spec.Ports[i].Port - service.Spec.Ports[i].TargetPort = intstr.FromInt(int(port)) + service.Spec.Ports[i].TargetPort = intstr.FromInt32(port) } } if len(o.ExternalIP) > 0 { diff --git a/pkg/cmd/expose/expose_test.go b/pkg/cmd/expose/expose_test.go index 585d07f30..e954671e5 100644 --- a/pkg/cmd/expose/expose_test.go +++ b/pkg/cmd/expose/expose_test.go @@ -68,7 +68,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"app": "go"}, @@ -99,7 +99,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -131,7 +131,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolTCP, Port: 80, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, }, Selector: map[string]string{"run": "this"}, @@ -162,7 +162,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -194,7 +194,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -227,7 +227,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -259,7 +259,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -317,7 +317,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -345,7 +345,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolTCP, Port: 90, - TargetPort: intstr.FromInt(90), + TargetPort: intstr.FromInt32(90), }, }, Selector: map[string]string{"svc": "frompod"}, @@ -369,12 +369,12 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolTCP, Port: 80, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Protocol: corev1.ProtocolTCP, Port: 443, - TargetPort: intstr.FromInt(443), + TargetPort: intstr.FromInt32(443), }, }, }, @@ -388,13 +388,13 @@ func TestRunExposeService(t *testing.T) { Name: "port-1", Protocol: corev1.ProtocolTCP, Port: 80, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Protocol: corev1.ProtocolTCP, Port: 443, - TargetPort: intstr.FromInt(443), + TargetPort: intstr.FromInt32(443), }, }, Selector: map[string]string{"svc": "fromfoo"}, @@ -418,22 +418,22 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolTCP, Port: 80, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Protocol: corev1.ProtocolUDP, Port: 8080, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Protocol: corev1.ProtocolUDP, Port: 8081, - TargetPort: intstr.FromInt(8081), + TargetPort: intstr.FromInt32(8081), }, { Protocol: corev1.ProtocolSCTP, Port: 8082, - TargetPort: intstr.FromInt(8082), + TargetPort: intstr.FromInt32(8082), }, }, }, @@ -447,25 +447,25 @@ func TestRunExposeService(t *testing.T) { Name: "port-1", Protocol: corev1.ProtocolTCP, Port: 80, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Protocol: corev1.ProtocolUDP, Port: 8080, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Name: "port-3", Protocol: corev1.ProtocolUDP, Port: 8081, - TargetPort: intstr.FromInt(8081), + TargetPort: intstr.FromInt32(8081), }, { Name: "port-4", Protocol: corev1.ProtocolSCTP, Port: 8082, - TargetPort: intstr.FromInt(8082), + TargetPort: intstr.FromInt32(8082), }, }, Selector: map[string]string{"svc": "fromfoo"}, @@ -496,7 +496,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolSCTP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"app": "go"}, @@ -527,7 +527,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolSCTP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -558,7 +558,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolSCTP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -590,7 +590,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolSCTP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -622,7 +622,7 @@ func TestRunExposeService(t *testing.T) { { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"func": "stream"}, @@ -821,7 +821,7 @@ status: { Protocol: corev1.ProtocolUDP, Port: 14, - TargetPort: intstr.FromInt(14), + TargetPort: intstr.FromInt32(14), }, }, Selector: map[string]string{"app": "go"}, @@ -897,7 +897,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -952,7 +952,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -1087,7 +1087,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -1113,7 +1113,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, SessionAffinity: corev1.ServiceAffinityClientIP, @@ -1141,7 +1141,7 @@ func TestGenerateService(t *testing.T) { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: "10.10.10.10", @@ -1169,7 +1169,7 @@ func TestGenerateService(t *testing.T) { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: corev1.ClusterIPNone, @@ -1226,13 +1226,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: corev1.ProtocolUDP, - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, { Name: "port-2", Port: 443, Protocol: corev1.ProtocolUDP, - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -1256,13 +1256,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 443, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(443), + TargetPort: intstr.FromInt32(443), }, }, }, @@ -1286,13 +1286,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: corev1.ProtocolUDP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -1316,19 +1316,19 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: corev1.ProtocolUDP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Name: "port-3", Port: 8081, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(8081), + TargetPort: intstr.FromInt32(8081), }, }, }, @@ -1390,7 +1390,7 @@ func TestGenerateService(t *testing.T) { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -1421,7 +1421,7 @@ func TestGenerateService(t *testing.T) { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -1447,7 +1447,7 @@ func TestGenerateService(t *testing.T) { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -1473,7 +1473,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, SessionAffinity: corev1.ServiceAffinityClientIP, @@ -1500,7 +1500,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: "10.10.10.10", @@ -1528,7 +1528,7 @@ func TestGenerateService(t *testing.T) { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: corev1.ClusterIPNone, @@ -1584,13 +1584,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: corev1.ProtocolSCTP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 443, Protocol: corev1.ProtocolSCTP, - TargetPort: intstr.FromInt(443), + TargetPort: intstr.FromInt32(443), }, }, }, @@ -1614,13 +1614,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: corev1.ProtocolSCTP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -1644,25 +1644,25 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: corev1.ProtocolUDP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Name: "port-3", Port: 8081, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(8081), + TargetPort: intstr.FromInt32(8081), }, { Name: "port-4", Port: 8082, Protocol: corev1.ProtocolSCTP, - TargetPort: intstr.FromInt(8082), + TargetPort: intstr.FromInt32(8082), }, }, }, diff --git a/pkg/cmd/portforward/portforward_test.go b/pkg/cmd/portforward/portforward_test.go index c0c181c7b..fb2252c54 100644 --- a/pkg/cmd/portforward/portforward_test.go +++ b/pkg/cmd/portforward/portforward_test.go @@ -158,7 +158,7 @@ func TestTranslateServicePortToTargetPort(t *testing.T) { Ports: []corev1.ServicePort{ { Port: 80, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -187,7 +187,7 @@ func TestTranslateServicePortToTargetPort(t *testing.T) { Ports: []corev1.ServicePort{ { Port: 80, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -216,7 +216,7 @@ func TestTranslateServicePortToTargetPort(t *testing.T) { Ports: []corev1.ServicePort{ { Port: 8080, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -246,7 +246,7 @@ func TestTranslateServicePortToTargetPort(t *testing.T) { Ports: []corev1.ServicePort{ { Port: 80, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -276,7 +276,7 @@ func TestTranslateServicePortToTargetPort(t *testing.T) { Ports: []corev1.ServicePort{ { Port: 80, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -378,12 +378,12 @@ func TestTranslateServicePortToTargetPort(t *testing.T) { { Port: 80, Name: "http", - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Port: 443, Name: "https", - TargetPort: intstr.FromInt(8443), + TargetPort: intstr.FromInt32(8443), }, }, }, @@ -414,12 +414,12 @@ func TestTranslateServicePortToTargetPort(t *testing.T) { { Port: 80, Name: "http", - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Port: 443, Name: "https", - TargetPort: intstr.FromInt(8443), + TargetPort: intstr.FromInt32(8443), }, }, }, diff --git a/pkg/cmd/run/run_test.go b/pkg/cmd/run/run_test.go index bd6df8c13..86fe03463 100644 --- a/pkg/cmd/run/run_test.go +++ b/pkg/cmd/run/run_test.go @@ -262,7 +262,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, }, Selector: map[string]string{ @@ -295,7 +295,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, }, Selector: map[string]string{ diff --git a/pkg/describe/describe_test.go b/pkg/describe/describe_test.go index 8841c0ef1..fc87d4479 100644 --- a/pkg/describe/describe_test.go +++ b/pkg/describe/describe_test.go @@ -667,7 +667,7 @@ func TestDescribeService(t *testing.T) { Name: "port-tcp", Port: 8080, Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(9527), + TargetPort: intstr.FromInt32(9527), NodePort: 31111, }}, Selector: map[string]string{"blah": "heh"}, @@ -2772,7 +2772,7 @@ func TestDescribeIngress(t *testing.T) { ingresClassName := "test" backendV1beta1 := networkingv1beta1.IngressBackend{ ServiceName: "default-backend", - ServicePort: intstr.FromInt(80), + ServicePort: intstr.FromInt32(80), } v1beta1 := fake.NewSimpleClientset(&networkingv1beta1.Ingress{ ObjectMeta: metav1.ObjectMeta{ @@ -3332,7 +3332,7 @@ func TestDescribeCSINode(t *testing.T) { } func TestDescribePodDisruptionBudgetV1beta1(t *testing.T) { - minAvailable := intstr.FromInt(22) + minAvailable := intstr.FromInt32(22) f := fake.NewSimpleClientset(&policyv1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", @@ -3360,7 +3360,7 @@ func TestDescribePodDisruptionBudgetV1beta1(t *testing.T) { } func TestDescribePodDisruptionBudgetV1(t *testing.T) { - minAvailable := intstr.FromInt(22) + minAvailable := intstr.FromInt32(22) f := fake.NewSimpleClientset(&policyv1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", @@ -4851,8 +4851,8 @@ Spec: Policy Types: Ingress, Egress ` - port80 := intstr.FromInt(80) - port82 := intstr.FromInt(82) + port80 := intstr.FromInt32(80) + port82 := intstr.FromInt32(82) protoTCP := corev1.ProtocolTCP versionedFake := fake.NewSimpleClientset(&networkingv1.NetworkPolicy{ @@ -5036,8 +5036,8 @@ Spec: Policy Types: Ingress ` - port80 := intstr.FromInt(80) - port82 := intstr.FromInt(82) + port80 := intstr.FromInt32(80) + port82 := intstr.FromInt32(82) protoTCP := corev1.ProtocolTCP versionedFake := fake.NewSimpleClientset(&networkingv1.NetworkPolicy{ @@ -5164,8 +5164,8 @@ Spec: Policy Types: Ingress, Egress ` - port80 := intstr.FromInt(80) - port82 := intstr.FromInt(82) + port80 := intstr.FromInt32(80) + port82 := intstr.FromInt32(82) protoTCP := corev1.ProtocolTCP versionedFake := fake.NewSimpleClientset(&networkingv1.NetworkPolicy{ diff --git a/pkg/generate/versioned/service.go b/pkg/generate/versioned/service.go index 30f379156..0c1beeaab 100644 --- a/pkg/generate/versioned/service.go +++ b/pkg/generate/versioned/service.go @@ -207,7 +207,7 @@ func generateService(genericParams map[string]interface{}) (runtime.Object, erro // should be the same as Port for i := range service.Spec.Ports { port := service.Spec.Ports[i].Port - service.Spec.Ports[i].TargetPort = intstr.FromInt(int(port)) + service.Spec.Ports[i].TargetPort = intstr.FromInt32(port) } } if len(params["external-ip"]) > 0 { diff --git a/pkg/generate/versioned/service_test.go b/pkg/generate/versioned/service_test.go index 9285ea522..30438480e 100644 --- a/pkg/generate/versioned/service_test.go +++ b/pkg/generate/versioned/service_test.go @@ -56,7 +56,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -119,7 +119,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -276,7 +276,7 @@ func TestGenerateService(t *testing.T) { Name: "default", Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -307,7 +307,7 @@ func TestGenerateService(t *testing.T) { Name: "default", Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, SessionAffinity: v1.ServiceAffinityClientIP, @@ -338,7 +338,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: "10.10.10.10", @@ -369,7 +369,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "TCP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: v1.ClusterIPNone, @@ -434,13 +434,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: v1.ProtocolUDP, - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, { Name: "port-2", Port: 443, Protocol: v1.ProtocolUDP, - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -468,13 +468,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 443, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(443), + TargetPort: intstr.FromInt32(443), }, }, }, @@ -502,13 +502,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: v1.ProtocolUDP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -536,19 +536,19 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: v1.ProtocolUDP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Name: "port-3", Port: 8081, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(8081), + TargetPort: intstr.FromInt32(8081), }, }, }, @@ -621,7 +621,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -654,7 +654,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -683,7 +683,7 @@ func TestGenerateService(t *testing.T) { Name: "default", Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, }, @@ -713,7 +713,7 @@ func TestGenerateService(t *testing.T) { Name: "default", Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, SessionAffinity: v1.ServiceAffinityClientIP, @@ -743,7 +743,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: "10.10.10.10", @@ -773,7 +773,7 @@ func TestGenerateService(t *testing.T) { { Port: 80, Protocol: "SCTP", - TargetPort: intstr.FromInt(1234), + TargetPort: intstr.FromInt32(1234), }, }, ClusterIP: v1.ClusterIPNone, @@ -835,13 +835,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: v1.ProtocolSCTP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 443, Protocol: v1.ProtocolSCTP, - TargetPort: intstr.FromInt(443), + TargetPort: intstr.FromInt32(443), }, }, }, @@ -868,13 +868,13 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: v1.ProtocolSCTP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -901,25 +901,25 @@ func TestGenerateService(t *testing.T) { Name: "port-1", Port: 80, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(80), + TargetPort: intstr.FromInt32(80), }, { Name: "port-2", Port: 8080, Protocol: v1.ProtocolUDP, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, { Name: "port-3", Port: 8081, Protocol: v1.ProtocolTCP, - TargetPort: intstr.FromInt(8081), + TargetPort: intstr.FromInt32(8081), }, { Name: "port-4", Port: 8082, Protocol: v1.ProtocolSCTP, - TargetPort: intstr.FromInt(8082), + TargetPort: intstr.FromInt32(8082), }, }, }, diff --git a/pkg/util/deployment/deployment.go b/pkg/util/deployment/deployment.go index f0352d9ef..31e174d2e 100644 --- a/pkg/util/deployment/deployment.go +++ b/pkg/util/deployment/deployment.go @@ -236,11 +236,11 @@ func findOldReplicaSets(deployment *appsv1.Deployment, rsList []*appsv1.ReplicaS // 2 desired, max unavailable 0%, surge 1% - should scale new(+1), then old(-1), then new(+1), then old(-1) // 1 desired, max unavailable 0%, surge 1% - should scale new(+1), then old(-1) func ResolveFenceposts(maxSurge, maxUnavailable *intstrutil.IntOrString, desired int32) (int32, int32, error) { - surge, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxSurge, intstrutil.FromInt(0)), int(desired), true) + surge, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxSurge, intstrutil.FromInt32(0)), int(desired), true) if err != nil { return 0, 0, err } - unavailable, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxUnavailable, intstrutil.FromInt(0)), int(desired), false) + unavailable, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxUnavailable, intstrutil.FromInt32(0)), int(desired), false) if err != nil { return 0, 0, err } diff --git a/pkg/util/service_port_test.go b/pkg/util/service_port_test.go index f15ae3c35..58d889989 100644 --- a/pkg/util/service_port_test.go +++ b/pkg/util/service_port_test.go @@ -39,7 +39,7 @@ func TestLookupContainerPortNumberByServicePort(t *testing.T) { Ports: []v1.ServicePort{ { Port: 80, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, }, @@ -69,7 +69,7 @@ func TestLookupContainerPortNumberByServicePort(t *testing.T) { Ports: []v1.ServicePort{ { Port: 80, - TargetPort: intstr.FromInt(8080), + TargetPort: intstr.FromInt32(8080), }, }, },