changing env names, and adding some comments
@@ -11,11 +11,13 @@ import (
)
func findValEffect(find string) (string, string, error) {
+ //Is the find string not null?
if len(find) < 1 {
return "", "", errors.New("Empty string in findValEffect")
}
findte := strings.Split(find, ":")
if len(findte) > 1 {
+ //if we split the string, and the value isn't null (we don't have ":something"), return the values
tvalue := findte[0]
teffect := findte[1]
if len(tvalue) < 1 {
@@ -23,34 +25,41 @@ func findValEffect(find string) (string, string, error) {
}
return tvalue, teffect, nil
}
+ // if we couldn't split the string, just return it back as the value
return find, "", nil
}
func createToleration(toleration string) (*corev1.Toleration, error) {
t := corev1.Toleration{}
+
+ // Ensure we were supplied a toleration string
if len(toleration) < 1 {
errorMessage := "Must pass toleration value to createToleration"
return &t, errors.New(errorMessage)
}
- splitkv := strings.Split(toleration, "=")
+ splitKV := strings.Split(toleration, "=")
//does toleration has a value provided
- if len(splitkv) > 1 {
- if len(splitkv[0]) < 1 {
+ if len(splitKV) > 1 {
+ //make sure there's real values on both sides of the split
+ if len(splitKV[0]) < 1 {
return &t, errors.New("Empty key after split on =")
}
- tvalue, teffect, err := findValEffect(splitkv[1])
+ // try to get value and effect by splitting on :
+ tValue, tEffect, err := findValEffect(splitKV[1])
if err != nil {
log.Errorln(err)
return &t, err
}
+ // create toleration based on returned value/effect
t = corev1.Toleration{
- Key: splitkv[0],
+ Key: splitKV[0],
Operator: corev1.TolerationOpEqual,
- Value: tvalue,
- Effect: corev1.TaintEffect(teffect),
+ Value: tValue,
+ Effect: corev1.TaintEffect(tEffect),
}
return &t, nil
}
+ // if no split can be done, just create a toleration based on the supplied string
t = corev1.Toleration{
Key: toleration,
Operator: corev1.TolerationOpExists,
@@ -144,6 +153,7 @@ func parseInputValues() {
//parse each toleration, create a corev1.Toleration object, and append to tolerations slice
tol, err := createToleration(toleration)
if err != nil {
+ // if we can't get a toleration based on that string, skip it and go on to the next one
log.Errorln(err)
continue
}
@@ -153,10 +163,12 @@ func parseInputValues() {
//parse single toleration and append to slice
tol, err := createToleration(tolerationsEnv)
if err != nil {
+ // if we can't create a toleration, error out and return
log.Errorln(err)
return
}
tolerations = append(tolerations, *tol)
+ // if we parsed tolerations, log them
if len(tolerations) > 1 {
log.Infoln("Parsed TOLERATIONS:", tolerations)
}
