Skip to content

Commit eaebb7c

Browse files
committed
Use Go 1.26 new() instead of ptr.To()
Signed-off-by: Stephen Kitt <skitt@redhat.com>
1 parent c54a3c7 commit eaebb7c

9 files changed

Lines changed: 20 additions & 28 deletions

File tree

pkg/cable/wireguard/driver.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/vishvananda/netlink"
4141
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
4242
k8snet "k8s.io/utils/net"
43-
"k8s.io/utils/ptr"
4443
logf "sigs.k8s.io/controller-runtime/pkg/log"
4544
)
4645

@@ -146,7 +145,7 @@ func NewDriver(localEndpoint *endpoint.Local, _ *types.SubmarinerCluster, _ cert
146145
peerConfigs := make([]wgtypes.PeerConfig, 0)
147146
cfg := wgtypes.Config{
148147
PrivateKey: &priv,
149-
ListenPort: ptr.To(int(port)),
148+
ListenPort: new(int(port)),
150149
FirewallMark: nil,
151150
ReplacePeers: true,
152151
Peers: peerConfigs,
@@ -272,7 +271,7 @@ func (w *wireguard) ConnectToEndpoint(endpointInfo *natdiscovery.NATEndpointInfo
272271
IP: remoteIP,
273272
Port: remotePort,
274273
},
275-
PersistentKeepaliveInterval: ptr.To(KeepAliveInterval),
274+
PersistentKeepaliveInterval: new(KeepAliveInterval),
276275
ReplaceAllowedIPs: true,
277276
AllowedIPs: allowedIPs,
278277
}}

pkg/globalnet/controllers/cluster_egressip_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4141
"k8s.io/apimachinery/pkg/runtime"
4242
"k8s.io/client-go/tools/cache"
43-
"k8s.io/utils/ptr"
4443
)
4544

4645
func NewClusterGlobalEgressIPController(ctx context.Context, config *syncer.ResourceSyncerConfig, localSubnets []string,
@@ -68,7 +67,7 @@ func NewClusterGlobalEgressIPController(ctx context.Context, config *syncer.Reso
6867
Name: constants.ClusterGlobalEgressIPName,
6968
},
7069
Spec: submarinerv1.ClusterGlobalEgressIPSpec{
71-
NumberOfIPs: ptr.To(DefaultNumberOfClusterEgressIPs),
70+
NumberOfIPs: new(DefaultNumberOfClusterEgressIPs),
7271
},
7372
}
7473

pkg/globalnet/controllers/cluster_egressip_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/submariner-io/submariner/pkg/globalnet/metrics"
3636
"github.com/submariner-io/submariner/pkg/packetfilter"
3737
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38-
"k8s.io/utils/ptr"
3938
)
4039

4140
var _ = Describe("ClusterGlobalEgressIP controller", func() {
@@ -212,7 +211,7 @@ var _ = Describe("ClusterGlobalEgressIP controller", func() {
212211
})
213212

214213
JustBeforeEach(func(ctx context.Context) {
215-
existing.Spec.NumberOfIPs = ptr.To(numberOfIPs)
214+
existing.Spec.NumberOfIPs = new(numberOfIPs)
216215
test.UpdateResource(ctx, t.clusterGlobalEgressIPs, existing)
217216
})
218217

pkg/globalnet/controllers/gateway_monitor.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import (
4848
"k8s.io/client-go/tools/leaderelection"
4949
"k8s.io/client-go/tools/leaderelection/resourcelock"
5050
k8snet "k8s.io/utils/net"
51-
"k8s.io/utils/ptr"
5251
"k8s.io/utils/set"
5352
)
5453

@@ -460,7 +459,7 @@ func (g *gatewayMonitor) startLocalGatewayCleanupController() error {
460459

461460
syncerConfig := NewGatewayResourceSyncerConfig(g.syncerConfig, g.Spec.Namespace)
462461
syncerConfig.Federator = federate.NewNoopFederator()
463-
syncerConfig.WaitForCacheSync = ptr.To(false)
462+
syncerConfig.WaitForCacheSync = new(false)
464463
syncerConfig.Name = "Gateway cleanup syncer"
465464

466465
// Here we run a resource syncer that removes the ingress rules for the local Gateway resource when it is deleted.

pkg/globalnet/controllers/global_ingressip_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"k8s.io/apimachinery/pkg/runtime"
4141
"k8s.io/apimachinery/pkg/util/wait"
4242
"k8s.io/client-go/tools/cache"
43-
"k8s.io/utils/ptr"
4443
)
4544

4645
func NewGlobalIngressIPController(ctx context.Context, config *syncer.ResourceSyncerConfig, pool *ipam.IPPool,
@@ -298,7 +297,7 @@ func (c *globalIngressIPController) createOrUpdateInternalService(ctx context.Co
298297
Ports: from.Spec.Ports,
299298
Selector: from.Spec.Selector,
300299
ExternalIPs: []string{extIP},
301-
IPFamilyPolicy: ptr.To(corev1.IPFamilyPolicySingleStack),
300+
IPFamilyPolicy: new(corev1.IPFamilyPolicySingleStack),
302301
PublishNotReadyAddresses: from.Spec.PublishNotReadyAddresses,
303302
},
304303
}

pkg/packetfilter/nftables/namedset.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/pkg/errors"
2626
"github.com/submariner-io/submariner/pkg/packetfilter"
2727
k8snet "k8s.io/utils/net"
28-
"k8s.io/utils/ptr"
2928
"sigs.k8s.io/knftables"
3029
)
3130

@@ -54,7 +53,7 @@ func (n *namedSet) Create(_ bool) error {
5453
tx := n.nftables.NewTransaction()
5554

5655
tx.Add(&knftables.Table{
57-
Comment: ptr.To("rules for submariner"),
56+
Comment: new("rules for submariner"),
5857
})
5958

6059
tx.Add(&n.set)

pkg/packetfilter/nftables/nftables.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ func (p *packetFilter) CreateIPHookChainIfNotExists(chain *packetfilter.ChainIPH
147147

148148
tx.Add(&knftables.Chain{
149149
Name: chain.Name,
150-
Type: ptr.To(iphookChainTypeToNftablesType[chain.Type]),
151-
Hook: ptr.To(iphookChainHookToNftablesHook[chain.Hook]),
152-
Priority: ptr.To(chainPriority),
150+
Type: new(iphookChainTypeToNftablesType[chain.Type]),
151+
Hook: new(iphookChainHookToNftablesHook[chain.Hook]),
152+
Priority: new(chainPriority),
153153
})
154154

155155
err := p.nftables.Run(context.TODO(), tx)
@@ -171,7 +171,7 @@ func (p *packetFilter) CreateChainIfNotExists(_ packetfilter.TableType, chain *p
171171
func (p *packetFilter) newTransactionWithTable() *knftables.Transaction {
172172
tx := p.nftables.NewTransaction()
173173
tx.Add(&knftables.Table{
174-
Comment: ptr.To("rules for submariner"),
174+
Comment: new("rules for submariner"),
175175
})
176176

177177
return tx
@@ -291,7 +291,7 @@ func (p *packetFilter) insertRuleAtPosition(chain string, rule *packetfilter.Rul
291291
knftRule := knftables.Rule{
292292
Chain: chain,
293293
Rule: ruleSpec,
294-
Comment: ptr.To(SerializeRule(rule)),
294+
Comment: new(SerializeRule(rule)),
295295
}
296296

297297
tx := p.newTransactionWithTable()
@@ -301,7 +301,7 @@ func (p *packetFilter) insertRuleAtPosition(chain string, rule *packetfilter.Rul
301301
} else {
302302
if pos > 1 {
303303
// Index is the number of a rule (counting from 0) to add this rule after
304-
knftRule.Index = ptr.To(pos - 2)
304+
knftRule.Index = new(pos - 2)
305305
}
306306

307307
tx.Add(&knftRule)

pkg/routeagent_driver/handlers/ovn/handler_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
corev1 "k8s.io/api/core/v1"
4848
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4949
k8snet "k8s.io/utils/net"
50-
"k8s.io/utils/ptr"
5150
)
5251

5352
const (
@@ -432,7 +431,7 @@ func (t *handlerTestDriver) testGatewayRoute(ipFamilySubnets []string, nonIPFami
432431
for _, cidr := range gwRoute.RoutePolicySpec.RemoteCIDRs {
433432
t.ovsdbClient.AwaitModel(&nbdb.LogicalRouterPolicy{
434433
Match: cidr,
435-
Nexthop: ptr.To(gwRoute.RoutePolicySpec.NextHops[0]),
434+
Nexthop: new(gwRoute.RoutePolicySpec.NextHops[0]),
436435
})
437436

438437
t.ovsdbClient.AwaitModel(&nbdb.LogicalRouterStaticRoute{
@@ -445,7 +444,7 @@ func (t *handlerTestDriver) testGatewayRoute(ipFamilySubnets []string, nonIPFami
445444
for _, cidr := range gwRoute.RoutePolicySpec.RemoteCIDRs {
446445
t.ovsdbClient.AwaitNoModel(&nbdb.LogicalRouterPolicy{
447446
Match: cidr,
448-
Nexthop: ptr.To(gwRoute.RoutePolicySpec.NextHops[0]),
447+
Nexthop: new(gwRoute.RoutePolicySpec.NextHops[0]),
449448
})
450449

451450
t.ovsdbClient.AwaitNoModel(&nbdb.LogicalRouterStaticRoute{
@@ -543,7 +542,7 @@ func (t *handlerTestDriver) testGatewayRoute(ipFamilySubnets []string, nonIPFami
543542
Priority: priority,
544543
Match: ipMatchField + " == " + t.clusterCIDR,
545544
Action: "reroute",
546-
Nexthop: ptr.To(t.OVNK8sMgmntIntCIDR[t.ipFamily].IP.String()),
545+
Nexthop: new(t.OVNK8sMgmntIntCIDR[t.ipFamily].IP.String()),
547546
ExternalIDs: map[string]string{}, // No submariner tag
548547
}
549548

@@ -608,7 +607,7 @@ func (t *handlerTestDriver) testNonGatewayRoutes(ipFamilyNextHop string, ipFamil
608607
for _, cidr := range ngr.RoutePolicySpec.RemoteCIDRs {
609608
t.ovsdbClient.AwaitModel(&nbdb.LogicalRouterPolicy{
610609
Match: cidr,
611-
Nexthop: ptr.To(nextHop),
610+
Nexthop: new(nextHop),
612611
})
613612
}
614613
}
@@ -617,7 +616,7 @@ func (t *handlerTestDriver) testNonGatewayRoutes(ipFamilyNextHop string, ipFamil
617616
for _, cidr := range ngr.RoutePolicySpec.RemoteCIDRs {
618617
t.ovsdbClient.AwaitNoModel(&nbdb.LogicalRouterPolicy{
619618
Match: cidr,
620-
Nexthop: ptr.To(nextHop),
619+
Nexthop: new(nextHop),
621620
})
622621
}
623622
}
@@ -704,7 +703,7 @@ func (t *handlerTestDriver) testNonGatewayRoutes(ipFamilyNextHop string, ipFamil
704703
for _, cidr := range nonIPFamilyCIDRs {
705704
t.ovsdbClient.EnsureNoModel(&nbdb.LogicalRouterPolicy{
706705
Match: cidr,
707-
Nexthop: ptr.To(nonIPFamilyNextHop),
706+
Nexthop: new(nonIPFamilyNextHop),
708707
})
709708
}
710709
})

pkg/routeagent_driver/handlers/ovn/ovn_logical_routes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/submariner-io/submariner/pkg/versions"
2929
"k8s.io/apimachinery/pkg/util/sets"
3030
k8snet "k8s.io/utils/net"
31-
"k8s.io/utils/ptr"
3231
)
3332

3433
const (
@@ -158,7 +157,7 @@ func buildLRPsFromSubnets(family k8snet.IPFamily, subnetsToAdd []string, nextHop
158157
Priority: priority,
159158
Action: "reroute",
160159
Match: match,
161-
Nexthop: ptr.To(nextHop),
160+
Nexthop: new(nextHop),
162161
ExternalIDs: map[string]string{
163162
SubmarinerExternalIDKey: versions.Submariner(),
164163
},

0 commit comments

Comments
 (0)