mirror of https://github.com/kubernetes/kops.git
Merge pull request #16229 from hakman/aws_skip_deleting_asg_instances
aws: Skip deleting ASG instances without volumes
This commit is contained in:
commit
0162f39aae
|
|
@ -356,8 +356,16 @@ func ListInstances(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Reso
|
|||
for _, instance := range reservation.Instances {
|
||||
id := aws.StringValue(instance.InstanceId)
|
||||
|
||||
managedByASG := false
|
||||
for _, tag := range instance.Tags {
|
||||
if fi.ValueOf(tag.Key) == "aws:autoscaling:groupName" {
|
||||
managedByASG = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if instance.State != nil {
|
||||
stateName := aws.StringValue(instance.State.Name)
|
||||
stateName := fi.ValueOf(instance.State.Name)
|
||||
switch stateName {
|
||||
case "terminated", "shutting-down":
|
||||
continue
|
||||
|
|
@ -384,11 +392,13 @@ func ListInstances(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Reso
|
|||
blocks = append(blocks, "subnet:"+aws.StringValue(instance.SubnetId))
|
||||
blocks = append(blocks, "vpc:"+aws.StringValue(instance.VpcId))
|
||||
|
||||
hasVolumes := false
|
||||
for _, volume := range instance.BlockDeviceMappings {
|
||||
if volume.Ebs == nil {
|
||||
if volume.Ebs == nil || fi.ValueOf(volume.Ebs.DeleteOnTermination) {
|
||||
continue
|
||||
}
|
||||
blocks = append(blocks, "volume:"+aws.StringValue(volume.Ebs.VolumeId))
|
||||
hasVolumes = true
|
||||
}
|
||||
for _, sg := range instance.SecurityGroups {
|
||||
blocks = append(blocks, "security-group:"+aws.StringValue(sg.GroupId))
|
||||
|
|
@ -396,8 +406,10 @@ func ListInstances(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Reso
|
|||
|
||||
resourceTracker.Blocks = blocks
|
||||
|
||||
resourceTrackers = append(resourceTrackers, resourceTracker)
|
||||
|
||||
// Track only instances not managed by ASG or with volumes
|
||||
if !managedByASG || hasVolumes {
|
||||
resourceTrackers = append(resourceTrackers, resourceTracker)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
|
|
|||
Loading…
Reference in New Issue