Skip to content

Commit

Permalink
fix(alibaba): fix multiple bugs
Browse files Browse the repository at this point in the history
1. null pointer exception on create logic
2. do not execute rollback when ids is empty

Signed-off-by: Jason-ZW <zhenyang@rancher.com>
  • Loading branch information
rancher-sy-bot committed Aug 28, 2020
1 parent 061b039 commit ff73b92
Showing 1 changed file with 46 additions and 42 deletions.
88 changes: 46 additions & 42 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p *Alibaba) CreateK3sCluster(ssh *types.SSH) error {
s.Start()
defer func() {
s.Stop()
if p.UI != "none" {
if p.UI != "none" && len(p.Status.MasterNodes) > 0 {
fmt.Printf("K3s UI %s URL: https://%s:8999\n", p.UI, p.Status.MasterNodes[0].PublicIPAddress[0])
fmt.Printf("Use `autok3s kubectl get pods -A` get UI status\n")
}
Expand Down Expand Up @@ -186,29 +186,31 @@ func (p *Alibaba) Rollback() error {
return true
})

request := ecs.CreateDeleteInstancesRequest()
request.Scheme = "https"
request.InstanceId = &ids
request.Force = requests.NewBoolean(true)
if len(ids) > 0 {
request := ecs.CreateDeleteInstancesRequest()
request.Scheme = "https"
request.InstanceId = &ids
request.Force = requests.NewBoolean(true)

wait.ErrWaitTimeout = fmt.Errorf("[%s] calling rollback error, please remove the cloud provider instances manually. region=%s, "+
"instanceName=%s, message=the maximum number of attempts reached\n", p.GetProviderName(), p.Region, ids)
wait.ErrWaitTimeout = fmt.Errorf("[%s] calling rollback error, please remove the cloud provider instances manually. region=%s, "+
"instanceName=%s, message=the maximum number of attempts reached\n", p.GetProviderName(), p.Region, ids)

// retry 5 times, total 120 seconds.
backoff := wait.Backoff{
Duration: 30 * time.Second,
Factor: 1,
Steps: 5,
}
// retry 5 times, total 120 seconds.
backoff := wait.Backoff{
Duration: 30 * time.Second,
Factor: 1,
Steps: 5,
}

if err := wait.ExponentialBackoff(backoff, func() (bool, error) {
response, err := p.c.DeleteInstances(request)
if err != nil || !response.IsSuccess() {
return false, nil
if err := wait.ExponentialBackoff(backoff, func() (bool, error) {
response, err := p.c.DeleteInstances(request)
if err != nil || !response.IsSuccess() {
return false, nil
}
return true, nil
}); err != nil {
return err
}
return true, nil
}); err != nil {
return err
}

return nil
Expand Down Expand Up @@ -273,34 +275,36 @@ func (p *Alibaba) getInstanceStatus() error {
return true
})

request := ecs.CreateDescribeInstanceStatusRequest()
request.Scheme = "https"
request.InstanceId = &ids
if len(ids) > 0 {
request := ecs.CreateDescribeInstanceStatusRequest()
request.Scheme = "https"
request.InstanceId = &ids

wait.ErrWaitTimeout = fmt.Errorf("[%s] calling getInstanceStatus error. region=%s, "+"instanceName=%s, message=not running status\n",
p.GetProviderName(), p.Region, ids)
wait.ErrWaitTimeout = fmt.Errorf("[%s] calling getInstanceStatus error. region=%s, "+"instanceName=%s, message=not running status\n",
p.GetProviderName(), p.Region, ids)

if err := wait.ExponentialBackoff(common.Backoff, func() (bool, error) {
response, err := p.c.DescribeInstanceStatus(request)
if err != nil || !response.IsSuccess() || len(response.InstanceStatuses.InstanceStatus) <= 0 {
return false, nil
}
if err := wait.ExponentialBackoff(common.Backoff, func() (bool, error) {
response, err := p.c.DescribeInstanceStatus(request)
if err != nil || !response.IsSuccess() || len(response.InstanceStatuses.InstanceStatus) <= 0 {
return false, nil
}

for _, status := range response.InstanceStatuses.InstanceStatus {
if status.Status == alibaba.StatusRunning {
if value, ok := p.m.Load(status.InstanceId); ok {
v := value.(types.Node)
v.InstanceStatus = alibaba.StatusRunning
p.m.Store(status.InstanceId, v)
for _, status := range response.InstanceStatuses.InstanceStatus {
if status.Status == alibaba.StatusRunning {
if value, ok := p.m.Load(status.InstanceId); ok {
v := value.(types.Node)
v.InstanceStatus = alibaba.StatusRunning
p.m.Store(status.InstanceId, v)
}
} else {
return false, nil
}
} else {
return false, nil
}
}

return true, nil
}); err != nil {
return err
return true, nil
}); err != nil {
return err
}
}

p.m.Range(func(key, value interface{}) bool {
Expand Down

0 comments on commit ff73b92

Please # to comment.