Skip to content

Commit df6e412

Browse files
authored
Merge pull request #170 from YoungJinJung/feat/modify-remove-prev-asg-after-timeout
feat:modify remove previous asg after goployer timeout
2 parents 0db878d + ffe98e3 commit df6e412

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ S3_RELEASE_PATH ?= s3://$(RELEASE_BUCKET)/releases/$(VERSION)
2424
S3_RELEASE_LATEST ?= s3://$(RELEASE_BUCKET)/releases/latest
2525
S3_BLEEDING_EDGE_LATEST ?= s3://$(RELEASE_BUCKET)/edge/latest
2626
S3_EXPERIMENTAL_LATEST ?= s3://$(RELEASE_BUCKET)/experimental/latest
27-
VERSION = 2.1.3
27+
VERSION = 2.1.4
2828

2929
GCP_ONLY ?= false
3030
GCP_PROJECT ?= goployer

pkg/deployer/deployer.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

7374
type 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

pkg/deployer/deployer_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,28 @@ func TestDeployer_ValidateOption(t *testing.T) {
8888
t.Errorf("Invalid Override Spot Types Option: %s", validErr)
8989
}
9090
}
91+
92+
func TestDeployer_HealthCheckingStatus(t *testing.T) {
93+
deployer := Deployer{
94+
HealthCheckStatus: make(map[string]bool),
95+
StepStatus: map[int64]bool{constants.StepDeploy: true},
96+
Stack: schemas.Stack{
97+
Regions: []schemas.RegionConfig{
98+
{Region: "ap-northeast-2"},
99+
},
100+
},
101+
}
102+
103+
// Initially, health check status should be false or not set
104+
if status, exists := deployer.HealthCheckStatus["ap-northeast-2"]; exists && status {
105+
t.Error("HealthCheckStatus should not be true initially")
106+
}
107+
108+
// Simulate successful health check by setting the status
109+
deployer.HealthCheckStatus["ap-northeast-2"] = true
110+
111+
// Verify that the status is now true
112+
if !deployer.HealthCheckStatus["ap-northeast-2"] {
113+
t.Error("HealthCheckStatus should be true after successful health check")
114+
}
115+
}

pkg/sumdb/sum.golang.org/latest

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
go.sum database tree
2+
43279701
3+
Um2aeKGAneeDXP1z1W4ltGD2tkI7jyD5f7tdq71kyuY=
4+
5+
— sum.golang.org Az3grgUju0c9GRK4rchalgvdwabWuqx1vJc2cdPRk58Seb1AqAEpfwzNtdDPJzKRKzokjOdVXUxLdKQ5VmioyPvKHQo=

0 commit comments

Comments
 (0)