Skip to content

Commit

Permalink
Implemment staticcheck and fmt suggestions (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobajagi authored Jan 15, 2025
1 parent 91f4a67 commit fb20f15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions exoscale/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions exoscale/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,18 @@ 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

expectedNLB = &egoscale.NetworkLoadBalancer{
ID: &testNLBID,
Name: &testNLBName,
Services: []*egoscale.NetworkLoadBalancerService{{
Name: &nlbServicePortName,
Port: &k8sServicePortPort,
Name: &nlbServicePortName,
Port: &k8sServicePortPort,
Protocol: &nlbServicePortProtocol,
}},
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb20f15

Please sign in to comment.