Skip to content

Commit

Permalink
feat: spider授权跳过部分不可用节点 TencentBlueKing#7323
Browse files Browse the repository at this point in the history
  • Loading branch information
fanfanyangyang authored and iSecloud committed Oct 14, 2024
1 parent 116bf5a commit c46de01
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions dbm-services/mysql/db-priv/service/add_priv.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,18 @@ func (m *PrivTaskPara) AddPriv(jsonPara string, ticket string) error {
runningNum = runningNum + 1
}
}
for _, proxy := range instance.Proxies {
if runningNum > 0 && proxy.Status != running {
slog.Warn(baseInfo, "proxy instance not running state, skipped", fmt.Sprintf("%s:%d", proxy.IP, proxy.Port))
continue
}
err = ImportProxyPrivilege(proxy, proxySQL, instance.BkCloudId)
if err != nil {
errMsgInner = append(errMsgInner, err.Error())
if runningNum == 0 {
errMsgInner = append(errMsgInner, "no running state proxy")
} else {
for _, proxy := range instance.Proxies {
if proxy.Status != running {
slog.Warn(baseInfo, "proxy instance not running state, skipped", fmt.Sprintf("%s:%d", proxy.IP, proxy.Port))
continue
}
err = ImportProxyPrivilege(proxy, proxySQL, instance.BkCloudId)
if err != nil {
errMsgInner = append(errMsgInner, err.Error())
}
}
}
}
Expand All @@ -204,13 +208,27 @@ func (m *PrivTaskPara) AddPriv(jsonPara string, ticket string) error {
} else {
errMsgInner = append(errMsgInner, fmt.Sprintf("wrong entry role %s", instance.EntryRole))
}
var runningNum int
for _, spider := range spiders {
address = fmt.Sprintf("%s:%d", spider.IP, spider.Port)
err = ImportBackendPrivilege(account, accountRule, address, proxyIPs, m.SourceIPs,
instance.ClusterType, tendbhaMasterDomain, instance.BkCloudId, false,
tendbhaPaddingProxy)
if err != nil {
errMsgInner = append(errMsgInner, err.Error())
if spider.Status == running {
runningNum = runningNum + 1
}
}
if runningNum == 0 {
errMsgInner = append(errMsgInner, "no running state spider")
} else {
for _, spider := range spiders {
address = fmt.Sprintf("%s:%d", spider.IP, spider.Port)
if spider.Status != running {
slog.Warn(baseInfo, "spider instance not running state, skipped", address)
continue
}
err = ImportBackendPrivilege(account, accountRule, address, proxyIPs, m.SourceIPs,
instance.ClusterType, tendbhaMasterDomain, instance.BkCloudId, false,
tendbhaPaddingProxy)
if err != nil {
errMsgInner = append(errMsgInner, err.Error())
}
}
}
if len(errMsgInner) > 0 {
Expand Down

0 comments on commit c46de01

Please sign in to comment.