@@ -68,6 +68,7 @@ type Deployer struct {
6868 Collector collector.Collector
6969 StepStatus map [int64 ]bool
7070 DeploymentFlag map [string ]string
71+ HealthCheckStatus map [string ]bool
7172}
7273
7374type APIAttacker struct {
@@ -99,6 +100,7 @@ func InitDeploymentConfiguration(h *helper.DeployerHelper, awsClients []aws.Clie
99100 Collector : h .Collector ,
100101 AppliedCapacity : nil ,
101102 StepStatus : helper .InitStartStatus (),
103+ HealthCheckStatus : map [string ]bool {},
102104 }
103105}
104106
@@ -596,6 +598,7 @@ func (d *Deployer) Deploy(config schemas.Config, region schemas.RegionConfig) er
596598 launchTemplateTags := d .GenerateLaunchTemplateTags (newAsgName , d .Stack .Stack , config .ExtraTags , region .Region )
597599
598600 blockDevices := client .EC2Service .MakeLaunchTemplateBlockDeviceMappings (d .Stack .BlockDevices )
601+
599602 d .Logger .Debugf ("additional blokcDevice information %s" , blockDevices )
600603
601604 ebsOptimized := d .Stack .EbsOptimized
@@ -615,7 +618,7 @@ func (d *Deployer) Deploy(config schemas.Config, region schemas.RegionConfig) er
615618 if len (securityGroups ) > 0 && (region .PrimaryENI != nil || len (region .SecondaryENIs ) > 0 ) {
616619 return fmt .Errorf ("cannot use both launch template security groups and ENI security groups at the same time" )
617620 }
618-
621+ d . Logger . Debugf ( "Block Device Len %d" , len ( blockDevices ))
619622 err = client .EC2Service .CreateNewLaunchTemplate (
620623 launchTemplateName ,
621624 ami ,
@@ -1021,12 +1024,15 @@ func (d *Deployer) HealthChecking(config schemas.Config) (bool, error) {
10211024 }
10221025
10231026 if isHealthy {
1027+ d .HealthCheckStatus [region .Region ] = true
10241028 if d .Collector .MetricConfig .Enabled {
10251029 if err := d .Collector .UpdateStatus (* asg .AutoScalingGroupName , "deployed" , nil ); err != nil {
10261030 d .Logger .Errorf ("Update status Error, %s : %s" , err .Error (), * asg .AutoScalingGroupName )
10271031 }
10281032 }
10291033 finished = append (finished , region .Region )
1034+ } else {
1035+ d .HealthCheckStatus [region .Region ] = false
10301036 }
10311037 }
10321038
@@ -1147,6 +1153,13 @@ func (d *Deployer) CleanPreviousAutoScalingGroup(config schemas.Config) error {
11471153 continue
11481154 }
11491155
1156+ // Check if health check passed for this region
1157+ if healthStatus , exists := d .HealthCheckStatus [region .Region ]; exists && ! healthStatus {
1158+ d .Logger .Warnf ("[%s] Skipping cleanup of previous ASGs due to failed health check" , region .Region )
1159+ d .Slack .SendSimpleMessage (fmt .Sprintf (":warning: Skipping cleanup of previous ASGs in %s due to failed health check" , region .Region ))
1160+ continue
1161+ }
1162+
11501163 d .Logger .Infof ("[%s]The number of previous versions to delete is %d" , region .Region , len (d .PrevAsgs [region .Region ]))
11511164
11521165 // select client
0 commit comments