Skip to content

Commit

Permalink
fix(alibaba): fix start and stop instance status debug info
Browse files Browse the repository at this point in the history
Signed-off-by: NewGr8Player <273221594@qq.com>
  • Loading branch information
NewGr8Player authored and rancher-sy-bot committed Oct 14, 2020
1 parent 8d04469 commit b667789
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,6 @@ func (p *Alibaba) startCluster() error {
}
}

for _, masterNode := range p.MasterNodes {
p.m.Store(masterNode.InstanceID, masterNode)
}
for _, workerNode := range p.WorkerNodes {
p.m.Store(workerNode.InstanceID, workerNode)
}

// wait ecs instances to be running status.
if err = p.getInstanceStatus(alibaba.StatusRunning); err != nil {
return err
Expand Down Expand Up @@ -644,13 +637,6 @@ func (p *Alibaba) stopCluster(f bool) error {
}
}

for _, masterNode := range p.MasterNodes {
p.m.Store(masterNode.InstanceID, masterNode)
}
for _, workerNode := range p.WorkerNodes {
p.m.Store(workerNode.InstanceID, workerNode)
}

// wait ecs instances to be stopped status.
if err = p.getInstanceStatus(alibaba.StatusStopped); err != nil {
return err
Expand Down Expand Up @@ -969,17 +955,36 @@ func (p *Alibaba) startAndStopCheck(aimStatus string) error {
return err
}
if response.IsSuccess() && len(response.Instances.Instance) > 0 {
masterCnt := 0
unexpectedStatusCnt := 0
for _, instance := range response.Instances.Instance {
if instance.Status != aimStatus {
unexpectedStatusCnt++
p.logger.Warnf("[%s] instance [%s] status is %s, but it is expected to be %s\n",
p.GetProviderName(), instance.InstanceId, instance.Status, aimStatus)
}
master := false
for _, tag := range instance.Tags.Tag {
if strings.EqualFold(tag.TagKey, "master") && strings.EqualFold(tag.TagValue, "true") {
master = true
masterCnt++
break
}
}
p.m.Store(instance.InstanceId, types.Node{
Master: master,
InstanceID: instance.InstanceId,
InstanceStatus: instance.Status,
InternalIPAddress: instance.InnerIpAddress.IpAddress,
PublicIPAddress: []string{instance.EipAddress.IpAddress},
EipAllocationIds: []string{instance.EipAddress.AllocationId},
})
}
if unexpectedStatusCnt > 0 {
return fmt.Errorf("[%s] status of %d instance(s) is unexpected", p.GetProviderName(), unexpectedStatusCnt)
}
p.Master = strconv.Itoa(masterCnt)
p.Worker = strconv.Itoa(len(response.Instances.Instance) - masterCnt)
return nil
}
return fmt.Errorf("[%s] unable to confirm the current status of instance(s)", p.GetProviderName())
Expand Down

0 comments on commit b667789

Please sign in to comment.