Skip to content

Commit 91c5796

Browse files
authored
Merge pull request kubernetes#3676 from wangshiqi308/pr_fix_scaledown_issue
fixed scaledown issue
2 parents 3d76c21 + d62598a commit 91c5796

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud_auto_scaling_group.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,25 @@ func (asg *AutoScalingGroup) IncreaseSize(delta int) error {
9494
func (asg *AutoScalingGroup) DeleteNodes(nodes []*apiv1.Node) error {
9595
instances, err := asg.cloudServiceManager.GetInstances(asg.groupID)
9696
if err != nil {
97-
klog.Warningf("failed to get nodes from group: %s, error: %v", asg.groupID, err)
97+
klog.Warningf("failed to get instances from group: %s, error: %v", asg.groupID, err)
9898
return err
9999
}
100100

101-
// TODO(RainbowMango): Check if all node in this group.
102-
// If one of the node is not belong to this group, just return error.
103-
104-
servers := make([]string, 0, len(instances))
101+
instanceIds := make([]string, 0, len(instances))
105102
for _, instance := range instances {
106-
servers = append(servers, instance.Id)
103+
for _, n := range nodes {
104+
if n.Spec.ProviderID == instance.Id {
105+
instanceIds = append(instanceIds, instance.Id)
106+
}
107+
}
107108
}
108109

109-
err = asg.cloudServiceManager.DeleteServers(servers)
110+
err = asg.cloudServiceManager.DeleteScalingInstances(asg.groupID, instanceIds)
110111
if err != nil {
111-
klog.Warningf("failed to delete nodes. error: %v", err)
112+
klog.Warningf("failed to delete scaling instances. error: %v", err)
112113
return err
113114
}
114115

115-
// TODO(RainbowMango): Wait for node group size updated.
116-
117116
return nil
118117
}
119118

cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud_service_manager.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type AutoScalingService interface {
6262
// IncreaseSizeInstance wait until instance number is updated.
6363
IncreaseSizeInstance(groupID string, delta int) error
6464

65+
// DeleteScalingInstances is used to delete instances from auto scaling group by instanceIDs.
66+
DeleteScalingInstances(groupID string, instanceIds []string) error
67+
6568
// Get default auto scaling group template
6669
getAsgTemplate(groupID string) (*asgTemplate, error)
6770

@@ -218,6 +221,29 @@ func (csm *cloudServiceManager) GetInstances(groupID string) ([]cloudprovider.In
218221
return instances, nil
219222
}
220223

224+
func (csm *cloudServiceManager) DeleteScalingInstances(groupID string, instanceIds []string) error {
225+
asClient := csm.getASClientFunc()
226+
227+
instanceDelete := "yes"
228+
opts := &huaweicloudsdkasmodel.UpdateScalingGroupInstanceRequest{
229+
ScalingGroupId: groupID,
230+
Body: &huaweicloudsdkasmodel.UpdateScalingGroupInstanceRequestBody{
231+
InstancesId: instanceIds,
232+
InstanceDelete: &instanceDelete,
233+
Action: huaweicloudsdkasmodel.GetUpdateScalingGroupInstanceRequestBodyActionEnum().REMOVE,
234+
},
235+
}
236+
237+
_, err := asClient.UpdateScalingGroupInstance(opts)
238+
239+
if err != nil {
240+
klog.Errorf("failed to delete scaling instances. group: %s, error: %v", groupID, err)
241+
return err
242+
}
243+
244+
return nil
245+
}
246+
221247
// IncreaseSizeInstance increases a scaling group's instance size.
222248
// The workflow works as follows:
223249
// 1. create scaling policy with scheduled type.

0 commit comments

Comments
 (0)