From 58a536552889ba7fc9ea535da52d52f5f770f692 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Mon, 6 May 2024 17:13:52 -0400 Subject: [PATCH] APPS-8711: container termination controls (#685) * APPS-8711: container termination controls * add test --- apps.gen.go | 37 ++++++++++++++++++++++------ apps_accessors.go | 56 ++++++++++++++++++++++++++++++++++++++++++ apps_accessors_test.go | 49 ++++++++++++++++++++++++++++++++++++ apps_test.go | 10 ++++++++ 4 files changed, 145 insertions(+), 7 deletions(-) diff --git a/apps.gen.go b/apps.gen.go index c037559..a5bef2d 100644 --- a/apps.gen.go +++ b/apps.gen.go @@ -388,6 +388,7 @@ type AppJobSpec struct { Alerts []*AppAlertSpec `json:"alerts,omitempty"` // A list of configured log forwarding destinations. LogDestinations []*AppLogDestinationSpec `json:"log_destinations,omitempty"` + Termination *AppJobSpecTermination `json:"termination,omitempty"` } // AppJobSpecKind - UNSPECIFIED: Default job type, will auto-complete to POST_DEPLOY kind. - PRE_DEPLOY: Indicates a job that runs before an app deployment. - POST_DEPLOY: Indicates a job that runs after an app deployment. - FAILED_DEPLOY: Indicates a job that runs after a component fails to deploy. @@ -401,6 +402,12 @@ const ( AppJobSpecKind_FailedDeploy AppJobSpecKind = "FAILED_DEPLOY" ) +// AppJobSpecTermination struct for AppJobSpecTermination +type AppJobSpecTermination struct { + // The number of seconds to wait between sending a TERM signal to a container and issuing a KILL which causes immediate shutdown. Default: 120, Minimum 1, Maximum 600. + GracePeriodSeconds int32 `json:"grace_period_seconds,omitempty"` +} + // AppLogDestinationSpec struct for AppLogDestinationSpec type AppLogDestinationSpec struct { // Name of the log destination. @@ -484,22 +491,23 @@ type AppServiceSpec struct { // A list of configured alerts which apply to the component. Alerts []*AppAlertSpec `json:"alerts,omitempty"` // A list of configured log forwarding destinations. - LogDestinations []*AppLogDestinationSpec `json:"log_destinations,omitempty"` + LogDestinations []*AppLogDestinationSpec `json:"log_destinations,omitempty"` + Termination *AppServiceSpecTermination `json:"termination,omitempty"` } // AppServiceSpecHealthCheck struct for AppServiceSpecHealthCheck type AppServiceSpecHealthCheck struct { // Deprecated. Use http_path instead. Path string `json:"path,omitempty"` - // The number of seconds to wait before beginning health checks. Default: 0 seconds; start health checks as soon as the service starts. + // The number of seconds to wait before beginning health checks. Default: 0 seconds, Minimum 0, Maximum 3600. InitialDelaySeconds int32 `json:"initial_delay_seconds,omitempty"` - // The number of seconds to wait between health checks. Default: 10 seconds. + // The number of seconds to wait between health checks. Default: 10 seconds, Minimum 1, Maximum 300. PeriodSeconds int32 `json:"period_seconds,omitempty"` - // The number of seconds after which the check times out. Default: 1 second. + // The number of seconds after which the check times out. Default: 1 second, Minimum 1, Maximum 120. TimeoutSeconds int32 `json:"timeout_seconds,omitempty"` - // The number of successful health checks before considered healthy. Default: 1. + // The number of successful health checks before considered healthy. Default: 1, Minimum 1, Maximum 50. SuccessThreshold int32 `json:"success_threshold,omitempty"` - // The number of failed health checks before considered unhealthy. Default: 9. + // The number of failed health checks before considered unhealthy. Default: 9, Minimum 1, Maximum 50. FailureThreshold int32 `json:"failure_threshold,omitempty"` // The route path used for the HTTP health check ping. If not set, the HTTP health check will be disabled and a TCP health check used instead. HTTPPath string `json:"http_path,omitempty"` @@ -507,6 +515,14 @@ type AppServiceSpecHealthCheck struct { Port int64 `json:"port,omitempty"` } +// AppServiceSpecTermination struct for AppServiceSpecTermination +type AppServiceSpecTermination struct { + // The number of seconds to wait between selecting a container instance for termination and issuing the TERM signal. Selecting a container instance for termination begins an asynchronous drain of new requests on upstream load-balancers. Default: 15 seconds, Minimum 1, Maximum 110. + DrainSeconds int32 `json:"drain_seconds,omitempty"` + // The number of seconds to wait between sending a TERM signal to a container and issuing a KILL which causes immediate shutdown. Default: 120, Minimum 1, Maximum 600. + GracePeriodSeconds int32 `json:"grace_period_seconds,omitempty"` +} + // AppSpec The desired configuration of an application. type AppSpec struct { // The name of the app. Must be unique across all apps in the same account. @@ -601,7 +617,14 @@ type AppWorkerSpec struct { // A list of configured alerts which apply to the component. Alerts []*AppAlertSpec `json:"alerts,omitempty"` // A list of configured log forwarding destinations. - LogDestinations []*AppLogDestinationSpec `json:"log_destinations,omitempty"` + LogDestinations []*AppLogDestinationSpec `json:"log_destinations,omitempty"` + Termination *AppWorkerSpecTermination `json:"termination,omitempty"` +} + +// AppWorkerSpecTermination struct for AppWorkerSpecTermination +type AppWorkerSpecTermination struct { + // The number of seconds to wait between sending a TERM signal to a container and issuing a KILL which causes immediate shutdown. Default: 120, Minimum 1, Maximum 600. + GracePeriodSeconds int32 `json:"grace_period_seconds,omitempty"` } // Buildpack struct for Buildpack diff --git a/apps_accessors.go b/apps_accessors.go index 0d655d8..734c27e 100644 --- a/apps_accessors.go +++ b/apps_accessors.go @@ -1261,6 +1261,22 @@ func (a *AppJobSpec) GetSourceDir() string { return a.SourceDir } +// GetTermination returns the Termination field. +func (a *AppJobSpec) GetTermination() *AppJobSpecTermination { + if a == nil { + return nil + } + return a.Termination +} + +// GetGracePeriodSeconds returns the GracePeriodSeconds field. +func (a *AppJobSpecTermination) GetGracePeriodSeconds() int32 { + if a == nil { + return 0 + } + return a.GracePeriodSeconds +} + // GetDatadog returns the Datadog field. func (a *AppLogDestinationSpec) GetDatadog() *AppLogDestinationSpecDataDog { if a == nil { @@ -1725,6 +1741,14 @@ func (a *AppServiceSpec) GetSourceDir() string { return a.SourceDir } +// GetTermination returns the Termination field. +func (a *AppServiceSpec) GetTermination() *AppServiceSpecTermination { + if a == nil { + return nil + } + return a.Termination +} + // GetFailureThreshold returns the FailureThreshold field. func (a *AppServiceSpecHealthCheck) GetFailureThreshold() int32 { if a == nil { @@ -1789,6 +1813,22 @@ func (a *AppServiceSpecHealthCheck) GetTimeoutSeconds() int32 { return a.TimeoutSeconds } +// GetDrainSeconds returns the DrainSeconds field. +func (a *AppServiceSpecTermination) GetDrainSeconds() int32 { + if a == nil { + return 0 + } + return a.DrainSeconds +} + +// GetGracePeriodSeconds returns the GracePeriodSeconds field. +func (a *AppServiceSpecTermination) GetGracePeriodSeconds() int32 { + if a == nil { + return 0 + } + return a.GracePeriodSeconds +} + // GetAlerts returns the Alerts field. func (a *AppSpec) GetAlerts() []*AppAlertSpec { if a == nil { @@ -2237,6 +2277,22 @@ func (a *AppWorkerSpec) GetSourceDir() string { return a.SourceDir } +// GetTermination returns the Termination field. +func (a *AppWorkerSpec) GetTermination() *AppWorkerSpecTermination { + if a == nil { + return nil + } + return a.Termination +} + +// GetGracePeriodSeconds returns the GracePeriodSeconds field. +func (a *AppWorkerSpecTermination) GetGracePeriodSeconds() int32 { + if a == nil { + return 0 + } + return a.GracePeriodSeconds +} + // GetDescription returns the Description field. func (b *Buildpack) GetDescription() []string { if b == nil { diff --git a/apps_accessors_test.go b/apps_accessors_test.go index 4dc958e..6748e69 100644 --- a/apps_accessors_test.go +++ b/apps_accessors_test.go @@ -1105,6 +1105,20 @@ func TestAppJobSpec_GetSourceDir(tt *testing.T) { a.GetSourceDir() } +func TestAppJobSpec_GetTermination(tt *testing.T) { + a := &AppJobSpec{} + a.GetTermination() + a = nil + a.GetTermination() +} + +func TestAppJobSpecTermination_GetGracePeriodSeconds(tt *testing.T) { + a := &AppJobSpecTermination{} + a.GetGracePeriodSeconds() + a = nil + a.GetGracePeriodSeconds() +} + func TestAppLogDestinationSpec_GetDatadog(tt *testing.T) { a := &AppLogDestinationSpec{} a.GetDatadog() @@ -1511,6 +1525,13 @@ func TestAppServiceSpec_GetSourceDir(tt *testing.T) { a.GetSourceDir() } +func TestAppServiceSpec_GetTermination(tt *testing.T) { + a := &AppServiceSpec{} + a.GetTermination() + a = nil + a.GetTermination() +} + func TestAppServiceSpecHealthCheck_GetFailureThreshold(tt *testing.T) { a := &AppServiceSpecHealthCheck{} a.GetFailureThreshold() @@ -1567,6 +1588,20 @@ func TestAppServiceSpecHealthCheck_GetTimeoutSeconds(tt *testing.T) { a.GetTimeoutSeconds() } +func TestAppServiceSpecTermination_GetDrainSeconds(tt *testing.T) { + a := &AppServiceSpecTermination{} + a.GetDrainSeconds() + a = nil + a.GetDrainSeconds() +} + +func TestAppServiceSpecTermination_GetGracePeriodSeconds(tt *testing.T) { + a := &AppServiceSpecTermination{} + a.GetGracePeriodSeconds() + a = nil + a.GetGracePeriodSeconds() +} + func TestAppSpec_GetAlerts(tt *testing.T) { a := &AppSpec{} a.GetAlerts() @@ -1959,6 +1994,20 @@ func TestAppWorkerSpec_GetSourceDir(tt *testing.T) { a.GetSourceDir() } +func TestAppWorkerSpec_GetTermination(tt *testing.T) { + a := &AppWorkerSpec{} + a.GetTermination() + a = nil + a.GetTermination() +} + +func TestAppWorkerSpecTermination_GetGracePeriodSeconds(tt *testing.T) { + a := &AppWorkerSpecTermination{} + a.GetGracePeriodSeconds() + a = nil + a.GetGracePeriodSeconds() +} + func TestBuildpack_GetDescription(tt *testing.T) { b := &Buildpack{} b.GetDescription() diff --git a/apps_test.go b/apps_test.go index 6a9800d..e86f808 100644 --- a/apps_test.go +++ b/apps_test.go @@ -30,6 +30,10 @@ var ( }, InstanceSizeSlug: "professional-xs", InstanceCount: 1, + Termination: &AppServiceSpecTermination{ + GracePeriodSeconds: 100, + DrainSeconds: 60, + }, }}, Workers: []*AppWorkerSpec{{ Name: "worker-name", @@ -42,6 +46,9 @@ var ( }, InstanceSizeSlug: "professional-xs", InstanceCount: 1, + Termination: &AppWorkerSpecTermination{ + GracePeriodSeconds: 100, + }, }}, StaticSites: []*AppStaticSiteSpec{{ Name: "static-name", @@ -63,6 +70,9 @@ var ( }, InstanceSizeSlug: "professional-xs", InstanceCount: 1, + Termination: &AppJobSpecTermination{ + GracePeriodSeconds: 100, + }, }}, Databases: []*AppDatabaseSpec{{ Name: "db",