fix: --console-address when specified endpoints missing (#12534)

Additionally upgrade console dependency for reading
environment variables properly.
This commit is contained in:
Harshavardhana 2021-06-20 23:04:47 -07:00 committed by GitHub
parent e1870c7b7c
commit 8f1fe3b761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 87 additions and 53 deletions

View File

@ -64,27 +64,49 @@ func releaseTag(version string) string {
// commitID returns the abbreviated commit-id hash of the last commit.
func commitID() string {
// git log --format="%h" -n1
// git log --format="%H" -n1
var (
commit []byte
e error
err error
)
cmdName := "git"
cmdArgs := []string{"log", "--format=%H", "-n1"}
if commit, e = exec.Command(cmdName, cmdArgs...).Output(); e != nil {
fmt.Fprintln(os.Stderr, "Error generating git commit-id: ", e)
if commit, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil {
fmt.Fprintln(os.Stderr, "Error generating git commit-id: ", err)
os.Exit(1)
}
return strings.TrimSpace(string(commit))
}
func commitTime() time.Time {
// git log --format=%cD -n1
var (
commitUnix []byte
err error
)
cmdName := "git"
cmdArgs := []string{"log", "--format=%cI", "-n1"}
if commitUnix, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil {
fmt.Fprintln(os.Stderr, "Error generating git commit-time: ", err)
os.Exit(1)
}
t, err := time.Parse(time.RFC3339, strings.TrimSpace(string(commitUnix)))
if err != nil {
fmt.Fprintln(os.Stderr, "Error generating git commit-time: ", err)
os.Exit(1)
}
return t.UTC()
}
func main() {
var version string
if len(os.Args) > 1 {
version = os.Args[1]
} else {
version = time.Now().UTC().Format(time.RFC3339)
version = commitTime().Format(time.RFC3339)
}
fmt.Println(genLDFlags(version))

View File

@ -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")

View File

@ -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

View File

@ -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)))

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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)))

View File

@ -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)
}

2
go.mod
View File

@ -40,7 +40,7 @@ require (
github.com/lib/pq v1.9.0
github.com/miekg/dns v1.1.35
github.com/minio/cli v1.22.0
github.com/minio/console v0.7.5-0.20210617075056-13f9f6c848d0
github.com/minio/console v0.7.5-0.20210618230329-b10c4f51b1ef
github.com/minio/csvparser v1.0.0
github.com/minio/highwayhash v1.0.2
github.com/minio/kes v0.14.0

8
go.sum
View File

@ -995,8 +995,8 @@ github.com/minio/cli v1.22.0 h1:VTQm7lmXm3quxO917X3p+el1l0Ca5X3S4PM2ruUYO68=
github.com/minio/cli v1.22.0/go.mod h1:bYxnK0uS629N3Bq+AOZZ+6lwF77Sodk4+UL9vNuXhOY=
github.com/minio/colorjson v1.0.1 h1:+hvfP8C1iMB95AT+ZFDRE+Knn9QPd9lg0CRJY9DRpos=
github.com/minio/colorjson v1.0.1/go.mod h1:oPM3zQQY8Gz9NGtgvuBEjQ+gPZLKAGc7T+kjMlwtOgs=
github.com/minio/console v0.7.5-0.20210617075056-13f9f6c848d0 h1:LGfT0EluVLXwVLt2u6IqAaCdWhSHgdGf/qBFizQTy2c=
github.com/minio/console v0.7.5-0.20210617075056-13f9f6c848d0/go.mod h1:GpMSCi0f9OlIyIlOJ/ecAen6I37hls9+h07oGK+Al7M=
github.com/minio/console v0.7.5-0.20210618230329-b10c4f51b1ef h1:IBFH0AosfqM2t2u2tJlFhOjlsIPki8j1+svG3rK3/iw=
github.com/minio/console v0.7.5-0.20210618230329-b10c4f51b1ef/go.mod h1:cjSSiiqz5KogE22e8fvVLr4/ExRrWd5uTmGCqnT9uSw=
github.com/minio/csvparser v1.0.0 h1:xJEHcYK8ZAjeW4hNV9Zu30u+/2o4UyPnYgyjWp8b7ZU=
github.com/minio/csvparser v1.0.0/go.mod h1:lKXskSLzPgC5WQyzP7maKH7Sl1cqvANXo9YCto8zbtM=
github.com/minio/direct-csi v1.3.5-0.20210601185811-f7776f7961bf h1:wylCc/PdvdTIqYqVNEU9LJAZBanvfGY1TwTnjM3zQaA=
@ -1020,8 +1020,8 @@ github.com/minio/minio-go/v7 v7.0.10/go.mod h1:td4gW1ldOsj1PbSNS+WYK43j+P1XVhX/8
github.com/minio/minio-go/v7 v7.0.11-0.20210302210017-6ae69c73ce78/go.mod h1:mTh2uJuAbEqdhMVl6CMIIZLUeiMiWtJR4JB8/5g2skw=
github.com/minio/minio-go/v7 v7.0.11-0.20210517200026-f0518ca447d6 h1:GVR+UTvfe2r2YTYHWrA/yRF5nouMjJh3kwxNTZ8npso=
github.com/minio/minio-go/v7 v7.0.11-0.20210517200026-f0518ca447d6/go.mod h1:td4gW1ldOsj1PbSNS+WYK43j+P1XVhX/8W8awaYlBFo=
github.com/minio/operator v0.0.0-20210604224119-7e256f98cf90 h1:bomLALJicW0gLAkFHomuPbyjU0OxR0znctdALiIdAJ4=
github.com/minio/operator v0.0.0-20210604224119-7e256f98cf90/go.mod h1:8/mIXK+CFdL6VqyxRn1SwD+PEX0jsN8uqjoadaw/Np0=
github.com/minio/operator v0.0.0-20210616045941-65f31f5f78ae h1:GONmqbjCi/KTEc1CGujnS/m1qeJeghcQ8dUBLh19qQo=
github.com/minio/operator v0.0.0-20210616045941-65f31f5f78ae/go.mod h1:8/mIXK+CFdL6VqyxRn1SwD+PEX0jsN8uqjoadaw/Np0=
github.com/minio/operator/logsearchapi v0.0.0-20210604224119-7e256f98cf90 h1:Qu6j6oE7+QNuq7Kr2DLyVYq3fqMdqFd/T8NAeNp47og=
github.com/minio/operator/logsearchapi v0.0.0-20210604224119-7e256f98cf90/go.mod h1:R+38Pf3wfm+JMiyLPb/r8OMrBm0vK2hZgUT4y4aYoSY=
github.com/minio/parquet-go v1.0.0 h1:fcWsEvub04Nsl/4hiRBDWlbqd6jhacQieV07a+nhiIk=

View File

@ -29,13 +29,14 @@ const (
EnvRootUser = "MINIO_ROOT_USER"
EnvRootPassword = "MINIO_ROOT_PASSWORD"
EnvBrowser = "MINIO_BROWSER"
EnvDomain = "MINIO_DOMAIN"
EnvRegionName = "MINIO_REGION_NAME"
EnvPublicIPs = "MINIO_PUBLIC_IPS"
EnvFSOSync = "MINIO_FS_OSYNC"
EnvArgs = "MINIO_ARGS"
EnvDNSWebhook = "MINIO_DNS_WEBHOOK_ENDPOINT"
EnvBrowser = "MINIO_BROWSER"
EnvBrowserRedirect = "MINIO_BROWSER_REDIRECT"
EnvDomain = "MINIO_DOMAIN"
EnvRegionName = "MINIO_REGION_NAME"
EnvPublicIPs = "MINIO_PUBLIC_IPS"
EnvFSOSync = "MINIO_FS_OSYNC"
EnvArgs = "MINIO_ARGS"
EnvDNSWebhook = "MINIO_DNS_WEBHOOK_ENDPOINT"
EnvRootDiskThresholdSize = "MINIO_ROOTDISK_THRESHOLD_SIZE"