Allow setting string slices in extra config

pull/992/head
Jimmi Dyson 2017-01-12 12:10:53 +00:00
parent 771aeb967c
commit 23a1e4ada4
No known key found for this signature in database
GPG Key ID: 978CD4AF4C1E87F5
2 changed files with 6 additions and 0 deletions

View File

@ -80,6 +80,9 @@ func setElement(e reflect.Value, v string) error {
return fmt.Errorf("Error converting input %s to PortRange: %s", v, err)
}
e.Set(reflect.ValueOf(*pr))
case []string:
vals := strings.Split(v, ",")
e.Set(reflect.ValueOf(vals))
default:
return fmt.Errorf("Unable to set type %T.", t)
}

View File

@ -19,6 +19,7 @@ package util
import (
"math"
"net"
"reflect"
"testing"
utilnet "k8s.io/kubernetes/pkg/util/net"
@ -52,6 +53,7 @@ type subConfig3 struct {
P bool
Q net.IP
R utilnet.PortRange
S []string
}
func buildConfig() testConfig {
@ -169,6 +171,7 @@ func TestSetElement(t *testing.T) {
{"D.I.P", "false", func(t testConfig) bool { return bool(t.D.I.P) == false }},
{"D.I.Q", "11.22.33.44", func(t testConfig) bool { return t.D.I.Q.Equal(net.ParseIP("11.22.33.44")) }},
{"D.I.R", "7-11", func(t testConfig) bool { return t.D.I.R.Base == 7 && t.D.I.R.Size == 5 }},
{"D.I.S", "a,b", func(t testConfig) bool { return reflect.DeepEqual(t.D.I.S, []string{"a", "b"}) }},
} {
a := buildConfig()
if err := FindAndSet(tc.path, &a, tc.newval); err != nil {