Skip to content

Commit f55b59f

Browse files
committed
pkg/controller: drop pointer wrapper functions
The new k8s.io/utils/ptr package provides generic wrapper functions, which can be used instead of type-specific pointer wrapper functions. This replaces the latter with the former, and migrates other uses of the deprecated pointer package to ptr in affected files. Signed-off-by: Stephen Kitt <[email protected]>
1 parent 498f888 commit f55b59f

File tree

2 files changed

+129
-138
lines changed

2 files changed

+129
-138
lines changed

pkg/controller/endpointslice/endpointslice_controller_test.go

Lines changed: 103 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
"k8s.io/klog/v2/ktesting"
4646
"k8s.io/kubernetes/pkg/controller"
4747
endpointslicepkg "k8s.io/kubernetes/pkg/controller/util/endpointslice"
48-
"k8s.io/utils/pointer"
48+
"k8s.io/utils/ptr"
4949
)
5050

5151
// Most of the tests related to EndpointSlice allocation can be found in reconciler_test.go
@@ -643,41 +643,41 @@ func TestSyncService(t *testing.T) {
643643
},
644644
expectedEndpointPorts: []discovery.EndpointPort{
645645
{
646-
Name: pointer.String("sctp-example"),
647-
Protocol: protoPtr(v1.ProtocolSCTP),
648-
Port: pointer.Int32(3456),
646+
Name: ptr.To("sctp-example"),
647+
Protocol: ptr.To(v1.ProtocolSCTP),
648+
Port: ptr.To[int32](3456),
649649
},
650650
{
651-
Name: pointer.String("udp-example"),
652-
Protocol: protoPtr(v1.ProtocolUDP),
653-
Port: pointer.Int32(161),
651+
Name: ptr.To("udp-example"),
652+
Protocol: ptr.To(v1.ProtocolUDP),
653+
Port: ptr.To[int32](161),
654654
},
655655
{
656-
Name: pointer.String("tcp-example"),
657-
Protocol: protoPtr(v1.ProtocolTCP),
658-
Port: pointer.Int32(80),
656+
Name: ptr.To("tcp-example"),
657+
Protocol: ptr.To(v1.ProtocolTCP),
658+
Port: ptr.To[int32](80),
659659
},
660660
},
661661
expectedEndpoints: []discovery.Endpoint{
662662
{
663663
Conditions: discovery.EndpointConditions{
664-
Ready: pointer.Bool(true),
665-
Serving: pointer.Bool(true),
666-
Terminating: pointer.Bool(false),
664+
Ready: ptr.To(true),
665+
Serving: ptr.To(true),
666+
Terminating: ptr.To(false),
667667
},
668668
Addresses: []string{"10.0.0.1"},
669669
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
670-
NodeName: pointer.String("node-1"),
670+
NodeName: ptr.To("node-1"),
671671
},
672672
{
673673
Conditions: discovery.EndpointConditions{
674-
Ready: pointer.Bool(true),
675-
Serving: pointer.Bool(true),
676-
Terminating: pointer.Bool(false),
674+
Ready: ptr.To(true),
675+
Serving: ptr.To(true),
676+
Terminating: ptr.To(false),
677677
},
678678
Addresses: []string{"10.0.0.2"},
679679
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
680-
NodeName: pointer.String("node-1"),
680+
NodeName: ptr.To("node-1"),
681681
},
682682
},
683683
},
@@ -760,31 +760,31 @@ func TestSyncService(t *testing.T) {
760760
},
761761
expectedEndpointPorts: []discovery.EndpointPort{
762762
{
763-
Name: pointer.String("sctp-example"),
764-
Protocol: protoPtr(v1.ProtocolSCTP),
765-
Port: pointer.Int32(3456),
763+
Name: ptr.To("sctp-example"),
764+
Protocol: ptr.To(v1.ProtocolSCTP),
765+
Port: ptr.To[int32](3456),
766766
},
767767
{
768-
Name: pointer.String("udp-example"),
769-
Protocol: protoPtr(v1.ProtocolUDP),
770-
Port: pointer.Int32(161),
768+
Name: ptr.To("udp-example"),
769+
Protocol: ptr.To(v1.ProtocolUDP),
770+
Port: ptr.To[int32](161),
771771
},
772772
{
773-
Name: pointer.String("tcp-example"),
774-
Protocol: protoPtr(v1.ProtocolTCP),
775-
Port: pointer.Int32(80),
773+
Name: ptr.To("tcp-example"),
774+
Protocol: ptr.To(v1.ProtocolTCP),
775+
Port: ptr.To[int32](80),
776776
},
777777
},
778778
expectedEndpoints: []discovery.Endpoint{
779779
{
780780
Conditions: discovery.EndpointConditions{
781-
Ready: pointer.Bool(true),
782-
Serving: pointer.Bool(true),
783-
Terminating: pointer.Bool(false),
781+
Ready: ptr.To(true),
782+
Serving: ptr.To(true),
783+
Terminating: ptr.To(false),
784784
},
785785
Addresses: []string{"fd08::5678:0000:0000:9abc:def0"},
786786
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
787-
NodeName: pointer.String("node-1"),
787+
NodeName: ptr.To("node-1"),
788788
},
789789
},
790790
},
@@ -865,41 +865,41 @@ func TestSyncService(t *testing.T) {
865865
},
866866
expectedEndpointPorts: []discovery.EndpointPort{
867867
{
868-
Name: pointer.String("sctp-example"),
869-
Protocol: protoPtr(v1.ProtocolSCTP),
870-
Port: pointer.Int32(3456),
868+
Name: ptr.To("sctp-example"),
869+
Protocol: ptr.To(v1.ProtocolSCTP),
870+
Port: ptr.To[int32](3456),
871871
},
872872
{
873-
Name: pointer.String("udp-example"),
874-
Protocol: protoPtr(v1.ProtocolUDP),
875-
Port: pointer.Int32(161),
873+
Name: ptr.To("udp-example"),
874+
Protocol: ptr.To(v1.ProtocolUDP),
875+
Port: ptr.To[int32](161),
876876
},
877877
{
878-
Name: pointer.String("tcp-example"),
879-
Protocol: protoPtr(v1.ProtocolTCP),
880-
Port: pointer.Int32(80),
878+
Name: ptr.To("tcp-example"),
879+
Protocol: ptr.To(v1.ProtocolTCP),
880+
Port: ptr.To[int32](80),
881881
},
882882
},
883883
expectedEndpoints: []discovery.Endpoint{
884884
{
885885
Conditions: discovery.EndpointConditions{
886-
Ready: pointer.Bool(true),
887-
Serving: pointer.Bool(true),
888-
Terminating: pointer.Bool(false),
886+
Ready: ptr.To(true),
887+
Serving: ptr.To(true),
888+
Terminating: ptr.To(false),
889889
},
890890
Addresses: []string{"10.0.0.1"},
891891
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
892-
NodeName: pointer.String("node-1"),
892+
NodeName: ptr.To("node-1"),
893893
},
894894
{
895895
Conditions: discovery.EndpointConditions{
896-
Ready: pointer.Bool(false),
897-
Serving: pointer.Bool(true),
898-
Terminating: pointer.Bool(true),
896+
Ready: ptr.To(false),
897+
Serving: ptr.To(true),
898+
Terminating: ptr.To(true),
899899
},
900900
Addresses: []string{"10.0.0.2"},
901901
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
902-
NodeName: pointer.String("node-1"),
902+
NodeName: ptr.To("node-1"),
903903
},
904904
},
905905
},
@@ -980,41 +980,41 @@ func TestSyncService(t *testing.T) {
980980
},
981981
expectedEndpointPorts: []discovery.EndpointPort{
982982
{
983-
Name: pointer.String("sctp-example"),
984-
Protocol: protoPtr(v1.ProtocolSCTP),
985-
Port: pointer.Int32(3456),
983+
Name: ptr.To("sctp-example"),
984+
Protocol: ptr.To(v1.ProtocolSCTP),
985+
Port: ptr.To[int32](3456),
986986
},
987987
{
988-
Name: pointer.String("udp-example"),
989-
Protocol: protoPtr(v1.ProtocolUDP),
990-
Port: pointer.Int32(161),
988+
Name: ptr.To("udp-example"),
989+
Protocol: ptr.To(v1.ProtocolUDP),
990+
Port: ptr.To[int32](161),
991991
},
992992
{
993-
Name: pointer.String("tcp-example"),
994-
Protocol: protoPtr(v1.ProtocolTCP),
995-
Port: pointer.Int32(80),
993+
Name: ptr.To("tcp-example"),
994+
Protocol: ptr.To(v1.ProtocolTCP),
995+
Port: ptr.To[int32](80),
996996
},
997997
},
998998
expectedEndpoints: []discovery.Endpoint{
999999
{
10001000
Conditions: discovery.EndpointConditions{
1001-
Ready: pointer.Bool(true),
1002-
Serving: pointer.Bool(true),
1003-
Terminating: pointer.Bool(false),
1001+
Ready: ptr.To(true),
1002+
Serving: ptr.To(true),
1003+
Terminating: ptr.To(false),
10041004
},
10051005
Addresses: []string{"10.0.0.1"},
10061006
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
1007-
NodeName: pointer.String("node-1"),
1007+
NodeName: ptr.To("node-1"),
10081008
},
10091009
{
10101010
Conditions: discovery.EndpointConditions{
1011-
Ready: pointer.Bool(false),
1012-
Serving: pointer.Bool(false),
1013-
Terminating: pointer.Bool(true),
1011+
Ready: ptr.To(false),
1012+
Serving: ptr.To(false),
1013+
Terminating: ptr.To(true),
10141014
},
10151015
Addresses: []string{"10.0.0.2"},
10161016
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
1017-
NodeName: pointer.String("node-1"),
1017+
NodeName: ptr.To("node-1"),
10181018
},
10191019
},
10201020
},
@@ -1110,41 +1110,41 @@ func TestSyncService(t *testing.T) {
11101110
},
11111111
expectedEndpointPorts: []discovery.EndpointPort{
11121112
{
1113-
Name: pointer.StringPtr("sctp-example"),
1114-
Protocol: protoPtr(v1.ProtocolSCTP),
1115-
Port: pointer.Int32Ptr(int32(3456)),
1113+
Name: ptr.To("sctp-example"),
1114+
Protocol: ptr.To(v1.ProtocolSCTP),
1115+
Port: ptr.To[int32](3456),
11161116
},
11171117
{
1118-
Name: pointer.StringPtr("udp-example"),
1119-
Protocol: protoPtr(v1.ProtocolUDP),
1120-
Port: pointer.Int32Ptr(int32(161)),
1118+
Name: ptr.To("udp-example"),
1119+
Protocol: ptr.To(v1.ProtocolUDP),
1120+
Port: ptr.To[int32](161),
11211121
},
11221122
{
1123-
Name: pointer.StringPtr("tcp-example"),
1124-
Protocol: protoPtr(v1.ProtocolTCP),
1125-
Port: pointer.Int32Ptr(int32(80)),
1123+
Name: ptr.To("tcp-example"),
1124+
Protocol: ptr.To(v1.ProtocolTCP),
1125+
Port: ptr.To[int32](80),
11261126
},
11271127
},
11281128
expectedEndpoints: []discovery.Endpoint{
11291129
{
11301130
Conditions: discovery.EndpointConditions{
1131-
Ready: pointer.BoolPtr(true),
1132-
Serving: pointer.BoolPtr(true),
1133-
Terminating: pointer.BoolPtr(false),
1131+
Ready: ptr.To(true),
1132+
Serving: ptr.To(true),
1133+
Terminating: ptr.To(false),
11341134
},
11351135
Addresses: []string{"10.0.0.1"},
11361136
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
1137-
NodeName: pointer.StringPtr("node-1"),
1137+
NodeName: ptr.To("node-1"),
11381138
},
11391139
{
11401140
Conditions: discovery.EndpointConditions{
1141-
Ready: pointer.BoolPtr(false),
1142-
Serving: pointer.BoolPtr(false),
1143-
Terminating: pointer.BoolPtr(false),
1141+
Ready: ptr.To(false),
1142+
Serving: ptr.To(false),
1143+
Terminating: ptr.To(false),
11441144
},
11451145
Addresses: []string{"10.0.0.1"},
11461146
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
1147-
NodeName: pointer.StringPtr("node-1"),
1147+
NodeName: ptr.To("node-1"),
11481148
},
11491149
},
11501150
},
@@ -1242,41 +1242,41 @@ func TestSyncService(t *testing.T) {
12421242
},
12431243
expectedEndpointPorts: []discovery.EndpointPort{
12441244
{
1245-
Name: pointer.StringPtr("sctp-example"),
1246-
Protocol: protoPtr(v1.ProtocolSCTP),
1247-
Port: pointer.Int32Ptr(int32(3456)),
1245+
Name: ptr.To("sctp-example"),
1246+
Protocol: ptr.To(v1.ProtocolSCTP),
1247+
Port: ptr.To[int32](3456),
12481248
},
12491249
{
1250-
Name: pointer.StringPtr("udp-example"),
1251-
Protocol: protoPtr(v1.ProtocolUDP),
1252-
Port: pointer.Int32Ptr(int32(161)),
1250+
Name: ptr.To("udp-example"),
1251+
Protocol: ptr.To(v1.ProtocolUDP),
1252+
Port: ptr.To[int32](161),
12531253
},
12541254
{
1255-
Name: pointer.StringPtr("tcp-example"),
1256-
Protocol: protoPtr(v1.ProtocolTCP),
1257-
Port: pointer.Int32Ptr(int32(80)),
1255+
Name: ptr.To("tcp-example"),
1256+
Protocol: ptr.To(v1.ProtocolTCP),
1257+
Port: ptr.To[int32](80),
12581258
},
12591259
},
12601260
expectedEndpoints: []discovery.Endpoint{
12611261
{
12621262
Conditions: discovery.EndpointConditions{
1263-
Ready: pointer.BoolPtr(true),
1264-
Serving: pointer.BoolPtr(true),
1265-
Terminating: pointer.BoolPtr(false),
1263+
Ready: ptr.To(true),
1264+
Serving: ptr.To(true),
1265+
Terminating: ptr.To(false),
12661266
},
12671267
Addresses: []string{"10.0.0.1"},
12681268
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
1269-
NodeName: pointer.StringPtr("node-1"),
1269+
NodeName: ptr.To("node-1"),
12701270
},
12711271
{
12721272
Conditions: discovery.EndpointConditions{
1273-
Ready: pointer.BoolPtr(true),
1274-
Serving: pointer.BoolPtr(true),
1275-
Terminating: pointer.BoolPtr(false),
1273+
Ready: ptr.To(true),
1274+
Serving: ptr.To(true),
1275+
Terminating: ptr.To(false),
12761276
},
12771277
Addresses: []string{"10.0.0.1"},
12781278
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
1279-
NodeName: pointer.StringPtr("node-1"),
1279+
NodeName: ptr.To("node-1"),
12801280
},
12811281
},
12821282
},
@@ -1983,13 +1983,13 @@ func TestUpdateNode(t *testing.T) {
19831983
Endpoints: []discovery.Endpoint{
19841984
{
19851985
Addresses: []string{"172.18.0.2"},
1986-
Zone: pointer.String("zone-a"),
1987-
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
1986+
Zone: ptr.To("zone-a"),
1987+
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
19881988
},
19891989
{
19901990
Addresses: []string{"172.18.1.2"},
1991-
Zone: pointer.String("zone-b"),
1992-
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
1991+
Zone: ptr.To("zone-b"),
1992+
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
19931993
},
19941994
},
19951995
AddressType: discovery.AddressTypeIPv4,
@@ -2090,11 +2090,6 @@ func expectAction(t *testing.T, actions []k8stesting.Action, index int, verb, re
20902090
}
20912091
}
20922092

2093-
// protoPtr takes a Protocol and returns a pointer to it.
2094-
func protoPtr(proto v1.Protocol) *v1.Protocol {
2095-
return &proto
2096-
}
2097-
20982093
// cacheMutationCheck helps ensure that cached objects have not been changed
20992094
// in any way throughout a test run.
21002095
type cacheMutationCheck struct {

0 commit comments

Comments
 (0)