Merge pull request #8585 from prasadkatti/extra_option_8130
Do not auto-set extra config that user wishes to overridepull/8697/head
commit
45677496fa
|
@ -980,6 +980,10 @@ func autoSetDriverOptions(cmd *cobra.Command, drvName string) (err error) {
|
|||
hints := driver.FlagDefaults(drvName)
|
||||
if len(hints.ExtraOptions) > 0 {
|
||||
for _, eo := range hints.ExtraOptions {
|
||||
if config.ExtraOptions.Exists(eo) {
|
||||
glog.Infof("skipping extra-config %q.", eo)
|
||||
continue
|
||||
}
|
||||
glog.Infof("auto setting extra-config to %q.", eo)
|
||||
err = config.ExtraOptions.Set(eo)
|
||||
if err != nil {
|
||||
|
|
|
@ -19,6 +19,8 @@ package config
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// ExtraOption is an extra option
|
||||
|
@ -38,6 +40,29 @@ type ExtraOptionSlice []ExtraOption
|
|||
// ComponentExtraOptionMap maps components to their extra opts, which is a map of keys to values
|
||||
type ComponentExtraOptionMap map[string]map[string]string
|
||||
|
||||
// Exists returns true if component.key (parsed from value) is already in ExtraOptionSlice
|
||||
func (es *ExtraOptionSlice) Exists(value string) bool {
|
||||
// The component is the value before the first dot.
|
||||
componentSplit := strings.SplitN(value, ".", 2)
|
||||
if len(componentSplit) != 2 {
|
||||
glog.Errorf("invalid value: must contain at least one period: %q", value)
|
||||
return false
|
||||
}
|
||||
|
||||
keySplit := strings.SplitN(componentSplit[1], "=", 2)
|
||||
if len(keySplit) != 2 {
|
||||
glog.Errorf("invalid value: must contain one equal sign: %q", value)
|
||||
return false
|
||||
}
|
||||
|
||||
for _, opt := range *es {
|
||||
if opt.Component == componentSplit[0] && opt.Key == keySplit[0] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Set parses the string value into a slice
|
||||
func (es *ExtraOptionSlice) Set(value string) error {
|
||||
// The component is the value before the first dot.
|
||||
|
|
|
@ -79,6 +79,29 @@ func TestValidFlags(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
extraOptions := ExtraOptionSlice{
|
||||
ExtraOption{Component: "c1", Key: "bar", Value: "c1-bar"},
|
||||
ExtraOption{Component: "c1", Key: "baz", Value: "c1-baz"},
|
||||
ExtraOption{Component: "c2", Key: "bar", Value: "c2-bar"},
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
searchString string
|
||||
expRes bool
|
||||
}{
|
||||
{"c1.bar=bar", true},
|
||||
{"c1.foo=foo", false},
|
||||
{"c2.bar=bar", true},
|
||||
{"c2.baz=baz", false},
|
||||
{"c3.baz=baz", false},
|
||||
} {
|
||||
if res := extraOptions.Exists(tc.searchString); res != tc.expRes {
|
||||
t.Errorf("Unexpected value. Expected %t, got %t", tc.expRes, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
extraOptions := ExtraOptionSlice{
|
||||
ExtraOption{Component: "c1", Key: "bar", Value: "c1-bar"},
|
||||
|
|
Loading…
Reference in New Issue