diff --git a/.changelog/100.txt b/.changelog/100.txt new file mode 100644 index 00000000..4342c503 --- /dev/null +++ b/.changelog/100.txt @@ -0,0 +1,3 @@ +```release-note:feature +Add -shutdown-drain-listeners, -shutdown-grace-period, -graceful-shutdown-path and -graceful-port flags to configure proxy lifecycle management settings for the Envoy container. +``` diff --git a/cmd/consul-dataplane/main.go b/cmd/consul-dataplane/main.go index 33607936..f49925a1 100644 --- a/cmd/consul-dataplane/main.go +++ b/cmd/consul-dataplane/main.go @@ -73,6 +73,11 @@ var ( consulDNSBindAddr string consulDNSPort int + + shutdownDrainListenersEnabled bool + shutdownGracePeriodSeconds int + gracefulShutdownPath string + gracefulPort int ) func init() { @@ -139,6 +144,15 @@ func init() { StringVar(&consulDNSBindAddr, "consul-dns-bind-addr", "127.0.0.1", "DP_CONSUL_DNS_BIND_ADDR", "The address that will be bound to the consul dns proxy.") IntVar(&consulDNSPort, "consul-dns-bind-port", -1, "DP_CONSUL_DNS_BIND_PORT", "The port the consul dns proxy will listen on. By default -1 disables the dns proxy") + + // Default is false because it will generally be configured appropriately by Helm + // configuration or pod annotation. + BoolVar(&shutdownDrainListenersEnabled, "shutdown-drain-listeners", false, "DP_SHUTDOWN_DRAIN_LISTENERS", "Wait for proxy listeners to drain before terminating the proxy container.") + // Default is 0 because it will generally be configured appropriately by Helm + // configuration or pod annotation. + IntVar(&shutdownGracePeriodSeconds, "shutdown-grace-period-seconds", 0, "DP_SHUTDOWN_GRACE_PERIOD_SECONDS", "Amount of time to wait after receiving a SIGTERM signal before terminating the proxy.") + StringVar(&gracefulShutdownPath, "graceful-shutdown-path", "/graceful_shutdown", "DP_GRACEFUL_SHUTDOWN_PATH", "An HTTP path to serve the graceful shutdown endpoint.") + IntVar(&gracefulPort, "graceful-port", 20300, "DP_GRACEFUL_PORT", "A port to serve HTTP endpoints for graceful shutdown.") } // validateFlags performs semantic validation of the flag values @@ -216,12 +230,16 @@ func main() { }, }, Envoy: &consuldp.EnvoyConfig{ - AdminBindAddress: adminBindAddr, - AdminBindPort: adminBindPort, - ReadyBindAddress: readyBindAddr, - ReadyBindPort: readyBindPort, - EnvoyConcurrency: envoyConcurrency, - ExtraArgs: flag.Args(), + AdminBindAddress: adminBindAddr, + AdminBindPort: adminBindPort, + ReadyBindAddress: readyBindAddr, + ReadyBindPort: readyBindPort, + EnvoyConcurrency: envoyConcurrency, + ShutdownDrainListenersEnabled: shutdownDrainListenersEnabled, + ShutdownGracePeriodSeconds: shutdownGracePeriodSeconds, + GracefulShutdownPath: gracefulShutdownPath, + GracefulPort: gracefulPort, + ExtraArgs: flag.Args(), }, XDSServer: &consuldp.XDSServer{ BindAddress: xdsBindAddr, diff --git a/pkg/consuldp/config.go b/pkg/consuldp/config.go index 7d41d4fd..dc17860b 100644 --- a/pkg/consuldp/config.go +++ b/pkg/consuldp/config.go @@ -274,6 +274,14 @@ type EnvoyConfig struct { ReadyBindPort int // EnvoyConcurrency is the envoy concurrency https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-concurrency EnvoyConcurrency int + // ShutdownDrainListenersEnabled configures whether to wait for all proxy listeners to drain before terminating the proxy container. + ShutdownDrainListenersEnabled bool + // ShutdownGracePeriodSeconds is the amount of time to wait after receiving a SIGTERM before terminating the proxy container. + ShutdownGracePeriodSeconds int + // GracefulShutdownPath is the path on which the HTTP endpoint to initiate a graceful shutdown of Envoy is served + GracefulShutdownPath string + // GracefulPort is the port on which the HTTP server for graceful shutdown endpoints will be available. + GracefulPort int // ExtraArgs are the extra arguments passed to envoy at startup of the proxy ExtraArgs []string }