Skip to content

Commit

Permalink
code cleanup, timeout fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorLeonHC committed Aug 14, 2023
1 parent 595a43e commit 6a57d91
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
7 changes: 3 additions & 4 deletions cmd/consul-dataplane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ func init() {
IntVar(flags, &flagOpts.dataplaneConfig.Envoy.ShutdownGracePeriodSeconds, "shutdown-grace-period-seconds", "DP_SHUTDOWN_GRACE_PERIOD_SECONDS", "Amount of time to wait after receiving a SIGTERM signal before terminating the proxy.")
StringVar(flags, &flagOpts.dataplaneConfig.Envoy.GracefulShutdownPath, "graceful-shutdown-path", "DP_GRACEFUL_SHUTDOWN_PATH", "An HTTP path to serve the graceful shutdown endpoint.")
IntVar(flags, &flagOpts.dataplaneConfig.Envoy.GracefulPort, "graceful-port", "DP_GRACEFUL_PORT", "A port to serve HTTP endpoints for graceful shutdown.")

// Default is false, may be useful for debugging unexpected termination.
BoolVar(flags, &flagOpts.dataplaneConfig.Envoy.DumpEnvoyConfigOnExitEnabled, "dump-envoy-config-on-exit", "DP_DUMP_ENVOY_CONFIG_ON_EXIT", "Call the Envoy /config_dump endpoint during consul-dataplane controlled shutdown.")
//#########################
IntVar(flags, &flagOpts.dataplaneConfig.Envoy.StartupGracePeriodSeconds, "startup-grace-period-seconds", "DP_STARTUP_GRACE_PERIOD_SECONDS", "Amount of time to wait for consul-dataplane startup.")
StringVar(flags, &flagOpts.dataplaneConfig.Envoy.GracefulStartupPath, "graceful-startup-path", "DP_GRACEFUL_STARTUP_PATH", "An HTTP path to serve the graceful startup endpoint.")
// Default is false, may be useful for debugging unexpected termination.
BoolVar(flags, &flagOpts.dataplaneConfig.Envoy.DumpEnvoyConfigOnExitEnabled, "dump-envoy-config-on-exit", "DP_DUMP_ENVOY_CONFIG_ON_EXIT", "Call the Envoy /config_dump endpoint during consul-dataplane controlled shutdown.")

flags.StringVar(&flagOpts.configFile, "config-file", "", "The json config file for configuring consul data plane")
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/consuldp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,14 @@ type EnvoyConfig struct {
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
// DumpEnvoyConfigOnExitEnabled configures whether to call Envoy's /config_dump endpoint during consul-dataplane controlled shutdown.
DumpEnvoyConfigOnExitEnabled bool
//##############
//StartupGracePeriodSeconds is the amount of time to block application after startup for Envoy proxy to be ready.
StartupGracePeriodSeconds int
// GracefulStartupPath is the path on which the HTTP endpoint to initiate a graceful startup of Envoy is served
GracefulStartupPath string
// GracefulPort is the port on which the HTTP server for graceful shutdown endpoints will be available.
GracefulPort int
// DumpEnvoyConfigOnExitEnabled configures whether to call Envoy's /config_dump endpoint during consul-dataplane controlled shutdown.
DumpEnvoyConfigOnExitEnabled bool
// ExtraArgs are the extra arguments passed to envoy at startup of the proxy
ExtraArgs []string
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/consuldp/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,18 @@ func (m *lifecycleConfig) gracefulShutdown() {

func (m *lifecycleConfig) gracefulStartupHandler(rw http.ResponseWriter, _ *http.Request) {

m.gracefulStartup()
//Unlike in gracefulShutdown, we want to delay the OK response until envoy is ready
//in order to block application container.
m.gracefulStartup()
rw.WriteHeader(http.StatusOK)

}

// gracefulStartup blocks until the startup grace period has elapsed or we have confirmed that
// Envoy proxy is ready.
func (m *lifecycleConfig) gracefulStartup() {
m.logger.Info("Blocking container startup until Envoy ready / grace period elapsed")
timeout := time.Duration(m.shutdownGracePeriodSeconds) * time.Second
timeout := time.Duration(m.startupGracePeriodSeconds) * time.Second
m.logger.Info("Blocking container startup until Envoy ready or until graceful timeout elapsed", "timeout", timeout)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

Expand Down

0 comments on commit 6a57d91

Please sign in to comment.