mirror of
https://github.com/minio/minio.git
synced 2025-11-10 05:59:43 -05:00
fix: --console-address when specified endpoints missing (#12534)
Additionally upgrade console dependency for reading environment variables properly.
This commit is contained in:
@@ -115,6 +115,9 @@ func minioConfigToConsoleFeatures() {
|
||||
if value := os.Getenv("MINIO_LOG_QUERY_URL"); value != "" {
|
||||
os.Setenv("CONSOLE_LOG_QUERY_URL", value)
|
||||
}
|
||||
if value := os.Getenv("MINIO_LOG_QUERY_AUTH_TOKEN"); value != "" {
|
||||
os.Setenv("CONSOLE_LOG_QUERY_AUTH_TOKEN", value)
|
||||
}
|
||||
// Enable if prometheus URL is set.
|
||||
if value := os.Getenv("MINIO_PROMETHEUS_URL"); value != "" {
|
||||
os.Setenv("CONSOLE_PROMETHEUS_URL", value)
|
||||
@@ -337,40 +340,43 @@ func handleCommonCmdArgs(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
// Fetch address option
|
||||
globalCLIContext.Addr = ctx.GlobalString("address")
|
||||
if globalCLIContext.Addr == "" || globalCLIContext.Addr == ":"+GlobalMinioDefaultPort {
|
||||
globalCLIContext.Addr = ctx.String("address")
|
||||
addr := ctx.GlobalString("address")
|
||||
if addr == "" || addr == ":"+GlobalMinioDefaultPort {
|
||||
addr = ctx.String("address")
|
||||
}
|
||||
|
||||
// Fetch console address option
|
||||
globalCLIContext.ConsoleAddr = ctx.GlobalString("console-address")
|
||||
if globalCLIContext.ConsoleAddr == "" {
|
||||
globalCLIContext.ConsoleAddr = ctx.String("console-address")
|
||||
consoleAddr := ctx.GlobalString("console-address")
|
||||
if consoleAddr == "" {
|
||||
consoleAddr = ctx.String("console-address")
|
||||
}
|
||||
|
||||
if globalCLIContext.ConsoleAddr == "" {
|
||||
if consoleAddr == "" {
|
||||
p, err := xnet.GetFreePort()
|
||||
if err != nil {
|
||||
logger.FatalIf(err, "Unable to get free port for console on the host")
|
||||
}
|
||||
globalMinioConsolePortAuto = true
|
||||
globalCLIContext.ConsoleAddr = net.JoinHostPort("", p.String())
|
||||
consoleAddr = net.JoinHostPort("", p.String())
|
||||
}
|
||||
|
||||
if globalCLIContext.ConsoleAddr == globalCLIContext.Addr {
|
||||
if _, _, err := net.SplitHostPort(consoleAddr); err != nil {
|
||||
logger.FatalIf(err, "Unable to start listening on console port")
|
||||
}
|
||||
|
||||
if consoleAddr == addr {
|
||||
logger.FatalIf(errors.New("--console-address cannot be same as --address"), "Unable to start the server")
|
||||
}
|
||||
|
||||
globalMinioAddr = globalCLIContext.Addr
|
||||
globalMinioConsoleAddr = globalCLIContext.ConsoleAddr
|
||||
|
||||
globalMinioHost, globalMinioPort = mustSplitHostPort(globalMinioAddr)
|
||||
globalMinioConsoleHost, globalMinioConsolePort = mustSplitHostPort(globalMinioConsoleAddr)
|
||||
globalMinioHost, globalMinioPort = mustSplitHostPort(addr)
|
||||
globalMinioConsoleHost, globalMinioConsolePort = mustSplitHostPort(consoleAddr)
|
||||
|
||||
if globalMinioPort == globalMinioConsolePort {
|
||||
logger.FatalIf(errors.New("--console-address port cannot be same as --address port"), "Unable to start the server")
|
||||
}
|
||||
|
||||
globalMinioAddr = addr
|
||||
|
||||
// Check "no-compat" flag from command line argument.
|
||||
globalCLIContext.StrictS3Compat = true
|
||||
if ctx.IsSet("no-compat") || ctx.GlobalIsSet("no-compat") {
|
||||
@@ -401,6 +407,11 @@ func handleCommonEnvVars() {
|
||||
logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER value in environment variable")
|
||||
}
|
||||
|
||||
globalBrowserRedirect, err = config.ParseBool(env.Get(config.EnvBrowserRedirect, config.EnableOn))
|
||||
if err != nil {
|
||||
logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER_REDIRECT value in environment variable")
|
||||
}
|
||||
|
||||
globalFSOSync, err = config.ParseBool(env.Get(config.EnvFSOSync, config.EnableOff))
|
||||
if err != nil {
|
||||
logger.Fatal(config.ErrInvalidFSOSyncValue(err), "Invalid MINIO_FS_OSYNC value in environment variable")
|
||||
|
||||
@@ -276,7 +276,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
|
||||
getCert = globalTLSCerts.GetCertificate
|
||||
}
|
||||
|
||||
httpServer := xhttp.NewServer([]string{globalCLIContext.Addr},
|
||||
httpServer := xhttp.NewServer([]string{globalMinioAddr},
|
||||
criticalErrorHandler{corsHandler(router)}, getCert)
|
||||
httpServer.BaseContext = func(listener net.Listener) context.Context {
|
||||
return GlobalContext
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
// Prints the formatted startup message.
|
||||
func printGatewayStartupMessage(apiEndPoints []string, backendType string) {
|
||||
strippedAPIEndpoints := stripStandardPorts(apiEndPoints)
|
||||
strippedAPIEndpoints := stripStandardPorts(apiEndPoints, globalMinioHost)
|
||||
// If cache layer is enabled, print cache capacity.
|
||||
cacheAPI := newCachedObjectLayerFn()
|
||||
if cacheAPI != nil {
|
||||
@@ -65,7 +65,7 @@ func printGatewayCommonMsg(apiEndpoints []string) {
|
||||
printEventNotifiers()
|
||||
|
||||
if globalBrowserEnabled {
|
||||
consoleEndpointStr := strings.Join(stripStandardPorts(getConsoleEndpoints()), " ")
|
||||
consoleEndpointStr := strings.Join(stripStandardPorts(getConsoleEndpoints(), globalMinioConsoleHost), " ")
|
||||
logStartupMessage(color.Blue("\nConsole: ") + color.Bold(fmt.Sprintf("%s ", consoleEndpointStr)))
|
||||
if color.IsTerminal() && !globalCLIContext.Anonymous {
|
||||
logStartupMessage(color.Blue("RootUser: ") + color.Bold(fmt.Sprintf("%s ", cred.AccessKey)))
|
||||
|
||||
@@ -161,7 +161,7 @@ func guessIsBrowserReq(r *http.Request) bool {
|
||||
func setBrowserRedirectHandler(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Re-direction is handled specifically for browser requests.
|
||||
if guessIsBrowserReq(r) {
|
||||
if guessIsBrowserReq(r) && globalBrowserRedirect {
|
||||
// Fetch the redirect location if any.
|
||||
u := getRedirectLocation(r)
|
||||
if u != nil {
|
||||
|
||||
@@ -118,8 +118,6 @@ const (
|
||||
var globalCLIContext = struct {
|
||||
JSON, Quiet bool
|
||||
Anonymous bool
|
||||
Addr string
|
||||
ConsoleAddr string
|
||||
StrictS3Compat bool
|
||||
}{}
|
||||
|
||||
@@ -139,6 +137,9 @@ var (
|
||||
// This flag is set to 'true' by default
|
||||
globalBrowserEnabled = true
|
||||
|
||||
// This flag is set to 'true' by default.
|
||||
globalBrowserRedirect = true
|
||||
|
||||
// This flag is set to 'true' when MINIO_UPDATE env is set to 'off'. Default is false.
|
||||
globalInplaceUpdateDisabled = false
|
||||
|
||||
@@ -146,8 +147,7 @@ var (
|
||||
globalServerRegion = globalMinioDefaultRegion
|
||||
|
||||
// MinIO local server address (in `host:port` format)
|
||||
globalMinioAddr = ""
|
||||
globalMinioConsoleAddr = ""
|
||||
globalMinioAddr = ""
|
||||
|
||||
// MinIO default port, can be changed through command line.
|
||||
globalMinioPort = GlobalMinioDefaultPort
|
||||
|
||||
@@ -156,9 +156,9 @@ func TestGetHostIP(t *testing.T) {
|
||||
|
||||
// Tests finalize api endpoints.
|
||||
func TestGetAPIEndpoints(t *testing.T) {
|
||||
host, port := globalMinioHost, globalMinioAddr
|
||||
host, port := globalMinioHost, globalMinioPort
|
||||
defer func() {
|
||||
globalMinioHost, globalMinioAddr = host, port
|
||||
globalMinioHost, globalMinioPort = host, port
|
||||
}()
|
||||
testCases := []struct {
|
||||
host, port string
|
||||
|
||||
@@ -123,7 +123,7 @@ func serverHandleCmdArgs(ctx *cli.Context) {
|
||||
// Handle common command args.
|
||||
handleCommonCmdArgs(ctx)
|
||||
|
||||
logger.FatalIf(CheckLocalServerAddr(globalCLIContext.Addr), "Unable to validate passed arguments")
|
||||
logger.FatalIf(CheckLocalServerAddr(globalMinioAddr), "Unable to validate passed arguments")
|
||||
|
||||
var err error
|
||||
var setupType SetupType
|
||||
@@ -144,7 +144,7 @@ func serverHandleCmdArgs(ctx *cli.Context) {
|
||||
// Register root CAs for remote ENVs
|
||||
env.RegisterGlobalCAs(globalRootCAs)
|
||||
|
||||
globalEndpoints, setupType, err = createServerEndpoints(globalCLIContext.Addr, serverCmdArgs(ctx)...)
|
||||
globalEndpoints, setupType, err = createServerEndpoints(globalMinioAddr, serverCmdArgs(ctx)...)
|
||||
logger.FatalIf(err, "Invalid command line arguments")
|
||||
|
||||
globalLocalNodeName = GetLocalPeer(globalEndpoints, globalMinioHost, globalMinioPort)
|
||||
@@ -595,11 +595,11 @@ func serverMain(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
go func() {
|
||||
<-globalOSSignalCh
|
||||
consoleSrv.Shutdown()
|
||||
logger.FatalIf(consoleSrv.Serve(), "Unable to initialize console server")
|
||||
}()
|
||||
|
||||
consoleSrv.Serve()
|
||||
<-globalOSSignalCh
|
||||
consoleSrv.Shutdown()
|
||||
} else {
|
||||
<-globalOSSignalCh
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func printStartupMessage(apiEndpoints []string, err error) {
|
||||
logStartupMessage(color.RedBold("Please use 'mc admin' commands to further investigate this issue"))
|
||||
}
|
||||
|
||||
strippedAPIEndpoints := stripStandardPorts(apiEndpoints)
|
||||
strippedAPIEndpoints := stripStandardPorts(apiEndpoints, globalMinioHost)
|
||||
// If cache layer is enabled, print cache capacity.
|
||||
cachedObjAPI := newCachedObjectLayerFn()
|
||||
if cachedObjAPI != nil {
|
||||
@@ -95,7 +95,7 @@ func isNotIPv4(host string) bool {
|
||||
// strip api endpoints list with standard ports such as
|
||||
// port "80" and "443" before displaying on the startup
|
||||
// banner. Returns a new list of API endpoints.
|
||||
func stripStandardPorts(apiEndpoints []string) (newAPIEndpoints []string) {
|
||||
func stripStandardPorts(apiEndpoints []string, host string) (newAPIEndpoints []string) {
|
||||
newAPIEndpoints = make([]string, len(apiEndpoints))
|
||||
// Check all API endpoints for standard ports and strip them.
|
||||
for i, apiEndpoint := range apiEndpoints {
|
||||
@@ -103,7 +103,7 @@ func stripStandardPorts(apiEndpoints []string) (newAPIEndpoints []string) {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if globalMinioHost == "" && isNotIPv4(u.Host) {
|
||||
if host == "" && isNotIPv4(u.Host) {
|
||||
// Skip all non-IPv4 endpoints when we bind to all interfaces.
|
||||
continue
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func printServerCommonMsg(apiEndpoints []string) {
|
||||
printEventNotifiers()
|
||||
|
||||
if globalBrowserEnabled {
|
||||
consoleEndpointStr := strings.Join(stripStandardPorts(getConsoleEndpoints()), " ")
|
||||
consoleEndpointStr := strings.Join(stripStandardPorts(getConsoleEndpoints(), globalMinioConsoleHost), " ")
|
||||
logStartupMessage(color.Blue("\nConsole: ") + color.Bold(fmt.Sprintf("%s ", consoleEndpointStr)))
|
||||
if color.IsTerminal() && !globalCLIContext.Anonymous {
|
||||
logStartupMessage(color.Blue("RootUser: ") + color.Bold(fmt.Sprintf("%s ", cred.AccessKey)))
|
||||
|
||||
@@ -50,20 +50,20 @@ func TestStorageInfoMsg(t *testing.T) {
|
||||
func TestStripStandardPorts(t *testing.T) {
|
||||
apiEndpoints := []string{"http://127.0.0.1:9000", "http://127.0.0.2:80", "https://127.0.0.3:443"}
|
||||
expectedAPIEndpoints := []string{"http://127.0.0.1:9000", "http://127.0.0.2", "https://127.0.0.3"}
|
||||
newAPIEndpoints := stripStandardPorts(apiEndpoints)
|
||||
newAPIEndpoints := stripStandardPorts(apiEndpoints, "")
|
||||
|
||||
if !reflect.DeepEqual(expectedAPIEndpoints, newAPIEndpoints) {
|
||||
t.Fatalf("Expected %#v, got %#v", expectedAPIEndpoints, newAPIEndpoints)
|
||||
}
|
||||
|
||||
apiEndpoints = []string{"http://%%%%%:9000"}
|
||||
newAPIEndpoints = stripStandardPorts(apiEndpoints)
|
||||
newAPIEndpoints = stripStandardPorts(apiEndpoints, "")
|
||||
if !reflect.DeepEqual([]string{""}, newAPIEndpoints) {
|
||||
t.Fatalf("Expected %#v, got %#v", apiEndpoints, newAPIEndpoints)
|
||||
}
|
||||
|
||||
apiEndpoints = []string{"http://127.0.0.1:443", "https://127.0.0.1:80"}
|
||||
newAPIEndpoints = stripStandardPorts(apiEndpoints)
|
||||
newAPIEndpoints = stripStandardPorts(apiEndpoints, "")
|
||||
if !reflect.DeepEqual(apiEndpoints, newAPIEndpoints) {
|
||||
t.Fatalf("Expected %#v, got %#v", apiEndpoints, newAPIEndpoints)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user