Skip to content

Commit 5157b12

Browse files
HadrienPattetklauser
authored andcommitted
pkg/{aws,azure}: Use go 1.26's new()
See [go 1.26 release notes](https://go.dev/doc/go1.26#language): > The built-in new function, which creates a new variable, now allows its operand to be an expression, specifying the initial value of the variable. > > This feature is particularly useful when working with serialization packages such as encoding/json or protocol buffers that use a pointer to represent an optional value, as it enables an optional field to be populated in a simple expression Followup to cilium#45336 Signed-off-by: Hadrien Patte <hadrien.patte@datadoghq.com>
1 parent c3947b6 commit 5157b12

6 files changed

Lines changed: 48 additions & 76 deletions

File tree

pkg/aws/eni/limits/limits_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/require"
10-
"k8s.io/utils/ptr"
1110

1211
ec2_types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
1312
"github.com/cilium/hive/hivetest"
@@ -30,12 +29,12 @@ func TestGet(t *testing.T) {
3029
api.UpdateInstanceTypes([]ec2_types.InstanceTypeInfo{{
3130
InstanceType: "test.large",
3231
NetworkInfo: &ec2_types.NetworkInfo{
33-
MaximumNetworkInterfaces: ptr.To[int32](4),
34-
Ipv4AddressesPerInterface: ptr.To[int32](5),
35-
Ipv6AddressesPerInterface: ptr.To[int32](6),
32+
MaximumNetworkInterfaces: new(int32(4)),
33+
Ipv4AddressesPerInterface: new(int32(5)),
34+
Ipv6AddressesPerInterface: new(int32(6)),
3635
},
3736
Hypervisor: ec2_types.InstanceTypeHypervisorNitro,
38-
BareMetal: ptr.To(false),
37+
BareMetal: new(false),
3938
}})
4039
newLimitsGetter, err := NewLimitsGetter(hivetest.Logger(t), api, testTriggerMinInterval, testEC2apiTimeout, testEC2apiRetryCount)
4140
require.NoError(t, err)
@@ -59,12 +58,12 @@ func TestGet(t *testing.T) {
5958
api.UpdateInstanceTypes([]ec2_types.InstanceTypeInfo{{
6059
InstanceType: "newtype",
6160
NetworkInfo: &ec2_types.NetworkInfo{
62-
MaximumNetworkInterfaces: ptr.To[int32](4),
63-
Ipv4AddressesPerInterface: ptr.To[int32](15),
64-
Ipv6AddressesPerInterface: ptr.To[int32](15),
61+
MaximumNetworkInterfaces: new(int32(4)),
62+
Ipv4AddressesPerInterface: new(int32(15)),
63+
Ipv6AddressesPerInterface: new(int32(15)),
6564
},
6665
Hypervisor: ec2_types.InstanceTypeHypervisorNitro,
67-
BareMetal: ptr.To(false),
66+
BareMetal: new(false),
6867
}})
6968

7069
limit, ok = newLimitsGetter.Get("newtype")
@@ -90,12 +89,12 @@ func TestInitEC2APIUpdateTrigger(t *testing.T) {
9089
{
9190
InstanceType: "test.large",
9291
NetworkInfo: &ec2_types.NetworkInfo{
93-
MaximumNetworkInterfaces: ptr.To[int32](4),
94-
Ipv4AddressesPerInterface: ptr.To[int32](10),
95-
Ipv6AddressesPerInterface: ptr.To[int32](10),
92+
MaximumNetworkInterfaces: new(int32(4)),
93+
Ipv4AddressesPerInterface: new(int32(10)),
94+
Ipv6AddressesPerInterface: new(int32(10)),
9695
},
9796
Hypervisor: ec2_types.InstanceTypeHypervisorNitro,
98-
BareMetal: ptr.To(false),
97+
BareMetal: new(false),
9998
},
10099
})
101100

pkg/azure/api/api.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
1616
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
1717
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
18-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1918
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
2019
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7"
2120
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v9"
@@ -696,7 +695,7 @@ func (c *Client) AssignPrivateIpAddressesVMSS(ctx context.Context, instanceID, v
696695
var netIfConfig *armcompute.VirtualMachineScaleSetNetworkConfiguration
697696

698697
vmssGetOptions := &armcompute.VirtualMachineScaleSetVMsClientGetOptions{
699-
Expand: to.Ptr(armcompute.InstanceViewTypesInstanceView),
698+
Expand: new(armcompute.InstanceViewTypesInstanceView),
700699
}
701700

702701
c.limiter.Limit(ctx, virtualMachineScaleSetVMsGet)
@@ -735,11 +734,11 @@ func (c *Client) AssignPrivateIpAddressesVMSS(ctx context.Context, instanceID, v
735734
for range addresses {
736735
ipConfigurations = append(ipConfigurations,
737736
&armcompute.VirtualMachineScaleSetIPConfiguration{
738-
Name: to.Ptr(generateIpConfigName()),
737+
Name: new(generateIpConfigName()),
739738
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
740739
ApplicationSecurityGroups: appSecurityGroups,
741-
PrivateIPAddressVersion: to.Ptr(armcompute.IPVersionIPv4),
742-
Subnet: &armcompute.APIEntityReference{ID: to.Ptr(subnetID)},
740+
PrivateIPAddressVersion: new(armcompute.IPVersionIPv4),
741+
Subnet: &armcompute.APIEntityReference{ID: new(subnetID)},
743742
},
744743
},
745744
)
@@ -800,12 +799,12 @@ func (c *Client) AssignPrivateIpAddressesVM(ctx context.Context, subnetID, inter
800799
ipConfigurations := make([]*armnetwork.InterfaceIPConfiguration, 0, addresses)
801800
for range addresses {
802801
ipConfigurations = append(ipConfigurations, &armnetwork.InterfaceIPConfiguration{
803-
Name: to.Ptr(generateIpConfigName()),
802+
Name: new(generateIpConfigName()),
804803
Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
805804
ApplicationSecurityGroups: appSecurityGroups,
806-
PrivateIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodDynamic),
805+
PrivateIPAllocationMethod: new(armnetwork.IPAllocationMethodDynamic),
807806
Subnet: &armnetwork.Subnet{
808-
ID: to.Ptr(subnetID),
807+
ID: new(subnetID),
809808
},
810809
},
811810
})
@@ -848,7 +847,7 @@ func (c *Client) AssignPublicIPAddressesVMSS(ctx context.Context, instanceID, vm
848847
var primaryNetIfConfig *armcompute.VirtualMachineScaleSetNetworkConfiguration
849848

850849
vmssGetOptions := &armcompute.VirtualMachineScaleSetVMsClientGetOptions{
851-
Expand: to.Ptr(armcompute.InstanceViewTypesInstanceView),
850+
Expand: new(armcompute.InstanceViewTypesInstanceView),
852851
}
853852

854853
c.limiter.Limit(ctx, virtualMachineScaleSetVMsGet)
@@ -927,10 +926,10 @@ func (c *Client) AssignPublicIPAddressesVMSS(ctx context.Context, instanceID, vm
927926

928927
// Create a new public IP configuration
929928
primaryIPConfig.Properties.PublicIPAddressConfiguration = &armcompute.VirtualMachineScaleSetPublicIPAddressConfiguration{
930-
Name: to.Ptr("cilium-managed-public-ip"),
929+
Name: new("cilium-managed-public-ip"),
931930
Properties: &armcompute.VirtualMachineScaleSetPublicIPAddressConfigurationProperties{
932931
PublicIPPrefix: &armcompute.SubResource{
933-
ID: to.Ptr(publicIPPrefixID),
932+
ID: new(publicIPPrefixID),
934933
},
935934
},
936935
}
@@ -980,7 +979,7 @@ func (c *Client) AssignPublicIPAddressesVM(ctx context.Context, instanceID strin
980979

981980
// Get the VM
982981
vmGetOptions := &armcompute.VirtualMachinesClientGetOptions{
983-
Expand: to.Ptr(armcompute.InstanceViewTypesInstanceView),
982+
Expand: new(armcompute.InstanceViewTypesInstanceView),
984983
}
985984

986985
c.limiter.Limit(ctx, virtualMachinesGet)
@@ -1062,11 +1061,11 @@ func (c *Client) AssignPublicIPAddressesVM(ctx context.Context, instanceID strin
10621061

10631062
// Assign the public IP prefix to the primary IP configuration
10641063
primaryIPConfig.Properties.PublicIPAddress = &armnetwork.PublicIPAddress{
1065-
Name: to.Ptr("cilium-managed-public-ip"),
1064+
Name: new("cilium-managed-public-ip"),
10661065
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
1067-
PublicIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodStatic),
1066+
PublicIPAllocationMethod: new(armnetwork.IPAllocationMethodStatic),
10681067
PublicIPPrefix: &armnetwork.SubResource{
1069-
ID: to.Ptr(publicIPPrefixID),
1068+
ID: new(publicIPPrefixID),
10701069
},
10711070
},
10721071
}

pkg/azure/api/api_test.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"net/netip"
88
"testing"
99

10-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1110
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7"
1211
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v9"
1312
"github.com/stretchr/testify/require"
@@ -25,52 +24,52 @@ func TestAvailableIPs(t *testing.T) {
2524
func TestFindPublicIPPrefixByTags(t *testing.T) {
2625
prefixes := []*armnetwork.PublicIPPrefix{
2726
{
28-
ID: to.Ptr("prefix1"),
27+
ID: new("prefix1"),
2928
Tags: map[string]*string{
30-
"env": to.Ptr("prod"),
31-
"pool": to.Ptr("pool-1"),
29+
"env": new("prod"),
30+
"pool": new("pool-1"),
3231
},
3332
Properties: &armnetwork.PublicIPPrefixPropertiesFormat{
34-
ProvisioningState: to.Ptr(armnetwork.ProvisioningStateSucceeded),
35-
IPPrefix: to.Ptr("10.0.0.0/28"),
33+
ProvisioningState: new(armnetwork.ProvisioningStateSucceeded),
34+
IPPrefix: new("10.0.0.0/28"),
3635
PublicIPAddresses: []*armnetwork.ReferencedPublicIPAddress{
37-
{ID: to.Ptr("ip1")},
36+
{ID: new("ip1")},
3837
},
3938
},
4039
},
4140
{
42-
ID: to.Ptr("prefix2"),
41+
ID: new("prefix2"),
4342
Tags: map[string]*string{
44-
"env": to.Ptr("dev"),
43+
"env": new("dev"),
4544
},
4645
Properties: &armnetwork.PublicIPPrefixPropertiesFormat{
47-
ProvisioningState: to.Ptr(armnetwork.ProvisioningStateSucceeded),
48-
IPPrefix: to.Ptr("10.1.0.0/28"),
46+
ProvisioningState: new(armnetwork.ProvisioningStateSucceeded),
47+
IPPrefix: new("10.1.0.0/28"),
4948
},
5049
},
5150
{
5251
// Not provisioned
53-
ID: to.Ptr("prefix3"),
52+
ID: new("prefix3"),
5453
Tags: map[string]*string{
55-
"env": to.Ptr("staging"),
54+
"env": new("staging"),
5655
},
5756
Properties: &armnetwork.PublicIPPrefixPropertiesFormat{
58-
ProvisioningState: to.Ptr(armnetwork.ProvisioningStateFailed),
59-
IPPrefix: to.Ptr("10.2.0.0/28"),
57+
ProvisioningState: new(armnetwork.ProvisioningStateFailed),
58+
IPPrefix: new("10.2.0.0/28"),
6059
},
6160
},
6261
{
6362
// Full
64-
ID: to.Ptr("prefix4"),
63+
ID: new("prefix4"),
6564
Tags: map[string]*string{
66-
"env": to.Ptr("test"),
65+
"env": new("test"),
6766
},
6867
Properties: &armnetwork.PublicIPPrefixPropertiesFormat{
69-
ProvisioningState: to.Ptr(armnetwork.ProvisioningStateSucceeded),
70-
IPPrefix: to.Ptr("10.3.0.0/31"), // 2 IPs
68+
ProvisioningState: new(armnetwork.ProvisioningStateSucceeded),
69+
IPPrefix: new("10.3.0.0/31"), // 2 IPs
7170
PublicIPAddresses: []*armnetwork.ReferencedPublicIPAddress{
72-
{ID: to.Ptr("ip1")},
73-
{ID: to.Ptr("ip2")},
71+
{ID: new("ip1")},
72+
{ID: new("ip2")},
7473
},
7574
},
7675
},
@@ -120,7 +119,7 @@ func TestIsPublicIPProvisionFailed(t *testing.T) {
120119
name: "success",
121120
instanceViewStatuses: []*armcompute.InstanceViewStatus{
122121
{
123-
Code: to.Ptr("ProvisioningState/succeeded"),
122+
Code: new("ProvisioningState/succeeded"),
124123
},
125124
},
126125
expected: false,
@@ -129,7 +128,7 @@ func TestIsPublicIPProvisionFailed(t *testing.T) {
129128
name: "failure",
130129
instanceViewStatuses: []*armcompute.InstanceViewStatus{
131130
{
132-
Code: to.Ptr("ProvisioningState/failed/PublicIpPrefixOutOfIpAddressesForVMScaleSet"),
131+
Code: new("ProvisioningState/failed/PublicIpPrefixOutOfIpAddressesForVMScaleSet"),
133132
},
134133
},
135134
expected: true,

vendor/github.com/Azure/azure-sdk-for-go/sdk/azcore/to/doc.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

vendor/github.com/Azure/azure-sdk-for-go/sdk/azcore/to/to.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

vendor/modules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore/log
2828
github.com/Azure/azure-sdk-for-go/sdk/azcore/policy
2929
github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime
3030
github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming
31-
github.com/Azure/azure-sdk-for-go/sdk/azcore/to
3231
github.com/Azure/azure-sdk-for-go/sdk/azcore/tracing
3332
# github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1
3433
## explicit; go 1.23.0

0 commit comments

Comments
 (0)