Skip to content

Commit

Permalink
fixup! fixup! fixup! add global lables to liqo-created resources
Browse files Browse the repository at this point in the history
  • Loading branch information
aleoli committed Nov 26, 2024
1 parent f1a6987 commit e8ac103
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/utils/args/stringmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
)

// StringMap implements the flag.Value interface and allows to parse stringified maps
// in the form: "key1=val1,key2=val2".
// in the form: "key1=val1,key2=val2". Values can contain additional '=' characters,
// for example: "argocd.argoproj.io/sync-options=Prune=false". In this case, only the
// first '=' is used as the key-value separator.
type StringMap struct {
StringMap map[string]string
}
Expand All @@ -41,21 +43,30 @@ func (sm StringMap) String() string {
}

// Set parses the provided string into the map[string]string map.
// The input string is expected to be in the format "key1=val1,key2=val2,...".
// Multiple '=' characters in the value part are preserved, only the first '='
// is used as the key-value separator.
func (sm *StringMap) Set(str string) error {
if sm.StringMap == nil {
sm.StringMap = map[string]string{}
}
if str == "" {
return nil
}
// Split the input string into chunks using comma as separator
chunks := strings.Split(str, ",")
for i := range chunks {
chunk := chunks[i]
strs := strings.Split(chunk, "=")
if len(strs) != 2 {
return fmt.Errorf("invalid value %v", chunk)
// Find the position of the first '=' character which separates key from value
idx := strings.Index(chunk, "=")
if idx == -1 {
return fmt.Errorf("invalid value %v: missing '=' separator", chunk)
}
sm.StringMap[strs[0]] = strs[1]
// Extract key and value using the position of the first '='
// Any subsequent '=' characters will be part of the value
key := chunk[:idx]
value := chunk[idx+1:]
sm.StringMap[key] = value
}
return nil
}
Expand Down

0 comments on commit e8ac103

Please sign in to comment.