diff --git a/pkg/cliutil/prepare/prepare.go b/pkg/cliutil/prepare/prepare.go index a994bbb332..bd7acb2242 100644 --- a/pkg/cliutil/prepare/prepare.go +++ b/pkg/cliutil/prepare/prepare.go @@ -25,6 +25,7 @@ import ( "github.com/pingcap/tiup/pkg/cluster/spec" "github.com/pingcap/tiup/pkg/cluster/task" "github.com/pingcap/tiup/pkg/errutil" + "github.com/pingcap/tiup/pkg/set" "go.uber.org/zap" ) @@ -231,6 +232,9 @@ func CheckClusterPortConflict(clusterSpec *spec.SpecManager, clusterName string, } metadata.GetTopology().IterInstance(func(inst spec.Instance) { + uniqueHosts := set.NewStringSet() + nodeExporterPort := metadata.GetTopology().GetMonitoredOptions().NodeExporterPort + blackboxExporterPort := metadata.GetTopology().GetMonitoredOptions().BlackboxExporterPort for _, port := range inst.UsedPorts() { existingEntries = append(existingEntries, Entry{ clusterName: name, @@ -238,6 +242,20 @@ func CheckClusterPortConflict(clusterSpec *spec.SpecManager, clusterName string, port: port, }) } + if !uniqueHosts.Exist(inst.GetHost()) { + uniqueHosts.Insert(inst.GetHost()) + existingEntries = append(existingEntries, + Entry{ + clusterName: name, + instance: inst, + port: nodeExporterPort, + }, + Entry{ + clusterName: name, + instance: inst, + port: blackboxExporterPort, + }) + } }) } @@ -248,6 +266,20 @@ func CheckClusterPortConflict(clusterSpec *spec.SpecManager, clusterName string, port: port, }) } + + uniqueHosts := set.NewStringSet() + if !uniqueHosts.Exist(inst.GetHost()) { + uniqueHosts.Insert(inst.GetHost()) + currentEntries = append(currentEntries, + Entry{ + instance: inst, + port: topo.GetMonitoredOptions().NodeExporterPort, + }, + Entry{ + instance: inst, + port: topo.GetMonitoredOptions().BlackboxExporterPort, + }) + } }) for _, p1 := range currentEntries {