diff --git a/.golangci.yaml b/.golangci.yaml index c7167bd3..70769e22 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -20,6 +20,7 @@ linters: - importas - ineffassign - misspell + - modernize - nakedret - noctx - nolintlint diff --git a/go.mod b/go.mod index 76b09526..db58b566 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/stackitcloud/cloud-provider-stackit -go 1.25.0 - -toolchain go1.26.1 +go 1.26.1 require ( github.com/container-storage-interface/spec v1.12.0 diff --git a/pkg/ccm/instances_test.go b/pkg/ccm/instances_test.go index 8c8ce4ad..95e66258 100644 --- a/pkg/ccm/instances_test.go +++ b/pkg/ccm/instances_test.go @@ -29,7 +29,6 @@ import ( "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" ) var _ = Describe("Node Controller", func() { @@ -83,7 +82,7 @@ var _ = Describe("Node Controller", func() { It("successfully get the instance when provider ID not there", func() { nodeMockClient.EXPECT().ListServers(gomock.Any(), projectID, region).Return(&[]iaas.Server{ { - Name: ptr.To("foo"), + Name: new("foo"), }, }, nil) @@ -98,7 +97,7 @@ var _ = Describe("Node Controller", func() { It("successfully get the instance when provider ID is there", func() { nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{ - Name: ptr.To("foo"), + Name: new("foo"), }, nil) node := &corev1.Node{ @@ -115,7 +114,7 @@ var _ = Describe("Node Controller", func() { It("successfully get the instance when old provider ID is there", func() { nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{ - Name: ptr.To("foo"), + Name: new("foo"), }, nil) node := &corev1.Node{ @@ -132,7 +131,7 @@ var _ = Describe("Node Controller", func() { It("successfully get the instance when old regional provider ID is there", func() { nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{ - Name: ptr.To("foo"), + Name: new("foo"), }, nil) node := &corev1.Node{ @@ -178,8 +177,8 @@ var _ = Describe("Node Controller", func() { It("successfully gets the instance status with provider ID", func() { nodeMockClient.EXPECT().ListServers(gomock.Any(), projectID, region).Return(&[]iaas.Server{ { - Name: ptr.To("foo"), - Status: ptr.To(instanceStopping), + Name: new("foo"), + Status: new(instanceStopping), }, }, nil) @@ -194,8 +193,8 @@ var _ = Describe("Node Controller", func() { It("successfully gets the instance status without provider ID", func() { nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{ - Name: ptr.To("foo"), - Status: ptr.To("ACTIVE"), + Name: new("foo"), + Status: new("ACTIVE"), }, nil) node := &corev1.Node{ @@ -239,12 +238,12 @@ var _ = Describe("Node Controller", func() { It("successfully get all the metadata values", func() { nodeMockClient.EXPECT().ListServers(gomock.Any(), projectID, region).Return(&[]iaas.Server{ { - Name: ptr.To("foo"), - Id: ptr.To(serverID), - MachineType: ptr.To("flatcar"), + Name: new("foo"), + Id: new(serverID), + MachineType: new("flatcar"), Nics: &[]iaas.ServerNetwork{ { - Ipv4: ptr.To("10.10.100.24"), + Ipv4: new("10.10.100.24"), }, }, }, diff --git a/pkg/ccm/loadbalancer.go b/pkg/ccm/loadbalancer.go index 675150d3..9843cbb2 100644 --- a/pkg/ccm/loadbalancer.go +++ b/pkg/ccm/loadbalancer.go @@ -12,7 +12,6 @@ import ( "k8s.io/client-go/tools/record" cloudprovider "k8s.io/cloud-provider" "k8s.io/cloud-provider/api" - "k8s.io/utils/ptr" "github.com/stackitcloud/cloud-provider-stackit/pkg/cmp" "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit" @@ -215,7 +214,7 @@ func (l *LoadBalancer) createLoadBalancer(ctx context.Context, clusterName strin return nil, fmt.Errorf("invalid load balancer specification: %w", err) } if l.opts.ExtraLabels != nil { - spec.Labels = ptr.To(l.opts.ExtraLabels) + spec.Labels = new(l.opts.ExtraLabels) } for _, event := range events { l.recorder.Event(service, event.Type, event.Reason, event.Message) @@ -433,7 +432,7 @@ func loadBalancerStatus(lb *loadbalancer.LoadBalancer, svc *corev1.Service) *cor if ip != nil { ingress := corev1.LoadBalancerIngress{IP: *ip} if ipModeProxy, _ := strconv.ParseBool(svc.Annotations[ipModeProxyAnnotation]); ipModeProxy { - ingress.IPMode = ptr.To(corev1.LoadBalancerIPModeProxy) + ingress.IPMode = new(corev1.LoadBalancerIPModeProxy) } ingresses = []corev1.LoadBalancerIngress{ingress} } diff --git a/pkg/ccm/loadbalancer_spec.go b/pkg/ccm/loadbalancer_spec.go index f60863a7..9c98a91b 100644 --- a/pkg/ccm/loadbalancer_spec.go +++ b/pkg/ccm/loadbalancer_spec.go @@ -3,14 +3,13 @@ package ccm import ( "fmt" "net/netip" + "slices" "strconv" "strings" "time" - "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" "github.com/stackitcloud/cloud-provider-stackit/pkg/cmp" ) @@ -216,10 +215,8 @@ func proxyProtocolEnableForPort(tcpProxyProtocolEnabled bool, tcpProxyProtocolPo func getPlanID(service *corev1.Service) (planID *string, msgs []string, err error) { msgs = make([]string, 0) if planID, found := service.Annotations[servicePlanAnnotation]; found { - for _, availablePlan := range availablePlanIDs { - if planID == availablePlan { - return &planID, nil, nil - } + if slices.Contains(availablePlanIDs, planID) { + return &planID, nil, nil } return nil, nil, fmt.Errorf("unsupported plan ID value %q, supported values are %v", planID, availablePlanIDs) } @@ -251,7 +248,7 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex. Options: &loadbalancer.LoadBalancerOptions{}, Networks: &[]loadbalancer.Network{ { - Role: utils.Ptr(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS), + Role: new(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS), NetworkId: &opts.NetworkID, }, }, @@ -260,17 +257,17 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex. if listenerNetwork := service.Annotations[listenerNetworkAnnotation]; listenerNetwork != "" { lb.Networks = &[]loadbalancer.Network{ { - Role: utils.Ptr(loadbalancer.NETWORKROLE_TARGETS), + Role: new(loadbalancer.NETWORKROLE_TARGETS), NetworkId: &opts.NetworkID, }, { - Role: utils.Ptr(loadbalancer.NETWORKROLE_LISTENERS), + Role: new(loadbalancer.NETWORKROLE_LISTENERS), NetworkId: &listenerNetwork, }, } } else { lb.Networks = &[]loadbalancer.Network{ { - Role: utils.Ptr(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS), + Role: new(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS), NetworkId: &opts.NetworkID, }, } @@ -278,7 +275,7 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex. // Add extraLabels if set if opts.ExtraLabels != nil { - lb.Labels = ptr.To(opts.ExtraLabels) + lb.Labels = new(opts.ExtraLabels) } // Add metric metricsRemoteWrite settings @@ -288,7 +285,7 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex. // Parse private network from annotations. // TODO: Split into separate function. - lb.Options.PrivateNetworkOnly = utils.Ptr(false) + lb.Options.PrivateNetworkOnly = new(false) var internal *bool var yawolInternal *bool if internalStr, found := service.Annotations[internalLBAnnotation]; found { @@ -333,9 +330,9 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex. "incompatible values for annotations %s and %s", yawolExistingFloatingIPAnnotation, externalIPAnnotation, ) } - lb.Options.EphemeralAddress = utils.Ptr(false) + lb.Options.EphemeralAddress = new(false) if !found && !yawolFound && !*lb.Options.PrivateNetworkOnly { - lb.Options.EphemeralAddress = utils.Ptr(true) + lb.Options.EphemeralAddress = new(true) } if !found && yawolFound { externalIP = yawolExternalIP @@ -507,12 +504,12 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex. protocol = loadbalancer.LISTENERPROTOCOL_TCP } tcpOptions = &loadbalancer.OptionsTCP{ - IdleTimeout: utils.Ptr(fmt.Sprintf("%.0fs", tcpIdleTimeout.Seconds())), + IdleTimeout: new(fmt.Sprintf("%.0fs", tcpIdleTimeout.Seconds())), } case corev1.ProtocolUDP: protocol = loadbalancer.LISTENERPROTOCOL_UDP udpOptions = &loadbalancer.OptionsUDP{ - IdleTimeout: utils.Ptr(fmt.Sprintf("%.0fs", udpIdleTimeout.Seconds())), + IdleTimeout: new(fmt.Sprintf("%.0fs", udpIdleTimeout.Seconds())), } default: return nil, nil, fmt.Errorf("unsupported protocol %q for port %q", port.Protocol, port.Name) @@ -520,19 +517,19 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex. listeners = append(listeners, loadbalancer.Listener{ DisplayName: &name, - Port: utils.Ptr(int64(port.Port)), + Port: new(int64(port.Port)), TargetPool: &name, - Protocol: utils.Ptr(protocol), + Protocol: new(protocol), Tcp: tcpOptions, Udp: udpOptions, }) targetPools = append(targetPools, loadbalancer.TargetPool{ Name: &name, - TargetPort: utils.Ptr(int64(port.NodePort)), + TargetPort: new(int64(port.NodePort)), Targets: &targets, SessionPersistence: &loadbalancer.SessionPersistence{ - UseSourceIpAddress: utils.Ptr(useSourceIP), + UseSourceIpAddress: new(useSourceIP), }, }) } diff --git a/pkg/ccm/loadbalancer_spec_test.go b/pkg/ccm/loadbalancer_spec_test.go index 590faf1b..029214e9 100644 --- a/pkg/ccm/loadbalancer_spec_test.go +++ b/pkg/ccm/loadbalancer_spec_test.go @@ -8,7 +8,6 @@ import ( . "github.com/onsi/gomega/gstruct" "github.com/onsi/gomega/types" - "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -188,7 +187,7 @@ var _ = Describe("lbSpecFromService", func() { pushURL := "test-endpoint" spec, _, err := lbSpecFromService(&corev1.Service{}, []*corev1.Node{}, lbOpts, &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), + CredentialsRef: new(sampleCredentialsRef), PushUrl: &pushURL, }, }) @@ -500,8 +499,8 @@ var _ = Describe("lbSpecFromService", func() { Expect(spec.TargetPools).To(PointTo(HaveLen(2))) Expect(spec.TargetPools).To(PointTo(HaveEach( haveTargets(ContainElements(loadbalancer.Target{ - DisplayName: utils.Ptr("node-1"), - Ip: utils.Ptr("10.2.3.4"), + DisplayName: new("node-1"), + Ip: new("10.2.3.4"), }))))) }) @@ -533,8 +532,8 @@ var _ = Describe("lbSpecFromService", func() { Expect(spec.TargetPools).To(PointTo(ConsistOf( haveTargets(ConsistOf( // node-2 is missing loadbalancer.Target{ - DisplayName: utils.Ptr("node-1"), - Ip: utils.Ptr("10.2.3.4"), + DisplayName: new("node-1"), + Ip: new("10.2.3.4"), }, )), ))) @@ -1232,30 +1231,30 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: true, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), Observability: &loadbalancer.LoadbalancerOptionObservability{ Logs: &loadbalancer.LoadbalancerOptionLogs{ - CredentialsRef: ptr.To("credentials-12345"), - PushUrl: ptr.To("https://logs.example.org"), + CredentialsRef: new("credentials-12345"), + PushUrl: new("https://logs.example.org"), }, Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To("credentials-12345"), - PushUrl: ptr.To("https://metrics.example.org"), + CredentialsRef: new("credentials-12345"), + PushUrl: new("https://metrics.example.org"), }, }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), Observability: &loadbalancer.LoadbalancerOptionObservability{ Logs: &loadbalancer.LoadbalancerOptionLogs{ - CredentialsRef: ptr.To("credentials-12345"), - PushUrl: ptr.To("https://logs.example.org"), + CredentialsRef: new("credentials-12345"), + PushUrl: new("https://logs.example.org"), }, Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To("credentials-12345"), - PushUrl: ptr.To("https://metrics.example.org"), + CredentialsRef: new("credentials-12345"), + PushUrl: new("https://metrics.example.org"), }, }, }, @@ -1266,18 +1265,18 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), Observability: &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To("credentials-12345"), - PushUrl: ptr.To("https://metrics.example.org"), + CredentialsRef: new("credentials-12345"), + PushUrl: new("https://metrics.example.org"), }, }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, }, }), @@ -1285,15 +1284,15 @@ var _ = DescribeTable("compareLBwithSpec", // The load balancer API uses the same field to report an ephemeral IP and to reference a static IP. wantFulfilled: true, lb: &loadbalancer.LoadBalancer{ - ExternalAddress: utils.Ptr("123.124.88.99"), + ExternalAddress: new("123.124.88.99"), Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(true), + EphemeralAddress: new(true), }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ ExternalAddress: nil, Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(true), + EphemeralAddress: new(true), }, }, }), @@ -1301,15 +1300,15 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, wantImmutabledChanged: nil, lb: &loadbalancer.LoadBalancer{ - PlanId: loadbalancer.PtrString("p10"), + PlanId: new("p10"), Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(true), + EphemeralAddress: new(true), }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ - PlanId: loadbalancer.PtrString("p250"), + PlanId: new("p250"), Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(true), + EphemeralAddress: new(true), }, }, }), @@ -1319,31 +1318,31 @@ var _ = DescribeTable("compareLBwithSpec", ExternalAddress: nil, }, spec: &loadbalancer.CreateLoadBalancerPayload{ - ExternalAddress: utils.Ptr("123.124.88.99"), + ExternalAddress: new("123.124.88.99"), }, }), Entry("When specified and actual IP don't match", &compareLBwithSpecTest{ // The IP can never be changed. Not even with promotion or demotion. wantImmutabledChanged: &resultImmutableChanged{field: ".externalAddress", annotation: externalIPAnnotation}, lb: &loadbalancer.LoadBalancer{ - ExternalAddress: utils.Ptr("123.124.88.01"), + ExternalAddress: new("123.124.88.01"), }, spec: &loadbalancer.CreateLoadBalancerPayload{ - ExternalAddress: utils.Ptr("123.124.88.99"), + ExternalAddress: new("123.124.88.99"), }, }), Entry("When IP is to be promoted", &compareLBwithSpecTest{ wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ - ExternalAddress: utils.Ptr("123.124.88.99"), + ExternalAddress: new("123.124.88.99"), Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(true), + EphemeralAddress: new(true), }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ - ExternalAddress: utils.Ptr("123.124.88.99"), + ExternalAddress: new("123.124.88.99"), Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(false), + EphemeralAddress: new(false), }, }, }), @@ -1351,13 +1350,13 @@ var _ = DescribeTable("compareLBwithSpec", wantImmutabledChanged: &resultImmutableChanged{field: ".options.ephemeralAddress", annotation: externalIPAnnotation}, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(false), + EphemeralAddress: new(false), }, - ExternalAddress: utils.Ptr("123.124.88.99"), + ExternalAddress: new("123.124.88.99"), }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - EphemeralAddress: utils.Ptr(true), + EphemeralAddress: new(true), }, }, }), @@ -1365,7 +1364,7 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ {}, {}, @@ -1373,7 +1372,7 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ {}, @@ -1384,18 +1383,18 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {DisplayName: utils.Ptr("port-a")}, + {DisplayName: new("port-a")}, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {DisplayName: utils.Ptr("port-b")}, + {DisplayName: new("port-b")}, }, }, }), @@ -1403,18 +1402,18 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {Port: utils.Ptr[int64](80)}, + {Port: new(int64(80))}, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {Port: utils.Ptr[int64](443)}, + {Port: new(int64(443))}, }, }, }), @@ -1422,18 +1421,18 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_TCP)}, + {Protocol: new(loadbalancer.LISTENERPROTOCOL_TCP)}, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_TCP_PROXY)}, + {Protocol: new(loadbalancer.LISTENERPROTOCOL_TCP_PROXY)}, }, }, }), @@ -1441,26 +1440,26 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ { - Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_TCP), + Protocol: new(loadbalancer.LISTENERPROTOCOL_TCP), Tcp: &loadbalancer.OptionsTCP{ - IdleTimeout: utils.Ptr("60s"), + IdleTimeout: new("60s"), }, }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ { - Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_TCP), + Protocol: new(loadbalancer.LISTENERPROTOCOL_TCP), Tcp: &loadbalancer.OptionsTCP{ - IdleTimeout: utils.Ptr("120s"), + IdleTimeout: new("120s"), }, }, }, @@ -1470,26 +1469,26 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ { - Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_UDP), + Protocol: new(loadbalancer.LISTENERPROTOCOL_UDP), Udp: &loadbalancer.OptionsUDP{ - IdleTimeout: utils.Ptr("60s"), + IdleTimeout: new("60s"), }, }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ { - Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_UDP), + Protocol: new(loadbalancer.LISTENERPROTOCOL_UDP), Udp: &loadbalancer.OptionsUDP{ - IdleTimeout: utils.Ptr("120s"), + IdleTimeout: new("120s"), }, }, }, @@ -1499,26 +1498,26 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ { - Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_TCP_PROXY), + Protocol: new(loadbalancer.LISTENERPROTOCOL_TCP_PROXY), Tcp: &loadbalancer.OptionsTCP{ - IdleTimeout: utils.Ptr("60s"), + IdleTimeout: new("60s"), }, }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ { - Protocol: utils.Ptr(loadbalancer.LISTENERPROTOCOL_TCP_PROXY), + Protocol: new(loadbalancer.LISTENERPROTOCOL_TCP_PROXY), Tcp: &loadbalancer.OptionsTCP{ - IdleTimeout: utils.Ptr("120s"), + IdleTimeout: new("120s"), }, }, }, @@ -1528,18 +1527,18 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {TargetPool: utils.Ptr("target-pool-a")}, + {TargetPool: new("target-pool-a")}, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Listeners: &[]loadbalancer.Listener{ - {TargetPool: utils.Ptr("target-pool-b")}, + {TargetPool: new("target-pool-b")}, }, }, }), @@ -1547,13 +1546,13 @@ var _ = DescribeTable("compareLBwithSpec", wantImmutabledChanged: &resultImmutableChanged{field: "len(.networks)", annotation: listenerNetworkAnnotation}, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Networks: nil, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Networks: &[]loadbalancer.Network{ {}, @@ -1564,21 +1563,21 @@ var _ = DescribeTable("compareLBwithSpec", wantImmutabledChanged: &resultImmutableChanged{field: ".networks[0].networkId", annotation: listenerNetworkAnnotation}, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Networks: &[]loadbalancer.Network{ { - NetworkId: utils.Ptr("my-network"), + NetworkId: new("my-network"), }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Networks: &[]loadbalancer.Network{ { - NetworkId: utils.Ptr("other-network"), + NetworkId: new("other-network"), }, }, }, @@ -1587,21 +1586,21 @@ var _ = DescribeTable("compareLBwithSpec", wantImmutabledChanged: &resultImmutableChanged{field: ".networks[0].role", annotation: listenerNetworkAnnotation}, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Networks: &[]loadbalancer.Network{ { - Role: utils.Ptr(loadbalancer.NETWORKROLE_LISTENERS), + Role: new(loadbalancer.NETWORKROLE_LISTENERS), }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, Networks: &[]loadbalancer.Network{ { - Role: utils.Ptr(loadbalancer.NETWORKROLE_TARGETS), + Role: new(loadbalancer.NETWORKROLE_TARGETS), }, }, }, @@ -1610,7 +1609,7 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ {}, @@ -1618,7 +1617,7 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ {}, {}, @@ -1629,21 +1628,21 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { - Name: utils.Ptr("target-pool-a"), + Name: new("target-pool-a"), }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { - Name: utils.Ptr("target-pool-b"), + Name: new("target-pool-b"), }, }, }, @@ -1652,21 +1651,21 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { - TargetPort: utils.Ptr[int64](80), + TargetPort: new(int64(80)), }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { - TargetPort: utils.Ptr[int64](443), + TargetPort: new(int64(443)), }, }, }, @@ -1675,18 +1674,18 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: true, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { Targets: &[]loadbalancer.Target{ { - DisplayName: utils.Ptr("node-a"), - Ip: utils.Ptr("10.0.0.1"), + DisplayName: new("node-a"), + Ip: new("10.0.0.1"), }, { - DisplayName: utils.Ptr("node-b"), - Ip: utils.Ptr("10.0.0.2"), + DisplayName: new("node-b"), + Ip: new("10.0.0.2"), }, }, }, @@ -1694,18 +1693,18 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { Targets: &[]loadbalancer.Target{ { - DisplayName: utils.Ptr("node-b"), - Ip: utils.Ptr("10.0.0.2"), + DisplayName: new("node-b"), + Ip: new("10.0.0.2"), }, { - DisplayName: utils.Ptr("node-a"), - Ip: utils.Ptr("10.0.0.1"), + DisplayName: new("node-a"), + Ip: new("10.0.0.1"), }, }, }, @@ -1716,14 +1715,14 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { Targets: &[]loadbalancer.Target{ { - DisplayName: utils.Ptr("node-a"), - Ip: utils.Ptr("10.0.0.1"), + DisplayName: new("node-a"), + Ip: new("10.0.0.1"), }, }, }, @@ -1731,18 +1730,18 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { Targets: &[]loadbalancer.Target{ { - DisplayName: utils.Ptr("node-b"), - Ip: utils.Ptr("10.0.0.2"), + DisplayName: new("node-b"), + Ip: new("10.0.0.2"), }, { - DisplayName: utils.Ptr("node-a"), - Ip: utils.Ptr("10.0.0.1"), + DisplayName: new("node-a"), + Ip: new("10.0.0.1"), }, }, }, @@ -1753,14 +1752,14 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { Targets: &[]loadbalancer.Target{ { - DisplayName: utils.Ptr("node-a"), - Ip: utils.Ptr("10.0.0.1"), + DisplayName: new("node-a"), + Ip: new("10.0.0.1"), }, }, }, @@ -1768,14 +1767,14 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { Targets: &[]loadbalancer.Target{ { - DisplayName: utils.Ptr("node-a"), - Ip: utils.Ptr("10.0.0.2"), + DisplayName: new("node-a"), + Ip: new("10.0.0.2"), }, }, }, @@ -1786,7 +1785,7 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: true, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { @@ -1796,7 +1795,7 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { @@ -1809,24 +1808,24 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { ActiveHealthCheck: &loadbalancer.ActiveHealthCheck{ - Interval: utils.Ptr("2"), + Interval: new("2"), }, }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { ActiveHealthCheck: &loadbalancer.ActiveHealthCheck{ - Interval: utils.Ptr("3"), + Interval: new("3"), }, }, }, @@ -1836,7 +1835,7 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { @@ -1848,12 +1847,12 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{ { ActiveHealthCheck: &loadbalancer.ActiveHealthCheck{ - UnhealthyThreshold: utils.Ptr[int64](3), + UnhealthyThreshold: new(int64(3)), }, }, }, @@ -1866,21 +1865,21 @@ var _ = DescribeTable("compareLBwithSpec", }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, }, }), Entry("When private IP is reported back from API", &compareLBwithSpecTest{ wantFulfilled: true, lb: &loadbalancer.LoadBalancer{ - PrivateAddress: utils.Ptr("10.1.1.3"), + PrivateAddress: new("10.1.1.3"), Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, }, }), @@ -1888,15 +1887,15 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), AccessControl: &loadbalancer.LoadbalancerOptionAccessControl{ - AllowedSourceRanges: utils.Ptr([]string{"10.0.0.0/24"}), + AllowedSourceRanges: new([]string{"10.0.0.0/24"}), }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, }, }), @@ -1904,17 +1903,17 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), AccessControl: &loadbalancer.LoadbalancerOptionAccessControl{ - AllowedSourceRanges: utils.Ptr([]string{"10.5.0.0/24"}), + AllowedSourceRanges: new([]string{"10.5.0.0/24"}), }, }, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), AccessControl: &loadbalancer.LoadbalancerOptionAccessControl{ - AllowedSourceRanges: utils.Ptr([]string{"10.0.0.0/24"}), + AllowedSourceRanges: new([]string{"10.0.0.0/24"}), }, }, }, @@ -1923,21 +1922,21 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: true, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{{ SessionPersistence: &loadbalancer.SessionPersistence{ - UseSourceIpAddress: utils.Ptr(true), + UseSourceIpAddress: new(true), }, }}, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{{ SessionPersistence: &loadbalancer.SessionPersistence{ - UseSourceIpAddress: utils.Ptr(true), + UseSourceIpAddress: new(true), }, }}, }, @@ -1946,21 +1945,21 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: true, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{{ SessionPersistence: &loadbalancer.SessionPersistence{ - UseSourceIpAddress: utils.Ptr(false), + UseSourceIpAddress: new(false), }, }}, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{{ SessionPersistence: &loadbalancer.SessionPersistence{ - UseSourceIpAddress: utils.Ptr(false), + UseSourceIpAddress: new(false), }, }}, }, @@ -1969,21 +1968,21 @@ var _ = DescribeTable("compareLBwithSpec", wantFulfilled: false, lb: &loadbalancer.LoadBalancer{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{{ SessionPersistence: &loadbalancer.SessionPersistence{ - UseSourceIpAddress: utils.Ptr(false), + UseSourceIpAddress: new(false), }, }}, }, spec: &loadbalancer.CreateLoadBalancerPayload{ Options: &loadbalancer.LoadBalancerOptions{ - PrivateNetworkOnly: utils.Ptr(true), + PrivateNetworkOnly: new(true), }, TargetPools: &[]loadbalancer.TargetPool{{ SessionPersistence: &loadbalancer.SessionPersistence{ - UseSourceIpAddress: utils.Ptr(true), + UseSourceIpAddress: new(true), }, }}, }, diff --git a/pkg/ccm/loadbalancer_test.go b/pkg/ccm/loadbalancer_test.go index a273d049..95c028eb 100644 --- a/pkg/ccm/loadbalancer_test.go +++ b/pkg/ccm/loadbalancer_test.go @@ -7,13 +7,11 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/cloud-provider/api" - "k8s.io/utils/ptr" "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit" ) @@ -117,9 +115,9 @@ var _ = Describe("LoadBalancer", func() { Name: spec.Name, Networks: spec.Networks, Options: spec.Options, - Status: ptr.To(loadbalancer.LOADBALANCERSTATUS_READY), + Status: new(loadbalancer.LOADBALANCERSTATUS_READY), TargetPools: spec.TargetPools, - Version: ptr.To("current-version"), + Version: new("current-version"), } } @@ -168,7 +166,7 @@ var _ = Describe("LoadBalancer", func() { myLb := convertToLB(spec) Expect(myLb.ExternalAddress).To(BeNil()) if hasPrivateAddress { - myLb.PrivateAddress = ptr.To("10.20.30.40") + myLb.PrivateAddress = new("10.20.30.40") } mockClient.EXPECT().GetLoadBalancer(gomock.Any(), projectID, gomock.Any()).Return(myLb, nil) @@ -208,9 +206,9 @@ var _ = Describe("LoadBalancer", func() { DoAndReturn(func(_ context.Context, _ string, payload loadbalancer.CreateCredentialsPayload) (*loadbalancer.CreateCredentialsResponse, error) { return &loadbalancer.CreateCredentialsResponse{ Credential: &loadbalancer.CredentialsResponse{ - CredentialsRef: utils.Ptr("my-credential-ref"), - DisplayName: utils.Ptr(*payload.DisplayName), - Username: utils.Ptr(*payload.Username), + CredentialsRef: new("my-credential-ref"), + DisplayName: new(*payload.DisplayName), + Username: new(*payload.Username), }, }, nil }) @@ -226,7 +224,7 @@ var _ = Describe("LoadBalancer", func() { svc := minimalLoadBalancerService() spec, _, err := lbSpecFromService(svc, []*corev1.Node{}, lbOpts, &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: utils.Ptr(sampleCredentialsRef), + CredentialsRef: new(sampleCredentialsRef), PushUrl: &lbInModeIgnoreAndObs.metricsRemoteWrite.endpoint, }, }) @@ -239,10 +237,10 @@ var _ = Describe("LoadBalancer", func() { Networks: spec.Networks, Options: spec.Options, PrivateAddress: spec.PrivateAddress, - Status: ptr.To(loadbalancer.LOADBALANCERSTATUS_READY), + Status: new(loadbalancer.LOADBALANCERSTATUS_READY), TargetPools: spec.TargetPools, - Version: ptr.To("current-version"), - PlanId: ptr.To("p10"), + Version: new("current-version"), + PlanId: new("p10"), } mockClient.EXPECT().GetLoadBalancer(gomock.Any(), projectID, gomock.Any()).Return(myLb, nil) @@ -265,9 +263,9 @@ var _ = Describe("LoadBalancer", func() { Networks: spec.Networks, Options: spec.Options, PrivateAddress: spec.PrivateAddress, - Status: ptr.To(loadbalancer.LOADBALANCERSTATUS_READY), + Status: new(loadbalancer.LOADBALANCERSTATUS_READY), TargetPools: spec.TargetPools, - Version: ptr.To("current-version"), + Version: new("current-version"), } mockClient.EXPECT().GetLoadBalancer(gomock.Any(), projectID, gomock.Any()).Return(myLb, nil) @@ -323,9 +321,9 @@ var _ = Describe("LoadBalancer", func() { Networks: spec.Networks, Options: spec.Options, PrivateAddress: spec.PrivateAddress, - Status: ptr.To(loadbalancer.LOADBALANCERSTATUS_READY), + Status: new(loadbalancer.LOADBALANCERSTATUS_READY), TargetPools: spec.TargetPools, - Version: ptr.To("current-version"), + Version: new("current-version"), } mockClient.EXPECT().GetLoadBalancer(gomock.Any(), projectID, gomock.Any()).Return(myLb, nil) @@ -346,8 +344,8 @@ var _ = Describe("LoadBalancer", func() { svc := minimalLoadBalancerService() spec, _, err := lbSpecFromService(svc, []*corev1.Node{}, lbOpts, &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), - PushUrl: ptr.To("test-endpoint"), + CredentialsRef: new(sampleCredentialsRef), + PushUrl: new("test-endpoint"), }, }) Expect(err).NotTo(HaveOccurred()) @@ -359,9 +357,9 @@ var _ = Describe("LoadBalancer", func() { Networks: spec.Networks, Options: spec.Options, PrivateAddress: spec.PrivateAddress, - Status: ptr.To(loadbalancer.LOADBALANCERSTATUS_READY), + Status: new(loadbalancer.LOADBALANCERSTATUS_READY), TargetPools: spec.TargetPools, - Version: ptr.To("current-version"), + Version: new("current-version"), } mockClient.EXPECT().GetLoadBalancer(gomock.Any(), projectID, gomock.Any()).Return(myLb, nil) @@ -411,7 +409,7 @@ var _ = Describe("LoadBalancer", func() { It("should finalize deletion if load balancer is state terminating", func() { mockClient.EXPECT().GetLoadBalancer(gomock.Any(), projectID, gomock.Any()).Return(&loadbalancer.LoadBalancer{ - Status: utils.Ptr(loadbalancer.LOADBALANCERSTATUS_TERMINATING), + Status: new(loadbalancer.LOADBALANCERSTATUS_TERMINATING), }, nil) err := loadBalancer.EnsureLoadBalancerDeleted(context.Background(), clusterName, minimalLoadBalancerService()) @@ -450,13 +448,13 @@ var _ = Describe("LoadBalancer", func() { Options: &loadbalancer.LoadBalancerOptions{ Observability: &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), - PushUrl: ptr.To("http://localhost"), + CredentialsRef: new(sampleCredentialsRef), + PushUrl: new("http://localhost"), }, }, - EphemeralAddress: ptr.To(false), + EphemeralAddress: new(false), }, - ExternalAddress: ptr.To("8.8.4.4"), + ExternalAddress: new("8.8.4.4"), Listeners: &[]loadbalancer.Listener{}, }, nil) gomock.InOrder( @@ -484,13 +482,13 @@ var _ = Describe("LoadBalancer", func() { Options: &loadbalancer.LoadBalancerOptions{ Observability: &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), - PushUrl: ptr.To("http://localhost"), + CredentialsRef: new(sampleCredentialsRef), + PushUrl: new("http://localhost"), }, }, - EphemeralAddress: ptr.To(true), + EphemeralAddress: new(true), }, - ExternalAddress: ptr.To("0.0.0.0 (ephemeral)"), + ExternalAddress: new("0.0.0.0 (ephemeral)"), Listeners: &[]loadbalancer.Listener{}, }, nil) gomock.InOrder( @@ -548,11 +546,11 @@ var _ = Describe("LoadBalancer", func() { pushURL := "test-endpoint" mockClient.EXPECT().UpdateCredentials(gomock.Any(), projectID, sampleCredentialsRef, gomock.Any()).MinTimes(1).Return(nil) credentialRef, err := lbInModeIgnoreAndObs.reconcileObservabilityCredentials(context.Background(), &loadbalancer.LoadBalancer{ - Name: ptr.To(sampleLBName), + Name: new(sampleLBName), Options: &loadbalancer.LoadBalancerOptions{ Observability: &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), + CredentialsRef: new(sampleCredentialsRef), }, }, }, @@ -560,7 +558,7 @@ var _ = Describe("LoadBalancer", func() { Expect(err).NotTo(HaveOccurred()) Expect(*credentialRef).To(Equal(loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), + CredentialsRef: new(sampleCredentialsRef), PushUrl: &pushURL, }, })) @@ -570,11 +568,11 @@ var _ = Describe("LoadBalancer", func() { errTest := errors.New("update credentials test error") mockClient.EXPECT().UpdateCredentials(gomock.Any(), projectID, sampleCredentialsRef, gomock.Any()).MinTimes(1).Return(errTest) credentialRef, err := lbInModeIgnoreAndObs.reconcileObservabilityCredentials(context.Background(), &loadbalancer.LoadBalancer{ - Name: ptr.To(sampleLBName), + Name: new(sampleLBName), Options: &loadbalancer.LoadBalancerOptions{ Observability: &loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), + CredentialsRef: new(sampleCredentialsRef), }, }, }, @@ -589,19 +587,19 @@ var _ = Describe("LoadBalancer", func() { }, nil) mockClient.EXPECT().CreateCredentials(gomock.Any(), projectID, gomock.Any()).MinTimes(1).Return(&loadbalancer.CreateCredentialsResponse{ Credential: &loadbalancer.CredentialsResponse{ - CredentialsRef: ptr.To(sampleCredentialsRef), - DisplayName: ptr.To(sampleLBName), - Username: ptr.To("test-username"), + CredentialsRef: new(sampleCredentialsRef), + DisplayName: new(sampleLBName), + Username: new("test-username"), }, }, nil) credentialRef, err := lbInModeIgnoreAndObs.reconcileObservabilityCredentials(context.Background(), &loadbalancer.LoadBalancer{ - Name: ptr.To(sampleLBName), + Name: new(sampleLBName), }, sampleLBName) Expect(err).NotTo(HaveOccurred()) Expect(*credentialRef).To(Equal(loadbalancer.LoadbalancerOptionObservability{ Metrics: &loadbalancer.LoadbalancerOptionMetrics{ - CredentialsRef: ptr.To(sampleCredentialsRef), - PushUrl: ptr.To("test-endpoint"), + CredentialsRef: new(sampleCredentialsRef), + PushUrl: new("test-endpoint"), }, })) }) @@ -613,7 +611,7 @@ var _ = Describe("LoadBalancer", func() { errTest := errors.New("delete credentials test error") mockClient.EXPECT().CreateCredentials(gomock.Any(), projectID, gomock.Any()).MinTimes(1).Return(nil, errTest) credentialRef, err := lbInModeIgnoreAndObs.reconcileObservabilityCredentials(context.Background(), &loadbalancer.LoadBalancer{ - Name: ptr.To(sampleLBName), + Name: new(sampleLBName), }, sampleLBName) Expect(err).To(MatchError(errTest)) Expect(credentialRef).To(BeNil()) @@ -626,24 +624,24 @@ var _ = Describe("LoadBalancer", func() { mockClient.EXPECT().ListCredentials(gomock.Any(), projectID).Return(&loadbalancer.ListCredentialsResponse{ Credentials: &[]loadbalancer.CredentialsResponse{ { - CredentialsRef: ptr.To("matching-1"), - DisplayName: ptr.To("my-loadbalancer"), - Username: ptr.To("luke"), + CredentialsRef: new("matching-1"), + DisplayName: new("my-loadbalancer"), + Username: new("luke"), }, { - CredentialsRef: ptr.To("display-name-not-match"), - DisplayName: ptr.To("other-loadbalancer"), - Username: ptr.To("leia"), + CredentialsRef: new("display-name-not-match"), + DisplayName: new("other-loadbalancer"), + Username: new("leia"), }, { - CredentialsRef: ptr.To("matching-2"), - DisplayName: ptr.To("my-loadbalancer"), - Username: ptr.To("chewie"), + CredentialsRef: new("matching-2"), + DisplayName: new("my-loadbalancer"), + Username: new("chewie"), }, { - CredentialsRef: ptr.To("no-display-name"), + CredentialsRef: new("no-display-name"), DisplayName: nil, - Username: ptr.To("han"), + Username: new("han"), }, }, }, nil).MinTimes(1), @@ -661,13 +659,13 @@ var _ = DescribeTable("loadBalancerStatus", }, Entry("empty address", &loadbalancer.LoadBalancer{}, &corev1.Service{}, &corev1.LoadBalancerStatus{}), Entry("address present", - &loadbalancer.LoadBalancer{ExternalAddress: ptr.To("1.2.3.4")}, &corev1.Service{}, + &loadbalancer.LoadBalancer{ExternalAddress: new("1.2.3.4")}, &corev1.Service{}, &corev1.LoadBalancerStatus{Ingress: []corev1.LoadBalancerIngress{{IP: "1.2.3.4"}}}, ), Entry("IP mode proxy", - &loadbalancer.LoadBalancer{ExternalAddress: ptr.To("1.2.3.4")}, + &loadbalancer.LoadBalancer{ExternalAddress: new("1.2.3.4")}, &corev1.Service{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{ipModeProxyAnnotation: "true"}}}, - &corev1.LoadBalancerStatus{Ingress: []corev1.LoadBalancerIngress{{IP: "1.2.3.4", IPMode: ptr.To(corev1.LoadBalancerIPModeProxy)}}}, + &corev1.LoadBalancerStatus{Ingress: []corev1.LoadBalancerIngress{{IP: "1.2.3.4", IPMode: new(corev1.LoadBalancerIPModeProxy)}}}, ), ) diff --git a/pkg/cmp/cmp_test.go b/pkg/cmp/cmp_test.go index a0f744ff..dc93a035 100644 --- a/pkg/cmp/cmp_test.go +++ b/pkg/cmp/cmp_test.go @@ -3,8 +3,6 @@ package cmp import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "github.com/stackitcloud/stackit-sdk-go/core/utils" ) type sliceEqualUnorderedTest struct { @@ -120,17 +118,17 @@ var _ = DescribeTable("PtrValEqual", Entry("nil vs value", &ptrValEqualTest{ want: false, a: nil, - b: utils.Ptr(""), + b: new(""), }), Entry("equal values", &ptrValEqualTest{ want: true, - a: utils.Ptr("c"), - b: utils.Ptr("c"), + a: new("c"), + b: new("c"), }), Entry("unequal values", &ptrValEqualTest{ want: false, - a: utils.Ptr("c"), - b: utils.Ptr("d"), + a: new("c"), + b: new("d"), }), ) @@ -153,17 +151,17 @@ var _ = DescribeTable("PtrValEqualFn", Entry("nil vs value", &ptrValEqualFnTest{ want: false, a: nil, - b: utils.Ptr(""), + b: new(""), }), Entry("equal values", &ptrValEqualFnTest{ want: true, - a: utils.Ptr("c"), - b: utils.Ptr("c"), + a: new("c"), + b: new("c"), }), Entry("unequal values", &ptrValEqualFnTest{ want: false, - a: utils.Ptr("c"), - b: utils.Ptr("d"), + a: new("c"), + b: new("d"), }), ) @@ -182,15 +180,15 @@ var _ = DescribeTable("LenSlicePtr", }), Entry("nil slice", &lenSlicePtrTest{ want: 0, - in: utils.Ptr[[]any](nil), + in: new([]any(nil)), }), Entry("empty slice", &lenSlicePtrTest{ want: 0, - in: utils.Ptr[[]any]([]any{}), + in: new([]any{}), }), Entry("length 1 slice", &lenSlicePtrTest{ want: 1, - in: utils.Ptr[[]any]([]any{nil}), + in: new([]any{nil}), }), ) @@ -205,6 +203,6 @@ var _ = Describe("UnpackPtr", func() { }) It("should", func() { - Expect(UnpackPtr(utils.Ptr("hello"))).To(Equal("hello")) + Expect(UnpackPtr(new("hello"))).To(Equal("hello")) }) }) diff --git a/pkg/csi/blockstorage/controllerserver.go b/pkg/csi/blockstorage/controllerserver.go index 4455017d..f7f57ccd 100644 --- a/pkg/csi/blockstorage/controllerserver.go +++ b/pkg/csi/blockstorage/controllerserver.go @@ -215,12 +215,12 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } opts := &iaas.CreateVolumePayload{ - Name: ptr.To(volName), + Name: new(volName), PerformanceClass: volParams.PerformanceClass, - Size: ptr.To(volSizeGB), - AvailabilityZone: ptr.To(volAvailability), + Size: new(volSizeGB), + AvailabilityZone: new(volAvailability), //TODO: IaaS API does not allow dots or slashes. Additionally we would like to actually use metadata/annotations - //Labels: ptr.To(util.ConvertMapStringToInterface(properties)), + //Labels: new(util.ConvertMapStringToInterface(properties)), } // Only set CreateVolumePayload.Source when actually creating volume from source/snapshot/backup @@ -233,8 +233,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol volumeSourceID := determineSourceIDForSourceType(volumeSourceType, sourceSnapshotID, sourceVolID) klog.V(4).Infof("Creating volume from %s source", volumeSourceType) opts.Source = &iaas.VolumeSource{ - Id: ptr.To(volumeSourceID), - Type: ptr.To(string(volumeSourceType)), + Id: new(volumeSourceID), + Type: new(string(volumeSourceType)), } } @@ -290,7 +290,7 @@ func setVolumeEncryptionParameters(opts *iaas.CreateVolumePayload, volParams *st encryptionConfig := &iaas.VolumeEncryptionParameter{ KekKeyId: volParams.KMSKeyID, - KekKeyVersion: ptr.To(int64(kmsKeyVersionInt)), + KekKeyVersion: new(int64(kmsKeyVersionInt)), KekKeyringId: volParams.KMSKeyringID, ServiceAccount: volParams.KMSServiceAccount, } diff --git a/pkg/csi/blockstorage/controllerserver_test.go b/pkg/csi/blockstorage/controllerserver_test.go index 6fcad907..1c4ff5e4 100644 --- a/pkg/csi/blockstorage/controllerserver_test.go +++ b/pkg/csi/blockstorage/controllerserver_test.go @@ -17,7 +17,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/timestamppb" - "k8s.io/utils/ptr" "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit" ) @@ -68,10 +67,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "new volume").Return([]iaas.Volume{}, nil) iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(&iaas.Volume{ - Id: ptr.To("volume-id"), - Name: ptr.To("new volume"), - AvailabilityZone: ptr.To("eu01"), - Size: ptr.To(int64(20)), + Id: new("volume-id"), + Name: new("new volume"), + AvailabilityZone: new("eu01"), + Size: new(int64(20)), }, nil) iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil) @@ -123,10 +122,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "volume name").Return([]iaas.Volume{}, nil) iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(&iaas.Volume{ - Id: ptr.To("volume-id"), - Name: ptr.To("volume name"), - AvailabilityZone: ptr.To("zone-from-parameters"), - Size: ptr.To(int64(20)), + Id: new("volume-id"), + Name: new("volume name"), + AvailabilityZone: new("zone-from-parameters"), + Size: new(int64(20)), }, nil) iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil) @@ -151,10 +150,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "volume name").Return([]iaas.Volume{}, nil) iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(&iaas.Volume{ - Id: ptr.To("volume-id"), - Name: ptr.To("volume name"), - AvailabilityZone: ptr.To("zone-from-accessibility-reqs"), - Size: ptr.To(int64(20)), + Id: new("volume-id"), + Name: new("volume name"), + AvailabilityZone: new("zone-from-accessibility-reqs"), + Size: new(int64(20)), }, nil) iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil) @@ -186,11 +185,11 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "new volume").Return([]iaas.Volume{ { - Id: ptr.To("existing-available-volume-id"), - Name: ptr.To("new volume"), - Size: ptr.To(int64(20)), - Status: ptr.To(stackit.VolumeAvailableStatus), - AvailabilityZone: ptr.To("eu01"), + Id: new("existing-available-volume-id"), + Name: new("new volume"), + Size: new(int64(20)), + Status: new(stackit.VolumeAvailableStatus), + AvailabilityZone: new("eu01"), }, }, nil) @@ -210,11 +209,11 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "new volume").Return([]iaas.Volume{ { - Id: ptr.To("existing-available-volume-id"), - Name: ptr.To("new volume"), - Size: ptr.To(int64(30)), - Status: ptr.To(stackit.VolumeAvailableStatus), - AvailabilityZone: ptr.To("eu01"), + Id: new("existing-available-volume-id"), + Name: new("new volume"), + Size: new(int64(30)), + Status: new(stackit.VolumeAvailableStatus), + AvailabilityZone: new("eu01"), }, }, nil) @@ -232,11 +231,11 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "new volume").Return([]iaas.Volume{ { - Id: ptr.To("existing-available-volume-id"), - Name: ptr.To("new volume"), - Size: ptr.To(int64(20)), - Status: ptr.To(stackit.VolumeAttachedStatus), - AvailabilityZone: ptr.To("eu01"), + Id: new("existing-available-volume-id"), + Name: new("new volume"), + Size: new(int64(20)), + Status: new(stackit.VolumeAttachedStatus), + AvailabilityZone: new("eu01"), }, }, nil) @@ -255,10 +254,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "new volume").Return([]iaas.Volume{ { - Id: ptr.To("volume-0"), + Id: new("volume-0"), }, { - Id: ptr.To("volume-1"), + Id: new("volume-1"), }, }, nil) @@ -298,13 +297,13 @@ var _ = Describe("ControllerServer test", Ordered, func() { } iaasClient.EXPECT().GetSnapshotByID(gomock.Any(), "snapshot-id").Return(&iaas.Snapshot{ - Id: ptr.To("snapshot-id"), - Status: ptr.To("AVAILABLE"), - VolumeId: ptr.To("snapshot-volume-id"), + Id: new("snapshot-id"), + Status: new("AVAILABLE"), + VolumeId: new("snapshot-volume-id"), }, nil) iaasClient.EXPECT().GetVolume(gomock.Any(), "snapshot-volume-id").Return(&iaas.Volume{ - Id: ptr.To("snapshot-volume-id"), - AvailabilityZone: ptr.To("eu01"), + Id: new("snapshot-volume-id"), + AvailabilityZone: new("eu01"), }, nil) iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()). Do(func(_ context.Context, opts *iaas.CreateVolumePayload) { @@ -312,10 +311,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { Expect(*opts.Source.Type).To(Equal("snapshot")) }). Return(&iaas.Volume{ - Id: ptr.To("volume-id"), - Name: ptr.To("new volume"), - AvailabilityZone: ptr.To("eu01"), - Size: ptr.To(int64(20)), + Id: new("volume-id"), + Name: new("new volume"), + AvailabilityZone: new("eu01"), + Size: new(int64(20)), }, nil) iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil) @@ -349,8 +348,8 @@ var _ = Describe("ControllerServer test", Ordered, func() { } iaasClient.EXPECT().GetSnapshotByID(gomock.Any(), "snapshot-id").Return(&iaas.Snapshot{ - Id: ptr.To("snapshot-id"), - Status: ptr.To("creating"), + Id: new("snapshot-id"), + Status: new("creating"), }, nil) _, err := fakeCs.CreateVolume(context.Background(), req) @@ -373,8 +372,8 @@ var _ = Describe("ControllerServer test", Ordered, func() { StatusCode: http.StatusNotFound, }) iaasClient.EXPECT().GetBackupByID(gomock.Any(), "snapshot-id").Return(&iaas.Backup{ - Status: ptr.To("AVAILABLE"), - AvailabilityZone: ptr.To("eu01"), + Status: new("AVAILABLE"), + AvailabilityZone: new("eu01"), }, nil) iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()). Do(func(_ context.Context, opts *iaas.CreateVolumePayload) { @@ -382,10 +381,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { Expect(*opts.Source.Type).To(Equal("backup")) }). Return(&iaas.Volume{ - Id: ptr.To("volume-id"), - Name: ptr.To("new volume"), - AvailabilityZone: ptr.To("eu01"), - Size: ptr.To(int64(20)), + Id: new("volume-id"), + Name: new("new volume"), + AvailabilityZone: new("eu01"), + Size: new(int64(20)), }, nil) iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil) @@ -408,14 +407,14 @@ var _ = Describe("ControllerServer test", Ordered, func() { } iaasClient.EXPECT().GetSnapshotByID(gomock.Any(), "snapshot-id").Return(&iaas.Snapshot{ - Id: ptr.To("snapshot-id"), - VolumeId: ptr.To("volume-id"), - Status: ptr.To("AVAILABLE"), + Id: new("snapshot-id"), + VolumeId: new("volume-id"), + Status: new("AVAILABLE"), }, nil) iaasClient.EXPECT().GetVolume(gomock.Any(), "volume-id").Return(&iaas.Volume{ - Status: ptr.To("AVAILABLE"), - AvailabilityZone: ptr.To("eu01"), - Id: ptr.To("volume-id"), + Status: new("AVAILABLE"), + AvailabilityZone: new("eu01"), + Id: new("volume-id"), }, nil) _, err := fakeCs.CreateVolume(context.Background(), req) @@ -462,7 +461,7 @@ var _ = Describe("ControllerServer test", Ordered, func() { StatusCode: http.StatusNotFound, }) iaasClient.EXPECT().GetBackupByID(gomock.Any(), "snapshot-id").Return(&iaas.Backup{ - Status: ptr.To("creating"), + Status: new("creating"), }, nil) _, err := fakeCs.CreateVolume(context.Background(), req) @@ -481,9 +480,9 @@ var _ = Describe("ControllerServer test", Ordered, func() { } iaasClient.EXPECT().GetVolume(gomock.Any(), "volume-source-id").Return(&iaas.Volume{ - Id: ptr.To("volume-source-id"), - Status: ptr.To("AVAILABLE"), - AvailabilityZone: ptr.To("eu01"), + Id: new("volume-source-id"), + Status: new("AVAILABLE"), + AvailabilityZone: new("eu01"), }, nil) iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()). Do(func(_ context.Context, opts *iaas.CreateVolumePayload) { @@ -491,10 +490,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { Expect(*opts.Source.Type).To(Equal("volume")) }). Return(&iaas.Volume{ - Id: ptr.To("volume-id"), - Name: ptr.To("new volume"), - AvailabilityZone: ptr.To("eu01"), - Size: ptr.To(int64(20)), + Id: new("volume-id"), + Name: new("new volume"), + AvailabilityZone: new("eu01"), + Size: new(int64(20)), }, nil) iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil) @@ -568,10 +567,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { iaasClient.EXPECT().GetVolumesByName(gomock.Any(), "new volume").Return([]iaas.Volume{}, nil) iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(&iaas.Volume{ - Id: ptr.To("volume-id"), - Name: ptr.To("new volume"), - AvailabilityZone: ptr.To("eu01"), - Size: ptr.To(int64(20)), + Id: new("volume-id"), + Name: new("new volume"), + AvailabilityZone: new("eu01"), + Size: new(int64(20)), }, nil) iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()). Return(fmt.Errorf("injected error")) @@ -624,17 +623,17 @@ var _ = Describe("ControllerServer test", Ordered, func() { // Pagination is not supported by the API yet, so the arguments are ignored iaasClient.EXPECT().ListVolumes(gomock.Any(), gomock.Any(), gomock.Any()).Return([]iaas.Volume{ { - Id: ptr.To("fake"), - Status: ptr.To("AVAILABLE"), - Name: ptr.To("fake"), - Size: ptr.To(int64(10)), + Id: new("fake"), + Status: new("AVAILABLE"), + Name: new("fake"), + Size: new(int64(10)), }, { - Id: ptr.To("fake1"), - Status: ptr.To("AVAILABLE"), - Name: ptr.To("fake1"), - Size: ptr.To(int64(10)), - ServerId: ptr.To("serverID"), + Id: new("fake1"), + Status: new("AVAILABLE"), + Name: new("fake1"), + Size: new(int64(10)), + ServerId: new("serverID"), }, }, "", nil) resp, err := fakeCs.ListVolumes(context.Background(), req) @@ -676,8 +675,8 @@ var _ = Describe("ControllerServer test", Ordered, func() { VolumeId: "fake", } expectedVol := &iaas.Volume{ - ServerId: ptr.To("fake"), - Size: ptr.To(100 * util.GIBIBYTE), + ServerId: new("fake"), + Size: new(100 * util.GIBIBYTE), } iaasClient.EXPECT().GetVolume(gomock.Any(), req.VolumeId).Return(expectedVol, nil) resp, err := fakeCs.ControllerGetVolume(context.Background(), req) @@ -694,8 +693,8 @@ var _ = Describe("ControllerServer test", Ordered, func() { } volSizeGB := util.RoundUpSize(req.GetCapacityRange().GetRequiredBytes(), util.GIBIBYTE) iaasClient.EXPECT().GetVolume(gomock.Any(), req.VolumeId).Return(&iaas.Volume{ - Size: ptr.To(int64(10)), - Status: ptr.To(stackit.VolumeAvailableStatus), + Size: new(int64(10)), + Status: new(stackit.VolumeAvailableStatus), }, nil) iaasClient.EXPECT().ExpandVolume(gomock.Any(), req.VolumeId, stackit.VolumeAvailableStatus, volSizeGB).Return(nil) iaasClient.EXPECT().WaitVolumeTargetStatus(gomock.Any(), req.VolumeId, expandTargetStatus).Return(nil) @@ -709,8 +708,8 @@ var _ = Describe("ControllerServer test", Ordered, func() { } volSizeGB := util.RoundUpSize(req.GetCapacityRange().GetRequiredBytes(), util.GIBIBYTE) iaasClient.EXPECT().GetVolume(gomock.Any(), req.VolumeId).Return(&iaas.Volume{ - Size: ptr.To(int64(10)), - Status: ptr.To("ERROR"), + Size: new(int64(10)), + Status: new("ERROR"), }, nil) iaasClient.EXPECT().ExpandVolume(gomock.Any(), req.VolumeId, "ERROR", volSizeGB).Return(fmt.Errorf("volume cannot be resized, when status is ERROR")) _, err := fakeCs.ControllerExpandVolume(context.Background(), req) @@ -734,20 +733,20 @@ var _ = Describe("ControllerServer test", Ordered, func() { // properties := map[string]string{blockStorageCSIClusterIDKey: "cluster"} properties := map[string]string{} expectedSnap := &iaas.Snapshot{ - Id: ptr.To("fake-snapshot"), - Name: ptr.To("fake-snapshot"), - Status: ptr.To("AVAILABLE"), - Size: ptr.To(int64(10)), - CreatedAt: ptr.To(time.Now()), + Id: new("fake-snapshot"), + Name: new("fake-snapshot"), + Status: new("AVAILABLE"), + Size: new(int64(10)), + CreatedAt: new(time.Now()), } expectedBackup := &iaas.Backup{ - Id: ptr.To("fake-backup"), - Name: ptr.To("fake-backup"), - Status: ptr.To("AVAILABLE"), - SnapshotId: ptr.To("fake-snapshot"), - Size: ptr.To(int64(10)), - VolumeId: ptr.To(req.GetSourceVolumeId()), - CreatedAt: ptr.To(time.Now()), + Id: new("fake-backup"), + Name: new("fake-backup"), + Status: new("AVAILABLE"), + SnapshotId: new("fake-snapshot"), + Size: new(int64(10)), + VolumeId: new(req.GetSourceVolumeId()), + CreatedAt: new(time.Now()), } iaasClient.EXPECT().ListBackups(gomock.Any(), gomock.Any()).Return([]iaas.Backup{}, nil) @@ -760,7 +759,7 @@ var _ = Describe("ControllerServer test", Ordered, func() { // Actually create the backup from the snapshot iaasClient.EXPECT().CreateBackup(gomock.Any(), "fake-snapshot", req.GetSourceVolumeId(), "fake-snapshot", gomock.Any()).Return(expectedBackup, nil) iaasClient.EXPECT().WaitBackupReady(gomock.Any(), "fake-backup", *expectedSnap.Size, stackit.BackupMaxDurationSecondsPerGBDefault). - Return(ptr.To("AVAILABLE"), nil) + Return(new("AVAILABLE"), nil) iaasClient.EXPECT().GetBackupByID(gomock.Any(), "fake-backup").Return(expectedBackup, nil) // Remove the snapshot after the backup is created @@ -771,17 +770,17 @@ var _ = Describe("ControllerServer test", Ordered, func() { }) It("should skip snapshot creation when backup already exists", func() { expectedBackup := &iaas.Backup{ - Id: ptr.To("fake-backup"), - Name: ptr.To("fake-backup"), - Status: ptr.To("AVAILABLE"), - SnapshotId: ptr.To("fake-snapshot"), - Size: ptr.To(int64(10)), - VolumeId: ptr.To(req.GetSourceVolumeId()), - CreatedAt: ptr.To(time.Now()), + Id: new("fake-backup"), + Name: new("fake-backup"), + Status: new("AVAILABLE"), + SnapshotId: new("fake-snapshot"), + Size: new(int64(10)), + VolumeId: new(req.GetSourceVolumeId()), + CreatedAt: new(time.Now()), } iaasClient.EXPECT().ListBackups(gomock.Any(), gomock.Any()).Return([]iaas.Backup{*expectedBackup}, nil) - iaasClient.EXPECT().WaitBackupReady(gomock.Any(), "fake-backup", int64(0), stackit.BackupMaxDurationSecondsPerGBDefault).Return(ptr.To("AVAILABLE"), nil) + iaasClient.EXPECT().WaitBackupReady(gomock.Any(), "fake-backup", int64(0), stackit.BackupMaxDurationSecondsPerGBDefault).Return(new("AVAILABLE"), nil) iaasClient.EXPECT().GetBackupByID(gomock.Any(), "fake-backup").Return(expectedBackup, nil) // Remove the snapshot after the backup is created @@ -793,10 +792,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { It("should find multiple backups and report with error", func() { iaasClient.EXPECT().ListBackups(gomock.Any(), gomock.Any()).Return([]iaas.Backup{ { - Id: ptr.To("fake-snapshot"), + Id: new("fake-snapshot"), }, { - Id: ptr.To("fake-snapshot2"), + Id: new("fake-snapshot2"), }, }, nil) _, err := fakeCs.CreateSnapshot(context.Background(), req) @@ -806,8 +805,8 @@ var _ = Describe("ControllerServer test", Ordered, func() { }) It("should return error when backup is found with same name but different volSourceId", func() { expectedBackup := &iaas.Backup{ - Id: ptr.To("fake-backup"), - VolumeId: ptr.To("another-fake"), + Id: new("fake-backup"), + VolumeId: new("another-fake"), } iaasClient.EXPECT().ListBackups(gomock.Any(), gomock.Any()).Return([]iaas.Backup{*expectedBackup}, nil) @@ -829,20 +828,20 @@ var _ = Describe("ControllerServer test", Ordered, func() { // properties := map[string]string{blockStorageCSIClusterIDKey: "cluster"} properties := map[string]string{} expectedSnap := &iaas.Snapshot{ - Id: ptr.To("fake-snapshot"), - Name: ptr.To("fake-snapshot"), - Status: ptr.To("AVAILABLE"), - Size: ptr.To(int64(10)), - CreatedAt: ptr.To(time.Now()), + Id: new("fake-snapshot"), + Name: new("fake-snapshot"), + Status: new("AVAILABLE"), + Size: new(int64(10)), + CreatedAt: new(time.Now()), } expectedBackup := &iaas.Backup{ - Id: ptr.To("fake-backup"), - Name: ptr.To("fake-backup"), - Status: ptr.To("AVAILABLE"), - SnapshotId: ptr.To("fake-snapshot"), - Size: ptr.To(int64(10)), - VolumeId: ptr.To(req.GetSourceVolumeId()), - CreatedAt: ptr.To(time.Now()), + Id: new("fake-backup"), + Name: new("fake-backup"), + Status: new("AVAILABLE"), + SnapshotId: new("fake-snapshot"), + Size: new(int64(10)), + VolumeId: new(req.GetSourceVolumeId()), + CreatedAt: new(time.Now()), } iaasClient.EXPECT().ListBackups(gomock.Any(), gomock.Any()).Return([]iaas.Backup{}, nil) @@ -854,7 +853,7 @@ var _ = Describe("ControllerServer test", Ordered, func() { // Actually create the backup from the snapshot iaasClient.EXPECT().CreateBackup(gomock.Any(), "fake-snapshot", req.GetSourceVolumeId(), "fake-snapshot", gomock.Any()).Return(expectedBackup, nil) - iaasClient.EXPECT().WaitBackupReady(gomock.Any(), "fake-backup", *expectedSnap.Size, customWaitTime).Return(ptr.To("AVAILABLE"), nil) + iaasClient.EXPECT().WaitBackupReady(gomock.Any(), "fake-backup", *expectedSnap.Size, customWaitTime).Return(new("AVAILABLE"), nil) iaasClient.EXPECT().GetBackupByID(gomock.Any(), "fake-backup").Return(expectedBackup, nil) // Remove the snapshot after the backup is created @@ -875,11 +874,11 @@ var _ = Describe("ControllerServer test", Ordered, func() { }) It("should create snapshot successfully", func() { expectedSnap := &iaas.Snapshot{ - Id: ptr.To("fake-snapshot"), - Name: ptr.To("fake-snapshot45"), - VolumeId: ptr.To("fake"), - Size: ptr.To(int64(10)), - CreatedAt: ptr.To(time.Now()), + Id: new("fake-snapshot"), + Name: new("fake-snapshot45"), + VolumeId: new("fake"), + Size: new(int64(10)), + CreatedAt: new(time.Now()), } // TODO: Use once IaaS has extended the label regex to allow for forward slashes and dots // properties := map[string]string{blockStorageCSIClusterIDKey: "cluster"} @@ -894,17 +893,17 @@ var _ = Describe("ControllerServer test", Ordered, func() { }) It("should return snapshot without creating a new one when already exists", func() { expectedSnap := &iaas.Snapshot{ - Id: ptr.To("fake-snapshot"), - Name: ptr.To("fake-snapshot45"), - VolumeId: ptr.To("fake"), - Status: ptr.To("AVAILABLE"), - Size: ptr.To(int64(10)), - CreatedAt: ptr.To(time.Now()), + Id: new("fake-snapshot"), + Name: new("fake-snapshot45"), + VolumeId: new("fake"), + Status: new("AVAILABLE"), + Size: new(int64(10)), + CreatedAt: new(time.Now()), } // TODO: Again filters are not implemented yet by the API iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{*expectedSnap}, "", nil) - iaasClient.EXPECT().WaitSnapshotReady(gomock.Any(), "fake-snapshot").Return(ptr.To("AVAILABLE"), nil) + iaasClient.EXPECT().WaitSnapshotReady(gomock.Any(), "fake-snapshot").Return(new("AVAILABLE"), nil) _, err := fakeCs.CreateSnapshot(context.Background(), req) Expect(err).ToNot(HaveOccurred()) }) @@ -912,10 +911,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { // TODO: Again filters are not implemented yet by the API iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{ { - Id: ptr.To("fake-snapshot"), + Id: new("fake-snapshot"), }, { - Id: ptr.To("fake-snapshot2"), + Id: new("fake-snapshot2"), }, }, "", nil) _, err := fakeCs.CreateSnapshot(context.Background(), req) @@ -927,8 +926,8 @@ var _ = Describe("ControllerServer test", Ordered, func() { // TODO: Again filters are not implemented yet by the API iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{ { - Id: ptr.To("fake-snapshot"), - VolumeId: ptr.To("something-different"), + Id: new("fake-snapshot"), + VolumeId: new("something-different"), }, }, "", nil) _, err := fakeCs.CreateSnapshot(context.Background(), req) @@ -956,10 +955,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { }, } iaasClient.EXPECT().GetSnapshotByID(gomock.Any(), "special-snapshot").Return(&iaas.Snapshot{ - Id: ptr.To("special-snapshot"), - VolumeId: ptr.To("fake"), - Size: ptr.To(int64(10)), - CreatedAt: ptr.To(snapShotCreationTime), + Id: new("special-snapshot"), + VolumeId: new("fake"), + Size: new(int64(10)), + CreatedAt: new(snapShotCreationTime), }, nil) resp, err := fakeCs.ListSnapshots(context.Background(), req) Expect(err).To(Not(HaveOccurred())) @@ -984,10 +983,10 @@ var _ = Describe("ControllerServer test", Ordered, func() { } iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{{ - Id: ptr.To("fake-snapshot"), - VolumeId: ptr.To("something-different"), - Size: ptr.To(int64(10)), - CreatedAt: ptr.To(snapShotCreationTime), + Id: new("fake-snapshot"), + VolumeId: new("something-different"), + Size: new(int64(10)), + CreatedAt: new(snapShotCreationTime), }}, "", nil) resp, err := fakeCs.ListSnapshots(context.Background(), req) Expect(err).To(Not(HaveOccurred())) diff --git a/pkg/csi/blockstorage/sanity_test.go b/pkg/csi/blockstorage/sanity_test.go index 01b8025f..c31f5d94 100644 --- a/pkg/csi/blockstorage/sanity_test.go +++ b/pkg/csi/blockstorage/sanity_test.go @@ -14,7 +14,6 @@ import ( . "github.com/onsi/ginkgo/v2" mountutils "k8s.io/mount-utils" exec "k8s.io/utils/exec/testing" - "k8s.io/utils/ptr" "github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util/mount" "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit" @@ -84,13 +83,13 @@ var _ = Describe("CSI sanity test", Ordered, func() { ).DoAndReturn(func(_ context.Context, opts *iaas.CreateVolumePayload) (*iaas.Volume, error) { size := opts.Size if size == nil { - size = ptr.To(int64(10)) // Default to 10GiB + size = new(int64(10)) // Default to 10GiB } newVol := &iaas.Volume{ - Id: ptr.To(uuid.New().String()), // Create a random ID + Id: new(uuid.New().String()), // Create a random ID Name: opts.Name, Size: size, - Status: ptr.To(stackit.VolumeAvailableStatus), + Status: new(stackit.VolumeAvailableStatus), AvailabilityZone: opts.AvailabilityZone, Source: opts.Source, } @@ -166,12 +165,12 @@ var _ = Describe("CSI sanity test", Ordered, func() { gomock.Any(), // tags ).DoAndReturn(func(_ context.Context, name string, volID string, _ map[string]string) (*iaas.Snapshot, error) { newSnap := &iaas.Snapshot{ - Id: ptr.To(uuid.New().String()), - Name: ptr.To(name), - Status: ptr.To(stackit.SnapshotReadyStatus), - CreatedAt: ptr.To(time.Now()), - Size: ptr.To(int64(10)), // 10 GiB - VolumeId: ptr.To(volID), + Id: new(uuid.New().String()), + Name: new(name), + Status: new(stackit.SnapshotReadyStatus), + CreatedAt: new(time.Now()), + Size: new(int64(10)), // 10 GiB + VolumeId: new(volID), } createdSnapshots[*newSnap.Id] = newSnap return newSnap, nil @@ -249,7 +248,7 @@ var _ = Describe("CSI sanity test", Ordered, func() { gomock.Any(), // context gomock.Any(), // snapshotID ).Return( - ptr.To(string(stackit.SnapshotReadyStatus)), + new(string(stackit.SnapshotReadyStatus)), nil, ).AnyTimes() @@ -263,12 +262,12 @@ var _ = Describe("CSI sanity test", Ordered, func() { gomock.Any(), // tags ).DoAndReturn(func(_ context.Context, name, volID, snapshotID string, _ map[string]string) (*iaas.Backup, error) { newBackup := &iaas.Backup{ - Id: ptr.To(uuid.New().String()), - Name: ptr.To(name), - Status: ptr.To("available"), - VolumeId: ptr.To(volID), - SnapshotId: ptr.To(snapshotID), - CreatedAt: ptr.To(time.Now()), + Id: new(uuid.New().String()), + Name: new(name), + Status: new("available"), + VolumeId: new(volID), + SnapshotId: new(snapshotID), + CreatedAt: new(time.Now()), } createdBackups[*newBackup.Id] = newBackup return newBackup, nil @@ -329,8 +328,8 @@ var _ = Describe("CSI sanity test", Ordered, func() { if !ok { return "", &oapierror.GenericOpenAPIError{StatusCode: http.StatusNotFound} } - vol.ServerId = ptr.To(instanceID) - vol.Status = ptr.To("attached") + vol.ServerId = new(instanceID) + vol.Status = new("attached") return *vol.Id, nil }).AnyTimes() diff --git a/pkg/csi/blockstorage/utils.go b/pkg/csi/blockstorage/utils.go index eec4015b..c749ef53 100644 --- a/pkg/csi/blockstorage/utils.go +++ b/pkg/csi/blockstorage/utils.go @@ -100,7 +100,7 @@ func DetermineMaxVolumesByFlavor(flavor string) int64 { } } -func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { +func logGRPC(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { callID := atomic.AddUint64(&serverGRPCEndpointCallCounter, 1) klog.V(3).Infof("[ID:%d] GRPC call: %s", callID, info.FullMethod) diff --git a/pkg/csi/util/mount/mount.go b/pkg/csi/util/mount/mount.go index a51496ca..0e458cc5 100644 --- a/pkg/csi/util/mount/mount.go +++ b/pkg/csi/util/mount/mount.go @@ -20,6 +20,7 @@ import ( "fmt" "os" "path" + "slices" "strings" "time" @@ -171,12 +172,10 @@ func (m *Mount) getDevicePathBySerialID(volumeID string) string { } for _, f := range files { - for _, c := range candidateDeviceNodes { - if c == f.Name() { - klog.V(4).Infof("Found disk attached as %q; full devicepath: %s\n", - f.Name(), path.Join("/dev/disk/by-id/", f.Name())) - return path.Join("/dev/disk/by-id/", f.Name()) - } + if slices.Contains(candidateDeviceNodes, f.Name()) { + klog.V(4).Infof("Found disk attached as %q; full devicepath: %s\n", + f.Name(), path.Join("/dev/disk/by-id/", f.Name())) + return path.Join("/dev/disk/by-id/", f.Name()) } } diff --git a/pkg/stackit/backups.go b/pkg/stackit/backups.go index 869728ee..5912155a 100644 --- a/pkg/stackit/backups.go +++ b/pkg/stackit/backups.go @@ -10,7 +10,6 @@ import ( "github.com/stackitcloud/stackit-sdk-go/core/runtime" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" - "k8s.io/utils/ptr" "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/stackiterrors" ) @@ -46,14 +45,14 @@ func (os *iaasClient) CreateBackup(ctx context.Context, name, volID, snapshotID } opts := iaas.CreateBackupPayload{ - Name: ptr.To(name), + Name: new(name), Source: &iaas.BackupSource{ - Type: ptr.To(string(backupSource)), - Id: ptr.To(backupSourceID), + Type: new(string(backupSource)), + Id: new(backupSourceID), }, } if tags != nil { - opts.Labels = ptr.To(map[string]interface{}(labelsFromTags(tags))) + opts.Labels = new(map[string]any(labelsFromTags(tags))) } var httpResp *http.Response ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(ctx, &httpResp) @@ -133,7 +132,7 @@ func (os *iaasClient) WaitBackupReady(ctx context.Context, backupID string, snap if back != nil { return back.Status, err } - return ptr.To("Failed to get backup status"), err + return new("Failed to get backup status"), err } func (os *iaasClient) waitBackupReadyWithContext(backupID string, duration time.Duration) error { diff --git a/pkg/stackit/backups_test.go b/pkg/stackit/backups_test.go index 8bf0d9ab..bd3beeab 100644 --- a/pkg/stackit/backups_test.go +++ b/pkg/stackit/backups_test.go @@ -8,7 +8,6 @@ import ( . "github.com/onsi/gomega" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "go.uber.org/mock/gomock" - "k8s.io/utils/ptr" mock "github.com/stackitcloud/cloud-provider-stackit/pkg/mock/iaas" ) @@ -68,10 +67,10 @@ var _ = Describe("Backup", func() { "volume-id", "", nil, iaas.CreateBackupPayload{ - Name: ptr.To("expected-name"), + Name: new("expected-name"), Source: &iaas.BackupSource{ - Type: ptr.To("volume"), - Id: ptr.To("volume-id"), + Type: new("volume"), + Id: new("volume-id"), }, Labels: nil, }, @@ -81,12 +80,12 @@ var _ = Describe("Backup", func() { "", "snapshot-id", map[string]string{"tag1": "value1"}, iaas.CreateBackupPayload{ - Name: ptr.To("expected-name"), + Name: new("expected-name"), Source: &iaas.BackupSource{ - Type: ptr.To("snapshot"), - Id: ptr.To("snapshot-id"), + Type: new("snapshot"), + Id: new("snapshot-id"), }, - Labels: ptr.To(map[string]any{ + Labels: new(map[string]any{ "tag1": "value1", }), }, @@ -159,12 +158,12 @@ var _ = Describe("Backup", func() { } expectedPayload := iaas.CreateBackupPayload{ - Name: ptr.To("expected-name"), + Name: new("expected-name"), Source: &iaas.BackupSource{ - Type: ptr.To("volume"), - Id: ptr.To("volume-id"), + Type: new("volume"), + Id: new("volume-id"), }, - Labels: ptr.To(map[string]any{ + Labels: new(map[string]any{ "special": "tag with spaces and !@#$%^&*()", "normal": "value", }), @@ -195,10 +194,10 @@ var _ = Describe("Backup", func() { It("should handle nil tags", func() { expectedPayload := iaas.CreateBackupPayload{ - Name: ptr.To("expected-name"), + Name: new("expected-name"), Source: &iaas.BackupSource{ - Type: ptr.To("volume"), - Id: ptr.To("volume-id"), + Type: new("volume"), + Id: new("volume-id"), }, Labels: nil, } @@ -214,12 +213,12 @@ var _ = Describe("Backup", func() { It("should handle empty tags map", func() { expectedPayload := iaas.CreateBackupPayload{ - Name: ptr.To("expected-name"), + Name: new("expected-name"), Source: &iaas.BackupSource{ - Type: ptr.To("volume"), - Id: ptr.To("volume-id"), + Type: new("volume"), + Id: new("volume-id"), }, - Labels: ptr.To(map[string]any{}), + Labels: new(map[string]any{}), } mockCreateBackup(mockCtrl, mockAPI, expectedPayload) @@ -235,10 +234,10 @@ var _ = Describe("Backup", func() { longName := "very-long-backup-name-" + string(make([]byte, 200)) expectedPayload := iaas.CreateBackupPayload{ - Name: ptr.To(longName), + Name: new(longName), Source: &iaas.BackupSource{ - Type: ptr.To("volume"), - Id: ptr.To("volume-id"), + Type: new("volume"), + Id: new("volume-id"), }, } @@ -260,7 +259,7 @@ func mockCreateBackup(mockCtrl *gomock.Controller, mockAPI *mock.MockDefaultApi, ) createRequest := mock.NewMockApiCreateBackupRequest(mockCtrl) createRequest.EXPECT().CreateBackupPayload(expectedPayload).Return(createRequest) - createRequest.EXPECT().Execute().Return(&iaas.Backup{Id: ptr.To("expected backup")}, nil) + createRequest.EXPECT().Execute().Return(&iaas.Backup{Id: new("expected backup")}, nil) mockAPI.EXPECT().CreateBackup(gomock.Any(), projectID, region).Return(createRequest) } diff --git a/pkg/stackit/filter_test.go b/pkg/stackit/filter_test.go index 69d1c68d..bc4918e6 100644 --- a/pkg/stackit/filter_test.go +++ b/pkg/stackit/filter_test.go @@ -4,7 +4,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "k8s.io/utils/ptr" ) var _ = Describe("Filter", func() { @@ -16,9 +15,9 @@ var _ = Describe("Filter", func() { BeforeEach(func() { backups = []iaas.Backup{ - {Status: ptr.To("available"), VolumeId: ptr.To("vol-1"), Name: ptr.To("backup-1")}, - {Status: ptr.To("error"), VolumeId: ptr.To("vol-2"), Name: ptr.To("backup-2")}, - {Status: ptr.To("available"), VolumeId: ptr.To("vol-1"), Name: ptr.To("backup-3")}, + {Status: new("available"), VolumeId: new("vol-1"), Name: new("backup-1")}, + {Status: new("error"), VolumeId: new("vol-2"), Name: new("backup-2")}, + {Status: new("available"), VolumeId: new("vol-1"), Name: new("backup-3")}, } filters = make(map[string]string) }) @@ -68,9 +67,9 @@ var _ = Describe("Filter", func() { BeforeEach(func() { volumes = []iaas.Volume{ - {Name: ptr.To("volume-1")}, - {Name: ptr.To("volume-2")}, - {Name: ptr.To("volume-1")}, + {Name: new("volume-1")}, + {Name: new("volume-2")}, + {Name: new("volume-1")}, } filters = make(map[string]string) }) @@ -97,9 +96,9 @@ var _ = Describe("Filter", func() { BeforeEach(func() { snapshots = []iaas.Snapshot{ - {Status: ptr.To("available"), VolumeId: ptr.To("vol-1"), Name: ptr.To("snapshot-1")}, - {Status: ptr.To("error"), VolumeId: ptr.To("vol-2"), Name: ptr.To("snapshot-2")}, - {Status: ptr.To("available"), VolumeId: ptr.To("vol-1"), Name: ptr.To("snapshot-3")}, + {Status: new("available"), VolumeId: new("vol-1"), Name: new("snapshot-1")}, + {Status: new("error"), VolumeId: new("vol-2"), Name: new("snapshot-2")}, + {Status: new("available"), VolumeId: new("vol-1"), Name: new("snapshot-3")}, } filters = make(map[string]string) }) diff --git a/pkg/stackit/labels.go b/pkg/stackit/labels.go index 36acef3f..0948daac 100644 --- a/pkg/stackit/labels.go +++ b/pkg/stackit/labels.go @@ -1,12 +1,12 @@ package stackit -type labels map[string]interface{} +type labels map[string]any func labelsFromTags(tags map[string]string) labels { - // Create a new map of type map[string]interface{} - l := make(map[string]interface{}, len(tags)) + // Create a new map of type map[string]any + l := make(map[string]any, len(tags)) - // Convert each value from string to interface{} + // Convert each value from string to any for key, value := range tags { l[key] = value } diff --git a/pkg/stackit/loadbalancer_test.go b/pkg/stackit/loadbalancer_test.go index 8ca7efaf..46aca1eb 100644 --- a/pkg/stackit/loadbalancer_test.go +++ b/pkg/stackit/loadbalancer_test.go @@ -35,7 +35,7 @@ var _ = Describe("LBAPI Client", func() { Describe("GetLoadBalancer", func() { It("should return the received load balancer instance", func() { expectedName := "test LB instance" - expectedLB := &loadbalancer.LoadBalancer{Name: ptr.To(expectedName)} + expectedLB := &loadbalancer.LoadBalancer{Name: new(expectedName)} mockAPI.EXPECT().GetLoadBalancerExecute(gomock.Any(), "projectID", gomock.Any(), expectedName). Return(expectedLB, nil).Times(1) diff --git a/pkg/stackit/metadata/metadata.go b/pkg/stackit/metadata/metadata.go index fb1b84eb..78d29595 100644 --- a/pkg/stackit/metadata/metadata.go +++ b/pkg/stackit/metadata/metadata.go @@ -313,8 +313,7 @@ func Get(ctx context.Context, order string) (*Metadata, error) { var md *Metadata var err error - elements := strings.Split(order, ",") - for _, id := range elements { + for id := range strings.SplitSeq(order, ",") { id = strings.TrimSpace(id) switch id { case ConfigDriveID: diff --git a/pkg/stackit/snapshots.go b/pkg/stackit/snapshots.go index 91490f8d..095cb0f4 100644 --- a/pkg/stackit/snapshots.go +++ b/pkg/stackit/snapshots.go @@ -11,7 +11,6 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/iaas" sdkWait "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/utils/ptr" ) const ( @@ -26,11 +25,11 @@ const ( func (os *iaasClient) CreateSnapshot(ctx context.Context, name, volID string, tags map[string]string) (*iaas.Snapshot, error) { opts := iaas.CreateSnapshotPayload{ - VolumeId: ptr.To(volID), - Name: ptr.To(name), + VolumeId: new(volID), + Name: new(name), } if tags != nil { - opts.Labels = ptr.To(map[string]interface{}(labelsFromTags(tags))) + opts.Labels = new(map[string]any(labelsFromTags(tags))) } var httpResp *http.Response ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(ctx, &httpResp) @@ -115,7 +114,7 @@ func (os *iaasClient) WaitSnapshotReady(ctx context.Context, snapshotID string) if snap != nil { return snap.Status, err } - return ptr.To("Failed to get snapshot status"), err + return new("Failed to get snapshot status"), err } func (os *iaasClient) snapshotIsReady(ctx context.Context, snapshotID string) (bool, error) { diff --git a/pkg/stackit/snapshots_test.go b/pkg/stackit/snapshots_test.go index 2fde27a5..e7efa1ab 100644 --- a/pkg/stackit/snapshots_test.go +++ b/pkg/stackit/snapshots_test.go @@ -8,7 +8,6 @@ import ( . "github.com/onsi/gomega" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "go.uber.org/mock/gomock" - "k8s.io/utils/ptr" mock "github.com/stackitcloud/cloud-provider-stackit/pkg/mock/iaas" ) @@ -37,22 +36,22 @@ var _ = Describe("Snapshot", func() { snapShotListResponse := iaas.SnapshotListResponse{ Items: &[]iaas.Snapshot{ { - Id: ptr.To("fake-snapshot"), - Name: ptr.To("fake-snapshot"), - VolumeId: ptr.To("some-special-volume"), - Status: ptr.To("ERROR"), + Id: new("fake-snapshot"), + Name: new("fake-snapshot"), + VolumeId: new("some-special-volume"), + Status: new("ERROR"), }, { - Id: ptr.To("fake-snapshot2"), - Name: ptr.To("fake-snapshot2"), - VolumeId: ptr.To("some-special-volume"), - Status: ptr.To("AVAILABLE"), + Id: new("fake-snapshot2"), + Name: new("fake-snapshot2"), + VolumeId: new("some-special-volume"), + Status: new("AVAILABLE"), }, { - Id: ptr.To("wrong snapshot"), - Name: ptr.To("wrong snapshot"), - VolumeId: ptr.To("another-special-volume"), - Status: ptr.To("AVAILABLE"), + Id: new("wrong snapshot"), + Name: new("wrong snapshot"), + VolumeId: new("another-special-volume"), + Status: new("AVAILABLE"), }, }, } @@ -81,16 +80,16 @@ var _ = Describe("Snapshot", func() { map[string]string{"VolumeID": "some-special-volume"}, []iaas.Snapshot{ { - Id: ptr.To("fake-snapshot"), - Name: ptr.To("fake-snapshot"), - VolumeId: ptr.To("some-special-volume"), - Status: ptr.To("ERROR"), + Id: new("fake-snapshot"), + Name: new("fake-snapshot"), + VolumeId: new("some-special-volume"), + Status: new("ERROR"), }, { - Id: ptr.To("fake-snapshot2"), - Name: ptr.To("fake-snapshot2"), - VolumeId: ptr.To("some-special-volume"), - Status: ptr.To("AVAILABLE"), + Id: new("fake-snapshot2"), + Name: new("fake-snapshot2"), + VolumeId: new("some-special-volume"), + Status: new("AVAILABLE"), }, }, ), @@ -98,10 +97,10 @@ var _ = Describe("Snapshot", func() { map[string]string{"Name": "fake-snapshot"}, []iaas.Snapshot{ { - Id: ptr.To("fake-snapshot"), - Name: ptr.To("fake-snapshot"), - VolumeId: ptr.To("some-special-volume"), - Status: ptr.To("ERROR"), + Id: new("fake-snapshot"), + Name: new("fake-snapshot"), + VolumeId: new("some-special-volume"), + Status: new("ERROR"), }, }, ), @@ -109,10 +108,10 @@ var _ = Describe("Snapshot", func() { map[string]string{"Name": "fake-snapshot2", "Status": "AVAILABLE"}, []iaas.Snapshot{ { - Id: ptr.To("fake-snapshot2"), - Name: ptr.To("fake-snapshot2"), - VolumeId: ptr.To("some-special-volume"), - Status: ptr.To("AVAILABLE"), + Id: new("fake-snapshot2"), + Name: new("fake-snapshot2"), + VolumeId: new("some-special-volume"), + Status: new("AVAILABLE"), }, }, ), diff --git a/pkg/stackit/volumes.go b/pkg/stackit/volumes.go index 8b539508..2fb142d2 100644 --- a/pkg/stackit/volumes.go +++ b/pkg/stackit/volumes.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "slices" "time" "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/stackiterrors" @@ -33,7 +34,7 @@ const ( var volumeErrorStates = [...]string{"ERROR", "ERROR_RESIZING", "ERROR_DELETING"} func (os *iaasClient) CreateVolume(ctx context.Context, payload *iaas.CreateVolumePayload) (*iaas.Volume, error) { - payload.Description = ptr.To(VolumeDescription) + payload.Description = new(VolumeDescription) var httpResp *http.Response ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(ctx, &httpResp) req, err := os.iaas.CreateVolume(ctxWithHTTPResp, os.projectID, os.region).CreateVolumePayload(*payload).Execute() @@ -82,7 +83,7 @@ func (os *iaasClient) AttachVolume(ctx context.Context, instanceID, volumeID str return *volume.Id, nil } payload := iaas.AddVolumeToServerPayload{ - DeleteOnTermination: ptr.To(false), + DeleteOnTermination: new(false), } var httpResp *http.Response ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(ctx, &httpResp) @@ -104,10 +105,8 @@ func (os *iaasClient) WaitVolumeTargetStatusWithCustomBackoff(ctx context.Contex if err != nil { return false, err } - for _, t := range tStatus { - if *vol.Status == t { - return true, nil - } + if slices.Contains(tStatus, *vol.Status) { + return true, nil } for _, eState := range volumeErrorStates { if *vol.Status == eState { @@ -305,10 +304,8 @@ func (os *iaasClient) WaitVolumeTargetStatus(ctx context.Context, volumeID strin if err != nil { return false, err } - for _, t := range tStatus { - if *vol.Status == t { - return true, nil - } + if slices.Contains(tStatus, *vol.Status) { + return true, nil } for _, eState := range volumeErrorStates { if *vol.Status == eState { @@ -326,7 +323,7 @@ func (os *iaasClient) WaitVolumeTargetStatus(ctx context.Context, volumeID strin } func (os *iaasClient) ExpandVolume(ctx context.Context, volumeID, volumeStatus string, newSize int64) error { - extendOpts := iaas.ResizeVolumePayload{Size: ptr.To(newSize)} + extendOpts := iaas.ResizeVolumePayload{Size: new(newSize)} var httpResp *http.Response ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(ctx, &httpResp)