forked from kubeflow/arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
40 lines (35 loc) · 1 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package argsbuilder
import (
"errors"
"github.com/kubeflow/arena/pkg/apis/types"
"strings"
)
func transformSliceToMap(sets []string, split string) (valuesMap map[string]string) {
valuesMap = map[string]string{}
for _, member := range sets {
splits := strings.SplitN(member, split, 2)
if len(splits) == 2 {
valuesMap[splits[0]] = splits[1]
}
}
return valuesMap
}
func parseTolerationString(toleration string) (*types.TolerationArgs, error) {
if strings.Contains(toleration, "=") && strings.Contains(toleration, ":") && strings.Contains(toleration, ",") {
key, toleration := split(toleration, "=")
value, toleration := split(toleration, ":")
effect, operator := split(toleration, ",")
return &types.TolerationArgs{
Key: key,
Value: value,
Effect: effect,
Operator: operator,
}, nil
} else {
return nil, errors.New("invalid toleration format")
}
}
func split(value, sep string) (string, string) {
index := strings.Index(value, sep)
return value[:index], value[index+1:]
}