server: Introduce a new env MINIO_REGION. (#4078)

This is implemented to be able to override region
through command line just like how access and
secret keys are provided.
master
Harshavardhana 8 years ago committed by GitHub
parent 604417baf4
commit b927523223
  1. 12
      cmd/config-v18.go
  2. 14
      cmd/config-v18_test.go
  3. 6
      cmd/globals.go
  4. 7
      cmd/server-main.go
  5. 2
      cmd/test-utils_test.go

@ -170,6 +170,10 @@ func newConfig() error {
srvCfg.SetBrowser(globalIsBrowserEnabled) srvCfg.SetBrowser(globalIsBrowserEnabled)
} }
if globalIsEnvRegion {
srvCfg.SetRegion(globalServerRegion)
}
// hold the mutex lock before a new config is assigned. // hold the mutex lock before a new config is assigned.
// Save the new config globally. // Save the new config globally.
// unlock the mutex. // unlock the mutex.
@ -295,10 +299,15 @@ func loadConfig() error {
if globalIsEnvCreds { if globalIsEnvCreds {
srvCfg.SetCredential(globalActiveCred) srvCfg.SetCredential(globalActiveCred)
} }
if globalIsEnvBrowser { if globalIsEnvBrowser {
srvCfg.SetBrowser(globalIsBrowserEnabled) srvCfg.SetBrowser(globalIsBrowserEnabled)
} }
if globalIsEnvRegion {
srvCfg.SetRegion(globalServerRegion)
}
// hold the mutex lock before a new config is assigned. // hold the mutex lock before a new config is assigned.
serverConfigMu.Lock() serverConfigMu.Lock()
serverConfig = srvCfg serverConfig = srvCfg
@ -308,6 +317,9 @@ func loadConfig() error {
if !globalIsEnvBrowser { if !globalIsEnvBrowser {
globalIsBrowserEnabled = serverConfig.GetBrowser() globalIsBrowserEnabled = serverConfig.GetBrowser()
} }
if !globalIsEnvRegion {
globalServerRegion = serverConfig.GetRegion()
}
serverConfigMu.Unlock() serverConfigMu.Unlock()
return nil return nil

@ -138,10 +138,10 @@ func TestServerConfigWithEnvs(t *testing.T) {
os.Setenv("MINIO_SECRET_KEY", "minio123") os.Setenv("MINIO_SECRET_KEY", "minio123")
defer os.Unsetenv("MINIO_SECRET_KEY") defer os.Unsetenv("MINIO_SECRET_KEY")
defer func() { os.Setenv("MINIO_REGION", "us-west-1")
globalIsEnvBrowser = false defer os.Unsetenv("MINIO_REGION")
globalIsEnvCreds = false
}() defer resetGlobalIsEnvs()
// Get test root. // Get test root.
rootPath, err := getTestRoot() rootPath, err := getTestRoot()
@ -165,6 +165,11 @@ func TestServerConfigWithEnvs(t *testing.T) {
t.Errorf("Expecting browser is set to false found %v", serverConfig.GetBrowser()) t.Errorf("Expecting browser is set to false found %v", serverConfig.GetBrowser())
} }
// Check if serverConfig has
if serverConfig.GetRegion() != "us-west-1" {
t.Errorf("Expecting region to be \"us-west-1\" found %v", serverConfig.GetRegion())
}
// Check if serverConfig has // Check if serverConfig has
cred := serverConfig.GetCredential() cred := serverConfig.GetCredential()
@ -175,6 +180,7 @@ func TestServerConfigWithEnvs(t *testing.T) {
if cred.SecretKey != "minio123" { if cred.SecretKey != "minio123" {
t.Errorf("Expecting access key to be `minio123` found %s", cred.SecretKey) t.Errorf("Expecting access key to be `minio123` found %s", cred.SecretKey)
} }
} }
func TestCheckDupJSONKeys(t *testing.T) { func TestCheckDupJSONKeys(t *testing.T) {

@ -66,9 +66,15 @@ var (
globalIsBrowserEnabled = true globalIsBrowserEnabled = true
// This flag is set to 'true' when MINIO_BROWSER env is set. // This flag is set to 'true' when MINIO_BROWSER env is set.
globalIsEnvBrowser = false globalIsEnvBrowser = false
// Set to true if credentials were passed from env, default is false. // Set to true if credentials were passed from env, default is false.
globalIsEnvCreds = false globalIsEnvCreds = false
// This flag is set to 'true' wen MINIO_REGION env is set.
globalIsEnvRegion = false
// This flag is set to 'us-east-1' by default
globalServerRegion = globalMinioDefaultRegion
// Maximum size of internal objects parts // Maximum size of internal objects parts
globalPutPartSize = int64(64 * 1024 * 1024) globalPutPartSize = int64(64 * 1024 * 1024)

@ -454,6 +454,13 @@ func serverHandleEnvVars() {
globalIsEnvBrowser = true globalIsEnvBrowser = true
globalIsBrowserEnabled = bool(browserFlag) globalIsBrowserEnabled = bool(browserFlag)
} }
if serverRegion := os.Getenv("MINIO_REGION"); serverRegion != "" {
// region Envs are set globally.
globalIsEnvRegion = true
globalServerRegion = serverRegion
}
} }
// serverMain handler called for 'minio server' command. // serverMain handler called for 'minio server' command.

@ -490,6 +490,8 @@ func resetGlobalIsXL() {
func resetGlobalIsEnvs() { func resetGlobalIsEnvs() {
globalIsEnvCreds = false globalIsEnvCreds = false
globalIsEnvBrowser = false
globalIsEnvRegion = false
} }
// Resets all the globals used modified in tests. // Resets all the globals used modified in tests.

Loading…
Cancel
Save