Skip to content

Commit 5086a84

Browse files
hdurand0710oktalz
authored andcommitted
OPTIM/MINOR: remove regex for balance
1 parent accf387 commit 5086a84

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.aspell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ allowed:
3535
- maxconn
3636
- kubebuilder
3737
- cfg
38+
- optim

pkg/annotations/service/loadbalance.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package service
33
import (
44
"errors"
55
"fmt"
6-
"regexp"
76
"strconv"
87
"strings"
98

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

4948
func GetParamsFromInput(value string) (*models.Balance, error) {
5049
balance := &models.Balance{}
51-
tokens := strings.Split(value, " ")
50+
tokens := strings.Fields(value)
5251
if len(tokens) == 0 {
5352
return nil, errors.New("missing algorithm name")
5453
}
5554

56-
reg := regexp.MustCompile(`(\(|\))`)
57-
algorithmTokens := reg.Split(tokens[0], -1)
55+
firstToken := strings.ReplaceAll(tokens[0], "(", " ")
56+
firstToken = strings.ReplaceAll(firstToken, ")", " ")
57+
algorithmTokens := strings.Fields(firstToken)
58+
59+
if len(algorithmTokens) == 0 {
60+
return nil, errors.New("invalid algorithm format")
61+
}
62+
5863
algorithm := algorithmTokens[0]
5964
balance.Algorithm = &algorithm
60-
if len(algorithmTokens) == 3 {
65+
if len(algorithmTokens) == 2 {
6166
switch algorithm {
6267
case "hdr":
6368
balance.HdrName = algorithmTokens[1]

0 commit comments

Comments
 (0)