feat: load configuration from Environment variables

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2021-07-29 06:23:10 +00:00
parent 6560337a0a
commit 4c16276a8d
2 changed files with 9 additions and 1 deletions

View File

@@ -141,6 +141,11 @@ func TryLoadFromDisk() (*Config, error) {
// Load from current working directory, only used for debugging
viper.AddConfigPath(".")
// Load from Environment variables
viper.SetEnvPrefix("kubesphere")
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
return nil, err