Skip to content

Commit

Permalink
OPTIM/MINOR: remove regex for balance
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurand0710 authored and oktalz committed Feb 11, 2025
1 parent accf387 commit 5086a84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .aspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ allowed:
- maxconn
- kubebuilder
- cfg
- optim
15 changes: 10 additions & 5 deletions pkg/annotations/service/loadbalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -48,16 +47,22 @@ func (a *LoadBalance) Process(k store.K8s, annotations ...map[string]string) err

func GetParamsFromInput(value string) (*models.Balance, error) {
balance := &models.Balance{}
tokens := strings.Split(value, " ")
tokens := strings.Fields(value)
if len(tokens) == 0 {
return nil, errors.New("missing algorithm name")
}

reg := regexp.MustCompile(`(\(|\))`)
algorithmTokens := reg.Split(tokens[0], -1)
firstToken := strings.ReplaceAll(tokens[0], "(", " ")
firstToken = strings.ReplaceAll(firstToken, ")", " ")
algorithmTokens := strings.Fields(firstToken)

if len(algorithmTokens) == 0 {
return nil, errors.New("invalid algorithm format")
}

algorithm := algorithmTokens[0]
balance.Algorithm = &algorithm
if len(algorithmTokens) == 3 {
if len(algorithmTokens) == 2 {
switch algorithm {
case "hdr":
balance.HdrName = algorithmTokens[1]
Expand Down

0 comments on commit 5086a84

Please sign in to comment.