From 676d096a877e5d4f6b9f42e28a6b1304679c52a3 Mon Sep 17 00:00:00 2001 From: Yee Hing Tong Date: Wed, 11 Oct 2023 09:38:17 +0800 Subject: [PATCH] add default config file itself into search path Signed-off-by: Yee Hing Tong --- flyteartifacts/artifact_config.yaml | 2 ++ flyteartifacts/cmd/main.go | 10 +++++++--- flyteartifacts/pkg/configuration/config.go | 6 +++++- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 flyteartifacts/artifact_config.yaml diff --git a/flyteartifacts/artifact_config.yaml b/flyteartifacts/artifact_config.yaml new file mode 100644 index 00000000000..b8b59a13269 --- /dev/null +++ b/flyteartifacts/artifact_config.yaml @@ -0,0 +1,2 @@ +artifactsServer: + myTestValue: "test from file" \ No newline at end of file diff --git a/flyteartifacts/cmd/main.go b/flyteartifacts/cmd/main.go index 8a5235e3030..fc4e939d175 100644 --- a/flyteartifacts/cmd/main.go +++ b/flyteartifacts/cmd/main.go @@ -69,16 +69,20 @@ func init() { } func initConfig(flags *pflag.FlagSet) error { - fmt.Println("initConfig called") configAccessor = viper.NewAccessor(config.Options{ - SearchPaths: []string{cfgFile, ".", "/etc/flyte/config", "$GOPATH/src/github.com/flyteorg/flyte/flyteartifacts"}, + SearchPaths: []string{cfgFile, "./artifact_config.yaml", ".", "/etc/flyte/config", "$GOPATH/src/github.com/flyteorg/flyte/flyteartifacts"}, StrictMode: false, }) logger.Infof(context.TODO(), "Using config file: %v", configAccessor.ConfigFilesUsed()) configAccessor.InitializePflags(flags) - fmt.Println("initConfig finish") + + err := flag.CommandLine.Parse([]string{}) + if err != nil { + fmt.Println(err) + os.Exit(-1) + } return configAccessor.UpdateConfig(context.TODO()) } diff --git a/flyteartifacts/pkg/configuration/config.go b/flyteartifacts/pkg/configuration/config.go index 18e72891655..fbcf21f866f 100644 --- a/flyteartifacts/pkg/configuration/config.go +++ b/flyteartifacts/pkg/configuration/config.go @@ -10,4 +10,8 @@ type ApplicationConfiguration struct { MyTestValue string `json:"myTestValue" pflag:",Test config value"` } -var ApplicationConfig = config.MustRegisterSection(artifactsServer, &ApplicationConfiguration{}) +var defaultApplicationConfiguration = ApplicationConfiguration{ + MyTestValue: "default", +} + +var ApplicationConfig = config.MustRegisterSection(artifactsServer, &defaultApplicationConfiguration)