From 56bc3c44d3430e7a1bba08cc80ff15d4a5f249ec Mon Sep 17 00:00:00 2001 From: Efe Karakus Date: Tue, 20 Sep 2022 13:09:39 -0700 Subject: [PATCH] fix: allow unseting GracePeriod when default value is provided Sort of fixes #4011 --- .../cloudformation/stack/backend_svc_test.go | 4 ++-- .../cloudformation/stack/lb_web_svc_test.go | 2 +- .../deploy/cloudformation/stack/transformers.go | 4 ++-- .../cloudformation/stack/transformers_test.go | 16 ++++++++-------- .../templates/workloads/services/backend/cf.yml | 2 ++ .../templates/workloads/services/lb-web/cf.yml | 2 ++ internal/pkg/template/workload.go | 7 +++++-- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/internal/pkg/deploy/cloudformation/stack/backend_svc_test.go b/internal/pkg/deploy/cloudformation/stack/backend_svc_test.go index 6feaea08c0b..ac58ce9c237 100644 --- a/internal/pkg/deploy/cloudformation/stack/backend_svc_test.go +++ b/internal/pkg/deploy/cloudformation/stack/backend_svc_test.go @@ -275,7 +275,7 @@ Outputs: }, HTTPHealthCheck: template.HTTPHealthCheckOpts{ HealthCheckPath: manifest.DefaultHealthCheckPath, - GracePeriod: aws.Int64(manifest.DefaultHealthCheckGracePeriod), + GracePeriod: manifest.DefaultHealthCheckGracePeriod, }, DeregistrationDelay: aws.Int64(60), // defaults to 60 CustomResources: map[string]template.S3ObjectLocation{ @@ -447,7 +447,7 @@ Outputs: UnhealthyThreshold: aws.Int64(63), Timeout: aws.Int64(62), Interval: aws.Int64(61), - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, HostedZoneAliases: make(template.AliasesForHostedZone), DeregistrationDelay: aws.Int64(59), diff --git a/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go b/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go index cc3bdc61ad1..2602ea452d1 100644 --- a/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go +++ b/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go @@ -252,7 +252,7 @@ Outputs: WorkloadType: manifest.LoadBalancedWebServiceType, HTTPHealthCheck: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, HostedZoneAliases: template.AliasesForHostedZone{ "mockHostedZone": []string{"mockAlias"}, diff --git a/internal/pkg/deploy/cloudformation/stack/transformers.go b/internal/pkg/deploy/cloudformation/stack/transformers.go index 1120f5952fb..d9783b62cf5 100644 --- a/internal/pkg/deploy/cloudformation/stack/transformers.go +++ b/internal/pkg/deploy/cloudformation/stack/transformers.go @@ -321,7 +321,7 @@ func convertHTTPHealthCheck(hc *manifest.HealthCheckArgsOrString) template.HTTPH HealthCheckPath: manifest.DefaultHealthCheckPath, HealthyThreshold: hc.HealthCheckArgs.HealthyThreshold, UnhealthyThreshold: hc.HealthCheckArgs.UnhealthyThreshold, - GracePeriod: aws.Int64(manifest.DefaultHealthCheckGracePeriod), + GracePeriod: manifest.DefaultHealthCheckGracePeriod, } if hc.HealthCheckArgs.Path != nil { opts.HealthCheckPath = *hc.HealthCheckArgs.Path @@ -341,7 +341,7 @@ func convertHTTPHealthCheck(hc *manifest.HealthCheckArgsOrString) template.HTTPH opts.Timeout = aws.Int64(int64(hc.HealthCheckArgs.Timeout.Seconds())) } if hc.HealthCheckArgs.GracePeriod != nil { - opts.GracePeriod = aws.Int64(int64(hc.HealthCheckArgs.GracePeriod.Seconds())) + opts.GracePeriod = int64(hc.HealthCheckArgs.GracePeriod.Seconds()) } return opts } diff --git a/internal/pkg/deploy/cloudformation/stack/transformers_test.go b/internal/pkg/deploy/cloudformation/stack/transformers_test.go index ebfa5bc6f12..cdaa5ed7e84 100644 --- a/internal/pkg/deploy/cloudformation/stack/transformers_test.go +++ b/internal/pkg/deploy/cloudformation/stack/transformers_test.go @@ -660,7 +660,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { wantedOpts: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, }, "just HealthyThreshold": { @@ -675,7 +675,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { wantedOpts: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", HealthyThreshold: aws.Int64(5), - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, }, "just UnhealthyThreshold": { @@ -690,7 +690,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { wantedOpts: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", UnhealthyThreshold: aws.Int64(5), - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, }, "just Interval": { @@ -705,7 +705,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { wantedOpts: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", Interval: aws.Int64(15), - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, }, "just Timeout": { @@ -720,7 +720,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { wantedOpts: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", Timeout: aws.Int64(15), - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, }, "just SuccessCodes": { @@ -735,7 +735,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { wantedOpts: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", SuccessCodes: "200,301", - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, }, "just Port": { @@ -745,7 +745,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { wantedOpts: template.HTTPHealthCheckOpts{ HealthCheckPath: "/", Port: "8000", - GracePeriod: aws.Int64(60), + GracePeriod: 60, }, }, "all values changed in manifest": { @@ -766,7 +766,7 @@ func Test_convertHTTPHealthCheck(t *testing.T) { UnhealthyThreshold: aws.Int64(3), Interval: aws.Int64(60), Timeout: aws.Int64(60), - GracePeriod: aws.Int64(15), + GracePeriod: 15, }, }, } diff --git a/internal/pkg/template/templates/workloads/services/backend/cf.yml b/internal/pkg/template/templates/workloads/services/backend/cf.yml index a1daa99e6ea..84e43d939c6 100644 --- a/internal/pkg/template/templates/workloads/services/backend/cf.yml +++ b/internal/pkg/template/templates/workloads/services/backend/cf.yml @@ -104,7 +104,9 @@ Resources: {{- "\n"}}{{ include "service-base-properties" . | indent 6 }} ServiceRegistries: !If [ExposePort, [{RegistryArn: !GetAtt DiscoveryService.Arn, Port: !Ref ContainerPort}], !Ref "AWS::NoValue"] {{- if .ALBEnabled}} + {{- if .HTTPHealthCheck.GracePeriod }} HealthCheckGracePeriodSeconds: {{.HTTPHealthCheck.GracePeriod}} + {{- end }} LoadBalancers: - ContainerName: !Ref TargetContainer ContainerPort: !Ref TargetPort diff --git a/internal/pkg/template/templates/workloads/services/lb-web/cf.yml b/internal/pkg/template/templates/workloads/services/lb-web/cf.yml index 9e4e7a76ef7..61eb21ee391 100644 --- a/internal/pkg/template/templates/workloads/services/lb-web/cf.yml +++ b/internal/pkg/template/templates/workloads/services/lb-web/cf.yml @@ -114,7 +114,9 @@ Resources: Properties: {{include "service-base-properties" . | indent 6}} # This may need to be adjusted if the container takes a while to start up + {{- if .HTTPHealthCheck.GracePeriod }} HealthCheckGracePeriodSeconds: {{.HTTPHealthCheck.GracePeriod}} + {{- end }} LoadBalancers: {{- if .ALBEnabled}} - ContainerName: !Ref TargetContainer diff --git a/internal/pkg/template/workload.go b/internal/pkg/template/workload.go index cd3fe9d19a6..95b298a1c5c 100644 --- a/internal/pkg/template/workload.go +++ b/internal/pkg/template/workload.go @@ -216,7 +216,11 @@ func (tg HTTPTargetContainer) IsHTTPS() bool { // HTTPHealthCheckOpts holds configuration that's needed for HTTP Health Check. type HTTPHealthCheckOpts struct { - HealthCheckPath string + // Fields with defaults always set. + HealthCheckPath string + GracePeriod int64 + + // Optional. Port string SuccessCodes string HealthyThreshold *int64 @@ -224,7 +228,6 @@ type HTTPHealthCheckOpts struct { Interval *int64 Timeout *int64 DeregistrationDelay *int64 - GracePeriod *int64 } // A Secret represents an SSM or SecretsManager secret that can be rendered in CloudFormation.