Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: JaySon-Huang <tshent@qq.com>
  • Loading branch information
JaySon-Huang committed Dec 8, 2020
1 parent 3fd4afe commit 9fd504c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/cluster/spec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
type Entry struct {
clusterName string
componentName string
host string
port int
instance Instance
}

currentEntries := []Entry{}
Expand All @@ -225,8 +225,8 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
existingEntries = append(existingEntries, Entry{
clusterName: name,
componentName: inst.ComponentName(),
host: inst.GetHost(),
port: port,
instance: inst,
})
}
if !uniqueHosts.Exist(inst.GetHost()) {
Expand All @@ -235,14 +235,14 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
Entry{
clusterName: name,
componentName: RoleMonitor,
host: inst.GetHost(),
port: nodeExporterPort,
instance: inst,
},
Entry{
clusterName: name,
componentName: RoleMonitor,
host: inst.GetHost(),
port: blackboxExporterPort,
instance: inst,
})
}
})
Expand All @@ -253,8 +253,8 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
for _, port := range inst.UsedPorts() {
currentEntries = append(currentEntries, Entry{
componentName: inst.ComponentName(),
host: inst.GetHost(),
port: port,
instance: inst,
})
}

Expand All @@ -267,32 +267,32 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
currentEntries = append(currentEntries,
Entry{
componentName: RoleMonitor,
host: inst.GetHost(),
port: mOpt.NodeExporterPort,
instance: inst,
},
Entry{
componentName: RoleMonitor,
host: inst.GetHost(),
port: mOpt.BlackboxExporterPort,
instance: inst,
})
}
})

for _, p1 := range currentEntries {
for _, p2 := range existingEntries {
if p1.host != p2.host {
if p1.instance.GetHost() != p2.instance.GetHost() {
continue
}

if p1.port == p2.port {
properties := map[string]string{
"ThisPort": strconv.Itoa(p1.port),
"ThisComponent": p1.componentName,
"ThisHost": p1.host,
"ThisHost": p1.instance.GetHost(),
"ExistCluster": p2.clusterName,
"ExistPort": strconv.Itoa(p2.port),
"ExistComponent": p2.componentName,
"ExistHost": p2.host,
"ExistHost": p2.instance.GetHost(),
}
zap.L().Info("Meet deploy port conflict", zap.Any("info", properties))
return errDeployPortConflict.New("Deploy port conflicts to an existing cluster").WithProperty(cliutil.SuggestionFromTemplate(`
Expand Down

0 comments on commit 9fd504c

Please sign in to comment.