deitch / aws-asg-roller

Manage rolling upgrades for AWS autoscaling groups
Apache License 2.0
57 stars 17 forks source link

Fix panic by treat instances without configuration name as old instan… #13

Closed nauxliu closed 5 years ago

nauxliu commented 5 years ago

I am using Terraform to manage ASG. If there are any changes, it will delete the old Launch Configuration and create a new one, so the old instances' LaunchConfigurationName will be nil.

Error logs:

2019/04/30 02:03:22 Sleeping 30 seconds
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1227faf]

goroutine 1 [running]:
main.groupInstances(0xc0003e88c0, 0xc0000f1620, 0xc000043b00, 0x2c, 0xc0000f18e8, 0xc00000e4d8, 0x1)
    /home/travis/gopath/src/github.com/deitch/aws-asg-roller/roller.go:179 +0xef
main.adjust(0xc0003ac310, 0x1, 0x1, 0x1839260, 0xc00000e6c8, 0x1830a20, 0xc00000e6b8, 0x17ccbe0, 0xc0003ad700, 0xc0000f1e88, ...)
    /home/travis/gopath/src/github.com/deitch/aws-asg-roller/roller.go:29 +0x27e
main.main()
    /home/travis/gopath/src/github.com/deitch/aws-asg-roller/main.go:42 +0x39c

The output of aws autoscaling describe-auto-scaling-instances

$ aws autoscaling describe-auto-scaling-instances
{
    "AutoScalingInstances": [
        {
            "InstanceId": "i-XXXXX",
            "AutoScalingGroupName": "AutoScalingGroupName",
            "AvailabilityZone": "us-east-2a",
            "LifecycleState": "InService",
            "HealthStatus": "HEALTHY",
            "ProtectedFromScaleIn": false
        },
        {
            "InstanceId": "i-XXXXX",
            "AutoScalingGroupName": "AutoScalingGroupName",
            "AvailabilityZone": "us-east-2a",
            "LifecycleState": "InService",
            "HealthStatus": "HEALTHY",
            "ProtectedFromScaleIn": false
        },
        {
            "InstanceId": "i-XXXXX",
            "AutoScalingGroupName": "AutoScalingGroupName",
            "AvailabilityZone": "us-east-2a",
            "LifecycleState": "InService",
            "HealthStatus": "HEALTHY",
            "LaunchConfigurationName": "AutoScalingGroupName20190429091314512400000001",
            "ProtectedFromScaleIn": false
        }
    ]
}
deitch commented 5 years ago

Thanks @nauxliu ' see #11 which resolves the exact same thing :-)