mirror of https://github.com/kubernetes/kops.git
aws: Terminate ASG instances in batches of 100 instances
This commit is contained in:
parent
baf021b484
commit
d71879f023
|
|
@ -318,24 +318,28 @@ func matchesIAMTags(tags map[string]string, actual []*iam.Tag) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
//type DeletableResource interface {
|
func DeleteInstances(cloud fi.Cloud, t []*resources.Resource) error {
|
||||||
// Delete(cloud fi.Cloud) error
|
|
||||||
//}
|
|
||||||
|
|
||||||
func DeleteInstance(cloud fi.Cloud, t *resources.Resource) error {
|
|
||||||
c := cloud.(awsup.AWSCloud)
|
c := cloud.(awsup.AWSCloud)
|
||||||
|
|
||||||
id := t.ID
|
var ids []*string
|
||||||
klog.V(2).Infof("Deleting EC2 instance %q", id)
|
for i, instance := range t {
|
||||||
request := &ec2.TerminateInstancesInput{
|
ids = append(ids, &instance.ID)
|
||||||
InstanceIds: []*string{&id},
|
if len(ids) < 100 && i < len(t)-1 {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
klog.Infof("Terminating %d EC2 instances", len(ids))
|
||||||
|
request := &ec2.TerminateInstancesInput{
|
||||||
|
InstanceIds: ids,
|
||||||
|
}
|
||||||
|
ids = []*string{}
|
||||||
_, err := c.EC2().TerminateInstances(request)
|
_, err := c.EC2().TerminateInstances(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if awsup.AWSErrorCode(err) == "InvalidInstanceID.NotFound" {
|
if awsup.AWSErrorCode(err) == "InvalidInstanceID.NotFound" {
|
||||||
klog.V(2).Infof("Got InvalidInstanceID.NotFound error deleting instance %q; will treat as already-deleted", id)
|
klog.V(2).Infof("Got InvalidInstanceID.NotFound error terminating instances; will treat as already terminated")
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("error deleting Instance %q: %v", id, err)
|
return fmt.Errorf("error terminating instances: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -363,7 +367,8 @@ func ListInstances(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Reso
|
||||||
Name: FindName(instance.Tags),
|
Name: FindName(instance.Tags),
|
||||||
ID: id,
|
ID: id,
|
||||||
Type: ec2.ResourceTypeInstance,
|
Type: ec2.ResourceTypeInstance,
|
||||||
Deleter: DeleteInstance,
|
GroupDeleter: DeleteInstances,
|
||||||
|
GroupKey: fi.ValueOf(instance.SubnetId),
|
||||||
Dumper: DumpInstance,
|
Dumper: DumpInstance,
|
||||||
Obj: instance,
|
Obj: instance,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue