From 3bf3ba842dedcc2a378d5b0b131f8a8e7c847352 Mon Sep 17 00:00:00 2001 From: 9547 Date: Tue, 8 Dec 2020 12:17:58 +0800 Subject: [PATCH] Fix/playground noset localhost (#973) * typo(cluster): set TiSpark's JDK msg more striking * fix(playground): don't modify instances's listenaddr * feat(playground/instance): use Host directly * Revert "fix(playground): don't modify instances's listenaddr" This reverts commit c124ad2cce1f24d9b3c68bb59f89e3f5d16efcf0. * Revert "feat(playground/instance): use Host directly" This reverts commit 83937f2d817b41e73fe7aa4164bbd7103a67fb60. * feat(playground): use the primary interface's addr instead of localhost if 0.0.0.0 Co-authored-by: SIGSEGV --- components/playground/instance/instance.go | 11 +++++++++++ pkg/cluster/manager.go | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/components/playground/instance/instance.go b/components/playground/instance/instance.go index d1be56f1da..33878b4cff 100644 --- a/components/playground/instance/instance.go +++ b/components/playground/instance/instance.go @@ -16,6 +16,7 @@ package instance import ( "context" "fmt" + "net" pkgver "github.com/pingcap/tiup/pkg/repository/version" ) @@ -74,6 +75,16 @@ func CompVersion(comp string, version pkgver.Version) string { func advertiseHost(listen string) string { if listen == "0.0.0.0" { + addrs, err := net.InterfaceAddrs() + if err != nil || len(addrs) == 0 { + return "localhost" + } + + for _, addr := range addrs { + if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() && ip.IP.To4() != nil { + return ip.IP.To4().String() + } + } return "localhost" } diff --git a/pkg/cluster/manager.go b/pkg/cluster/manager.go index 3405fb87dc..d7b82846bb 100644 --- a/pkg/cluster/manager.go +++ b/pkg/cluster/manager.go @@ -1869,8 +1869,11 @@ func (m *Manager) confirmTopology(clusterName, version string, topo spec.Topolog if spec, ok := topo.(*spec.Specification); ok { if len(spec.TiSparkMasters) > 0 || len(spec.TiSparkWorkers) > 0 { - log.Warnf("There are TiSpark nodes defined in the topology, please note that you'll need to manually install Java Runtime Environment (JRE) 8 on the host, other wise the TiSpark nodes will fail to start.") - log.Warnf("You may read the OpenJDK doc for a reference: https://openjdk.java.net/install/") + cyan := color.New(color.FgCyan, color.Bold) + msg := cyan.Sprint(`There are TiSpark nodes defined in the topology, please note that you'll need to manually install Java Runtime Environment (JRE) 8 on the host, otherwise the TiSpark nodes will fail to start. +You may read the OpenJDK doc for a reference: https://openjdk.java.net/install/ + `) + log.Warnf(msg) } }