Skip to content

Commit

Permalink
finish renaming to shutdownDrainListenersEnabled and ShutdownDrainLis…
Browse files Browse the repository at this point in the history
…tenersEnabled after rebase
  • Loading branch information
mikemorris committed Jun 6, 2023
1 parent b5e3aea commit bf8f0c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
20 changes: 10 additions & 10 deletions pkg/consuldp/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type lifecycleConfig struct {
logger hclog.Logger

// consuldp proxy lifecycle management config
shutdownDrainListeners bool
shutdownGracePeriodSeconds int
gracefulPort int
gracefulShutdownPath string
shutdownDrainListenersEnabled bool
shutdownGracePeriodSeconds int
gracefulPort int
gracefulShutdownPath string

// manager for controlling the Envoy proxy process
proxy envoy.ProxyManager
Expand All @@ -51,10 +51,10 @@ type lifecycleConfig struct {

func NewLifecycleConfig(cfg *Config, proxy envoy.ProxyManager) *lifecycleConfig {
return &lifecycleConfig{
shutdownDrainListeners: cfg.Envoy.ShutdownDrainListeners,
shutdownGracePeriodSeconds: cfg.Envoy.ShutdownGracePeriodSeconds,
gracefulPort: cfg.Envoy.GracefulPort,
gracefulShutdownPath: cfg.Envoy.GracefulShutdownPath,
shutdownDrainListenersEnabled: cfg.Envoy.ShutdownDrainListenersEnabled,
shutdownGracePeriodSeconds: cfg.Envoy.ShutdownGracePeriodSeconds,
gracefulPort: cfg.Envoy.GracefulPort,
gracefulShutdownPath: cfg.Envoy.GracefulShutdownPath,

proxy: proxy,

Expand Down Expand Up @@ -163,11 +163,11 @@ func (m *lifecycleConfig) gracefulShutdown(rw http.ResponseWriter, _ *http.Reque
go func() {
defer wg.Done()

// If shutdownDrainListeners enabled, initiatie graceful shutdown of Envoy.
// If shutdownDrainListenersEnabled, initiatie graceful shutdown of Envoy.
// We want to start draining connections from inbound listeners if
// configured, but still allow outbound traffic until gracefulShutdownPeriod
// has elapsed to facilitate a graceful application shutdown.
if m.shutdownDrainListeners {
if m.shutdownDrainListenersEnabled {
err := m.proxy.Drain()
if err != nil {
m.logger.Warn("error while draining Envoy listeners", "error", err)
Expand Down
34 changes: 17 additions & 17 deletions pkg/consuldp/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func TestLifecycleServerClosed(t *testing.T) {

func TestLifecycleServerEnabled(t *testing.T) {
cases := map[string]struct {
shutdownDrainListeners bool
shutdownGracePeriodSeconds int
gracefulShutdownPath string
gracefulPort int
shutdownDrainListenersEnabled bool
shutdownGracePeriodSeconds int
gracefulShutdownPath string
gracefulPort int
}{
// TODO: testing the actual Envoy behavior here such as how open or new
// connections are handled should happpen in integration or acceptance tests
Expand All @@ -58,7 +58,7 @@ func TestLifecycleServerEnabled(t *testing.T) {
// connections, GOAWAY to inbound HTTP2, and terminate connections on
// request completion. Outbound connections should start being rejected
// immediately.
shutdownDrainListeners: true,
shutdownDrainListenersEnabled: true,
},
"connection draining disabled with grace period": {
// This should immediately terminate any open inbound connections.
Expand All @@ -73,13 +73,13 @@ func TestLifecycleServerEnabled(t *testing.T) {
// Outbound connections should be allowed until the grace period has
// elapsed, then any remaining open connections should be closed and new
// outbound connections should start being rejected until pod termination.
shutdownDrainListeners: true,
shutdownGracePeriodSeconds: 5,
shutdownDrainListenersEnabled: true,
shutdownGracePeriodSeconds: 5,
},
"custom graceful shutdown path and port": {
shutdownDrainListeners: true,
shutdownGracePeriodSeconds: 5,
gracefulShutdownPath: "/quit-nicely",
shutdownDrainListenersEnabled: true,
shutdownGracePeriodSeconds: 5,
gracefulShutdownPath: "/quit-nicely",
// TODO: should this be random or use freeport? logic disallows passing
// zero value explicitly
gracefulPort: 23108,
Expand All @@ -92,12 +92,12 @@ func TestLifecycleServerEnabled(t *testing.T) {
t.Run(name, func(t *testing.T) {
cfg := Config{
Envoy: &EnvoyConfig{
AdminBindAddress: envoyAdminAddr,
AdminBindPort: envoyAdminPort,
ShutdownDrainListeners: c.shutdownDrainListeners,
ShutdownGracePeriodSeconds: c.shutdownGracePeriodSeconds,
GracefulShutdownPath: c.gracefulShutdownPath,
GracefulPort: c.gracefulPort,
AdminBindAddress: envoyAdminAddr,
AdminBindPort: envoyAdminPort,
ShutdownDrainListenersEnabled: c.shutdownDrainListenersEnabled,
ShutdownGracePeriodSeconds: c.shutdownGracePeriodSeconds,
GracefulShutdownPath: c.gracefulShutdownPath,
GracefulPort: c.gracefulPort,
},
}
m := NewLifecycleConfig(&cfg, &mockProxy{})
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestLifecycleServerEnabled(t *testing.T) {
resp, err := http.Get(url)

// Use mock client to check expected method calls to proxy manager
if c.shutdownDrainListeners {
if c.shutdownDrainListenersEnabled {
require.Equal(t, 1, m.proxy.(*mockProxy).drainCalled, "Proxy.Drain() not called as expected")
} else {
require.Equal(t, 0, m.proxy.(*mockProxy).drainCalled, "Proxy.Drain() called unexpectedly")
Expand Down

0 comments on commit bf8f0c8

Please sign in to comment.