From fb20f156e867e174d10a8be4a744f19f8c62ecf5 Mon Sep 17 00:00:00 2001 From: Predrag Janosevic Date: Wed, 15 Jan 2025 15:28:58 +0000 Subject: [PATCH] Implemment staticcheck and fmt suggestions (#100) --- exoscale/loadbalancer.go | 10 +++++----- exoscale/loadbalancer_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/exoscale/loadbalancer.go b/exoscale/loadbalancer.go index 93ad2029..aec47ca6 100644 --- a/exoscale/loadbalancer.go +++ b/exoscale/loadbalancer.go @@ -28,7 +28,7 @@ const ( annotationLoadBalancerServiceDescription = annotationPrefix + "service-description" annotationLoadBalancerServiceInstancePoolID = annotationPrefix + "service-instancepool-id" annotationLoadBalancerServiceHealthCheckMode = annotationPrefix + "service-healthcheck-mode" - annotationLoadBalancerServiceHealthCheckPort = annotationPrefix + "service-healthcheck-port" + annotationLoadBalancerServiceHealthCheckPort = annotationPrefix + "service-healthcheck-port" annotationLoadBalancerServiceHealthCheckURI = annotationPrefix + "service-healthcheck-uri" annotationLoadBalancerServiceHealthCheckInterval = annotationPrefix + "service-healthcheck-interval" annotationLoadBalancerServiceHealthCheckTimeout = annotationPrefix + "service-healthcheck-timeout" @@ -215,7 +215,7 @@ func (l *loadBalancer) EnsureLoadBalancerDeleted(ctx context.Context, _ string, remainingServices := len(nlb.Services) for _, nlbService := range nlb.Services { for _, servicePort := range service.Spec.Ports { - if int32(*nlbService.Port) == servicePort.Port && strings.ToLower(*nlbService.Protocol) == strings.ToLower(string(servicePort.Protocol)) { + if int32(*nlbService.Port) == servicePort.Port && strings.EqualFold(*nlbService.Protocol, string(servicePort.Protocol)) { infof("deleting NLB service %s/%s", *nlb.Name, *nlbService.Name) if err = l.p.client.DeleteNetworkLoadBalancerService(ctx, l.p.zone, nlb, nlbService); err != nil { return err @@ -282,13 +282,13 @@ next: for _, nlbServiceCurrent := range nlbCurrent.Services { key := ServiceKey{Port: *nlbServiceCurrent.Port, Protocol: *nlbServiceCurrent.Protocol} debugf("Checking existing NLB service %s/%s - key %v", *nlbCurrent.Name, *nlbServiceCurrent.Name, key) - + for _, nlbServiceUpdate := range nlbUpdate.Services { updateKey := ServiceKey{Port: *nlbServiceUpdate.Port, Protocol: *nlbServiceUpdate.Protocol} - + if key == updateKey { debugf("Match found for existing service %s/%s with updated service %s/%s", - *nlbCurrent.Name, *nlbServiceCurrent.Name, *nlbUpdate.Name, *nlbServiceUpdate.Name) + *nlbCurrent.Name, *nlbServiceCurrent.Name, *nlbUpdate.Name, *nlbServiceUpdate.Name) nlbServices[key] = nlbServiceCurrent continue next } diff --git a/exoscale/loadbalancer_test.go b/exoscale/loadbalancer_test.go index bf1c8254..2a065661 100644 --- a/exoscale/loadbalancer_test.go +++ b/exoscale/loadbalancer_test.go @@ -369,9 +369,9 @@ func (ts *exoscaleCCMTestSuite) Test_loadBalancer_EnsureLoadBalancerDeleted() { k8sServiceUID = ts.randomID() k8sServicePortPort uint16 = 80 k8sServicePortNodePort uint16 = 32672 - k8sServicePortProtocol = v1.ProtocolTCP + k8sServicePortProtocol = v1.ProtocolTCP nlbServicePortName = fmt.Sprintf("%s-%d", k8sServiceUID, k8sServicePortPort) - nlbServicePortProtocol = strings.ToLower(string(v1.ProtocolTCP)) + nlbServicePortProtocol = strings.ToLower(string(v1.ProtocolTCP)) nlbDeleted = false nlbServiceDeleted = false @@ -379,8 +379,8 @@ func (ts *exoscaleCCMTestSuite) Test_loadBalancer_EnsureLoadBalancerDeleted() { ID: &testNLBID, Name: &testNLBName, Services: []*egoscale.NetworkLoadBalancerService{{ - Name: &nlbServicePortName, - Port: &k8sServicePortPort, + Name: &nlbServicePortName, + Port: &k8sServicePortPort, Protocol: &nlbServicePortProtocol, }}, } @@ -1037,7 +1037,7 @@ func Test_buildLoadBalancerFromAnnotations(t *testing.T) { // Variant: UDP with healthcheck port defined var serviceHealthCheckPort uint16 = 32123 - + service.Spec.Ports[0].Protocol = v1.ProtocolUDP service.Annotations[annotationLoadBalancerServiceHealthCheckPort] = fmt.Sprint(serviceHealthCheckPort) expected.Services[0].Protocol = &testNLBServiceProtocolUDP