diff --git a/flytestdlib/config/tests/accessor_test.go b/flytestdlib/config/tests/accessor_test.go index 899938be64..f2328c5c36 100644 --- a/flytestdlib/config/tests/accessor_test.go +++ b/flytestdlib/config/tests/accessor_test.go @@ -22,6 +22,7 @@ import ( k8sRand "k8s.io/apimachinery/pkg/util/rand" "github.com/flyteorg/flyte/flytestdlib/config" + "github.com/flyteorg/flyte/flytestdlib/config/viper" "github.com/flyteorg/flyte/flytestdlib/internal/utils" ) @@ -132,7 +133,7 @@ func TestAccessor_InitializePflags(t *testing.T) { set := pflag.NewFlagSet("test", pflag.ContinueOnError) v.InitializePflags(set) - key := "MY_COMPONENT.STR2" + key := fmt.Sprintf("MY_COMPONENT%sSTR2", viper.KeyDelim) assert.NoError(t, os.Setenv(key, "123")) defer func() { assert.NoError(t, os.Unsetenv(key)) }() assert.NoError(t, v.UpdateConfig(context.TODO())) @@ -179,10 +180,10 @@ func TestAccessor_InitializePflags(t *testing.T) { set := pflag.NewFlagSet("test", pflag.ExitOnError) v.InitializePflags(set) - assert.NoError(t, set.Parse([]string{"--my-component.nested.int-val=3"})) + assert.NoError(t, set.Parse([]string{fmt.Sprintf("--my-component%snested%sint-val=3", viper.KeyDelim, viper.KeyDelim)})) assert.True(t, set.Parsed()) - flagValue, err := set.GetInt("my-component.nested.int-val") + flagValue, err := set.GetInt(fmt.Sprintf("my-component%snested%sint-val", viper.KeyDelim, viper.KeyDelim)) assert.NoError(t, err) assert.Equal(t, 3, flagValue) @@ -414,7 +415,7 @@ func TestAccessor_UpdateConfig(t *testing.T) { SearchPaths: []string{filepath.Join("testdata", "config.yaml")}, RootSection: reg, }) - key := strings.ToUpper("my-component.str") + key := strings.ToUpper(fmt.Sprintf("my-component%sstr", viper.KeyDelim)) assert.NoError(t, os.Setenv(key, "Set From Env")) defer func() { assert.NoError(t, os.Unsetenv(key)) }() assert.NoError(t, v.UpdateConfig(context.TODO())) @@ -428,7 +429,7 @@ func TestAccessor_UpdateConfig(t *testing.T) { assert.NoError(t, err) v := provider(config.Options{RootSection: reg}) - key := strings.ToUpper("my-component.str3") + key := strings.ToUpper(fmt.Sprintf("my-component%sstr3", viper.KeyDelim)) assert.NoError(t, os.Setenv(key, "Set From Env")) defer func() { assert.NoError(t, os.Unsetenv(key)) }() assert.NoError(t, v.UpdateConfig(context.TODO())) @@ -521,7 +522,7 @@ func TestAccessor_UpdateConfig(t *testing.T) { SearchPaths: []string{filepath.Join("testdata", "config.yaml")}, RootSection: reg, }) - key := strings.ToUpper("my-component.str") + key := strings.ToUpper(fmt.Sprintf("my-component%sstr", viper.KeyDelim)) assert.NoError(t, os.Setenv(key, "Set From Env")) defer func() { assert.NoError(t, os.Unsetenv(key)) }() assert.NoError(t, v.UpdateConfig(context.TODO())) diff --git a/flytestdlib/config/viper/collection.go b/flytestdlib/config/viper/collection.go index 914ff07526..aaf8927b5c 100644 --- a/flytestdlib/config/viper/collection.go +++ b/flytestdlib/config/viper/collection.go @@ -114,7 +114,7 @@ func (c CollectionProxy) MergeConfig(in io.Reader) error { } func (c CollectionProxy) MergeAllConfigs() (all Viper, err error) { - combinedConfig := viperLib.New() + combinedConfig := viperLib.NewWithOptions(viperLib.KeyDelimiter(KeyDelim)) if c.envVars != nil { for _, envConfig := range c.envVars { err = combinedConfig.BindEnv(envConfig...) diff --git a/flytestdlib/config/viper/viper.go b/flytestdlib/config/viper/viper.go index 9ba4a552c2..15877c8d86 100644 --- a/flytestdlib/config/viper/viper.go +++ b/flytestdlib/config/viper/viper.go @@ -25,7 +25,7 @@ import ( ) const ( - keyDelim = "." + KeyDelim = "::" ) var ( @@ -81,7 +81,7 @@ func (v viperAccessor) addSectionsPFlags(flags *pflag.FlagSet) (err error) { func (v viperAccessor) addSubsectionsPFlags(flags *pflag.FlagSet, rootKey string, root config.Section) error { for key, section := range root.GetSections() { - prefix := rootKey + key + keyDelim + prefix := rootKey + key + KeyDelim if asPFlagProvider, ok := section.GetConfig().(config.PFlagProvider); ok { flags.AddFlagSet(asPFlagProvider.GetPFlagSet(prefix)) } @@ -110,7 +110,7 @@ func (v viperAccessor) bindViperConfigsEnvDepth(m map[string]interface{}, prefix for key, val := range m { subKey := prefix + key if asMap, ok := val.(map[string]interface{}); ok { - errs.Append(v.bindViperConfigsEnvDepth(asMap, subKey+keyDelim)) + errs.Append(v.bindViperConfigsEnvDepth(asMap, subKey+KeyDelim)) } else { errs.Append(v.viper.BindEnv(subKey, strings.ToUpper(strings.Replace(subKey, "-", "_", -1)))) } @@ -272,6 +272,9 @@ func (v viperAccessor) parseViperConfigRecursive(root config.Section, settings i if asMap, casted := settings.(map[string]interface{}); casted { myMap := map[string]interface{}{} for childKey, childValue := range asMap { + if childKey == "default-annotations" { + logger.Debugf(context.Background(), "Found default-annotations in config. Skipping.") + } if childSection, found := root.GetSections()[childKey]; found { errs.Append(v.parseViperConfigRecursive(childSection, childValue)) } else { @@ -396,7 +399,7 @@ func (v viperAccessor) sendUpdatedEvents(ctx context.Context, root config.Sectio section.GetConfigUpdatedHandler()(ctx, section.GetConfig()) } - v.sendUpdatedEvents(ctx, section, forceSend, sectionKey+key+keyDelim) + v.sendUpdatedEvents(ctx, section, forceSend, sectionKey+key+KeyDelim) } } @@ -413,7 +416,7 @@ func newAccessor(opts config.Options) *viperAccessor { vipers := make([]Viper, 0, 1) configFiles := files.FindConfigFiles(opts.SearchPaths) for _, configFile := range configFiles { - v := viperLib.New() + v := viperLib.NewWithOptions(viperLib.KeyDelimiter(KeyDelim)) v.SetConfigFile(configFile) vipers = append(vipers, v) @@ -421,7 +424,7 @@ func newAccessor(opts config.Options) *viperAccessor { // Create a default viper even if we couldn't find any matching files if len(configFiles) == 0 { - v := viperLib.New() + v := viperLib.NewWithOptions(viperLib.KeyDelimiter(KeyDelim)) vipers = append(vipers, v) }