@@ -3,14 +3,13 @@ package ccm
33import (
44 "fmt"
55 "net/netip"
6+ "slices"
67 "strconv"
78 "strings"
89 "time"
910
10- "github.com/stackitcloud/stackit-sdk-go/core/utils"
1111 "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
1212 corev1 "k8s.io/api/core/v1"
13- "k8s.io/utils/ptr"
1413
1514 "github.com/stackitcloud/cloud-provider-stackit/pkg/cmp"
1615)
@@ -216,10 +215,8 @@ func proxyProtocolEnableForPort(tcpProxyProtocolEnabled bool, tcpProxyProtocolPo
216215func getPlanID (service * corev1.Service ) (planID * string , msgs []string , err error ) {
217216 msgs = make ([]string , 0 )
218217 if planID , found := service .Annotations [servicePlanAnnotation ]; found {
219- for _ , availablePlan := range availablePlanIDs {
220- if planID == availablePlan {
221- return & planID , nil , nil
222- }
218+ if slices .Contains (availablePlanIDs , planID ) {
219+ return & planID , nil , nil
223220 }
224221 return nil , nil , fmt .Errorf ("unsupported plan ID value %q, supported values are %v" , planID , availablePlanIDs )
225222 }
@@ -251,7 +248,7 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
251248 Options : & loadbalancer.LoadBalancerOptions {},
252249 Networks : & []loadbalancer.Network {
253250 {
254- Role : utils . Ptr (loadbalancer .NETWORKROLE_LISTENERS_AND_TARGETS ),
251+ Role : new (loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS ),
255252 NetworkId : & opts .NetworkID ,
256253 },
257254 },
@@ -260,25 +257,25 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
260257 if listenerNetwork := service .Annotations [listenerNetworkAnnotation ]; listenerNetwork != "" {
261258 lb .Networks = & []loadbalancer.Network {
262259 {
263- Role : utils . Ptr (loadbalancer .NETWORKROLE_TARGETS ),
260+ Role : new (loadbalancer.NETWORKROLE_TARGETS ),
264261 NetworkId : & opts .NetworkID ,
265262 }, {
266- Role : utils . Ptr (loadbalancer .NETWORKROLE_LISTENERS ),
263+ Role : new (loadbalancer.NETWORKROLE_LISTENERS ),
267264 NetworkId : & listenerNetwork ,
268265 },
269266 }
270267 } else {
271268 lb .Networks = & []loadbalancer.Network {
272269 {
273- Role : utils . Ptr (loadbalancer .NETWORKROLE_LISTENERS_AND_TARGETS ),
270+ Role : new (loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS ),
274271 NetworkId : & opts .NetworkID ,
275272 },
276273 }
277274 }
278275
279276 // Add extraLabels if set
280277 if opts .ExtraLabels != nil {
281- lb .Labels = ptr . To (opts .ExtraLabels )
278+ lb .Labels = new (opts.ExtraLabels )
282279 }
283280
284281 // Add metric metricsRemoteWrite settings
@@ -288,7 +285,7 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
288285
289286 // Parse private network from annotations.
290287 // TODO: Split into separate function.
291- lb .Options .PrivateNetworkOnly = utils . Ptr (false )
288+ lb .Options .PrivateNetworkOnly = new (false )
292289 var internal * bool
293290 var yawolInternal * bool
294291 if internalStr , found := service .Annotations [internalLBAnnotation ]; found {
@@ -333,9 +330,9 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
333330 "incompatible values for annotations %s and %s" , yawolExistingFloatingIPAnnotation , externalIPAnnotation ,
334331 )
335332 }
336- lb .Options .EphemeralAddress = utils . Ptr (false )
333+ lb .Options .EphemeralAddress = new (false )
337334 if ! found && ! yawolFound && ! * lb .Options .PrivateNetworkOnly {
338- lb .Options .EphemeralAddress = utils . Ptr (true )
335+ lb .Options .EphemeralAddress = new (true )
339336 }
340337 if ! found && yawolFound {
341338 externalIP = yawolExternalIP
@@ -507,32 +504,32 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
507504 protocol = loadbalancer .LISTENERPROTOCOL_TCP
508505 }
509506 tcpOptions = & loadbalancer.OptionsTCP {
510- IdleTimeout : utils . Ptr (fmt .Sprintf ("%.0fs" , tcpIdleTimeout .Seconds ())),
507+ IdleTimeout : new (fmt.Sprintf ("%.0fs" , tcpIdleTimeout .Seconds ())),
511508 }
512509 case corev1 .ProtocolUDP :
513510 protocol = loadbalancer .LISTENERPROTOCOL_UDP
514511 udpOptions = & loadbalancer.OptionsUDP {
515- IdleTimeout : utils . Ptr (fmt .Sprintf ("%.0fs" , udpIdleTimeout .Seconds ())),
512+ IdleTimeout : new (fmt.Sprintf ("%.0fs" , udpIdleTimeout .Seconds ())),
516513 }
517514 default :
518515 return nil , nil , fmt .Errorf ("unsupported protocol %q for port %q" , port .Protocol , port .Name )
519516 }
520517
521518 listeners = append (listeners , loadbalancer.Listener {
522519 DisplayName : & name ,
523- Port : utils . Ptr (int64 (port .Port )),
520+ Port : new (int64 (port.Port )),
524521 TargetPool : & name ,
525- Protocol : utils . Ptr (protocol ),
522+ Protocol : new (protocol ),
526523 Tcp : tcpOptions ,
527524 Udp : udpOptions ,
528525 })
529526
530527 targetPools = append (targetPools , loadbalancer.TargetPool {
531528 Name : & name ,
532- TargetPort : utils . Ptr (int64 (port .NodePort )),
529+ TargetPort : new (int64 (port.NodePort )),
533530 Targets : & targets ,
534531 SessionPersistence : & loadbalancer.SessionPersistence {
535- UseSourceIpAddress : utils . Ptr (useSourceIP ),
532+ UseSourceIpAddress : new (useSourceIP ),
536533 },
537534 })
538535 }
0 commit comments