diff --git a/pkg/config/env_source.go b/pkg/config/env_source.go index 48bc6e54ba..d0f931fc24 100644 --- a/pkg/config/env_source.go +++ b/pkg/config/env_source.go @@ -24,15 +24,20 @@ import ( "github.com/milvus-io/milvus/pkg/v2/util/typeutil" ) +// DefaultEnvPrefix is the default prefix for environment variables +const DefaultEnvPrefix = "MILVUS_CONF_" + type EnvSource struct { configs *typeutil.ConcurrentMap[string, string] KeyFormatter func(string) string + prefix string } func NewEnvSource(KeyFormatter func(string) string) EnvSource { es := EnvSource{ configs: typeutil.NewConcurrentMap[string, string](), KeyFormatter: KeyFormatter, + prefix: DefaultEnvPrefix, } for _, value := range os.Environ() { @@ -43,6 +48,15 @@ func NewEnvSource(KeyFormatter func(string) string) EnvSource { envKey := KeyFormatter(key) es.configs.Insert(key, value) es.configs.Insert(envKey, value) + + // Handle prefixed environment variables + // e.g., MILVUS_MINIO_PORT will override MINIO_PORT + if strings.HasPrefix(key, es.prefix) { + originalKey := key[len(es.prefix):] + originalEnvKey := KeyFormatter(originalKey) + es.configs.Insert(originalKey, value) + es.configs.Insert(originalEnvKey, value) + } } return es }