Skip to content

Commit

Permalink
优化腾讯自研云支持大批量手动上架节点-分批添加
Browse files Browse the repository at this point in the history
  • Loading branch information
dove0012 committed Nov 22, 2024
1 parent a9969ca commit 5dcfc57
Showing 1 changed file with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,49 +832,57 @@ func AddNodesToCluster(ctx context.Context, info *cloudprovider.CloudDependBasic
}

var (
resp *api.AddExistedInstanceRsp
result = &AddExistedInstanceResult{}
addInstanceReq *api.AddExistedInstanceReq
nodeIPs = make([]string, 0)
result = &AddExistedInstanceResult{}
)
for i := range nodeIDs {

for i, id := range nodeIDs {
var (
newNodeIDs = make([]string, 0)
nodeIPs = make([]string, 0)
resp *api.AddExistedInstanceRsp
addInstanceReq *api.AddExistedInstanceReq
)

if ip, ok := idToIP[nodeIDs[i]]; ok {
nodeIPs = append(nodeIPs, ip)
newNodeIDs = append(newNodeIDs, id)
}
}

// nodeGroup or nodeTemplate
if isNodeGroup {
addInstanceReq = GenerateNGAddExistedInstanceReq(info, nodeIDs, nodeIPs, passwd, operator, options)
} else {
addInstanceReq = GenerateNTAddExistedInstanceReq(info, nodeIDs, nodeIPs, passwd, operator, options)
}
if (i+1)%100 == 0 || i+1 == len(nodeIDs) {
// nodeGroup or nodeTemplate
if isNodeGroup {
addInstanceReq = GenerateNGAddExistedInstanceReq(info, newNodeIDs, nodeIPs, passwd, operator, options)
} else {
addInstanceReq = GenerateNTAddExistedInstanceReq(info, newNodeIDs, nodeIPs, passwd, operator, options)
}

blog.Infof("AddNodesToCluster[%s] AddExistedInstancesToCluster request[%+v]", taskID, *addInstanceReq)
blog.Infof("AddNodesToCluster[%s] AddExistedInstancesToCluster request[%+v]", taskID, *addInstanceReq)

err = retry.Do(func() error {
resp, err = tkeCli.AddExistedInstancesToCluster(addInstanceReq)
if err != nil {
return err
}
err = retry.Do(func() error {
resp, err = tkeCli.AddExistedInstancesToCluster(addInstanceReq)
if err != nil {
return err
}

return nil
}, retry.Attempts(3))
if err != nil {
blog.Errorf("AddNodesToCluster[%s] AddExistedInstancesToCluster failed: %v", taskID, err)
return nil, err
}
return nil
}, retry.Attempts(3))
if err != nil {
blog.Errorf("AddNodesToCluster[%s] AddExistedInstancesToCluster failed: %v", taskID, err)
return nil, err
}

if len(resp.SuccessInstanceIDs) > 0 {
result.SuccessNodes = resp.SuccessInstanceIDs
}
if len(resp.FailedInstanceIDs) > 0 || len(resp.TimeoutInstanceIDs) > 0 {
result.FailedNodes = append(result.FailedNodes, resp.TimeoutInstanceIDs...)
result.FailedNodes = append(result.FailedNodes, resp.FailedInstanceIDs...)
}
if len(resp.SuccessInstanceIDs) > 0 {
result.SuccessNodes = resp.SuccessInstanceIDs
}
if len(resp.FailedInstanceIDs) > 0 || len(resp.TimeoutInstanceIDs) > 0 {
result.FailedNodes = append(result.FailedNodes, resp.TimeoutInstanceIDs...)
result.FailedNodes = append(result.FailedNodes, resp.FailedInstanceIDs...)
}

blog.Infof("AddNodesToCluster[%s] AddExistedInstancesToCluster success[%v] failed[%v]"+
"reasons[%v]", taskID, result.SuccessNodes, result.FailedNodes, resp.FailedReasons)
blog.Infof("AddNodesToCluster[%s] AddExistedInstancesToCluster success[%v] failed[%v]"+
"reasons[%v]", taskID, result.SuccessNodes, result.FailedNodes, resp.FailedReasons)
}
}

cloudprovider.GetStorageModel().CreateTaskStepLogInfo(context.Background(), taskID, stepName,
fmt.Sprintf("success [%v] failed [%v]", result.SuccessNodes, result.FailedNodes))
Expand Down

0 comments on commit 5dcfc57

Please sign in to comment.