Skip to content

Commit

Permalink
revisit envoy shutdown settings (envoyproxy#4288)
Browse files Browse the repository at this point in the history
* Set default minDrainDuration to `10s` . Since the default
  `readinessProbe.periodSeconds` is `5s`, this gives any LB controller
  `5s` to update its endpoint pool if its basing it off the k8s API
  server
* Set default `drainTimeout` to `60s`. This ensures clients holding
  persistent connections, can be closed sooner.
  Fixes: envoyproxy#4125
* Updates the default `terminationGracePeriodSeconds` to `360s`
which is `300s` more than the default drain timeout

Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: zirain <[email protected]>
  • Loading branch information
arkodg and zirain authored Sep 21, 2024
1 parent f4ae934 commit 475cd61
Show file tree
Hide file tree
Showing 42 changed files with 85 additions and 47 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/envoyproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ type EnvoyProxyProvider struct {
// ShutdownConfig defines configuration for graceful envoy shutdown process.
type ShutdownConfig struct {
// DrainTimeout defines the graceful drain timeout. This should be less than the pod's terminationGracePeriodSeconds.
// If unspecified, defaults to 600 seconds.
// If unspecified, defaults to 60 seconds.
//
// +optional
DrainTimeout *metav1.Duration `json:"drainTimeout,omitempty"`
// MinDrainDuration defines the minimum drain duration allowing time for endpoint deprogramming to complete.
// If unspecified, defaults to 5 seconds.
// If unspecified, defaults to 10 seconds.
//
// +optional
MinDrainDuration *metav1.Duration `json:"minDrainDuration,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10248,12 +10248,12 @@ spec:
drainTimeout:
description: |-
DrainTimeout defines the graceful drain timeout. This should be less than the pod's terminationGracePeriodSeconds.
If unspecified, defaults to 600 seconds.
If unspecified, defaults to 60 seconds.
type: string
minDrainDuration:
description: |-
MinDrainDuration defines the minimum drain duration allowing time for endpoint deprogramming to complete.
If unspecified, defaults to 5 seconds.
If unspecified, defaults to 10 seconds.
type: string
type: object
telemetry:
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func getShutdownCommand() *cobra.Command {
},
}

cmd.PersistentFlags().DurationVar(&drainTimeout, "drain-timeout", 600*time.Second,
cmd.PersistentFlags().DurationVar(&drainTimeout, "drain-timeout", 60*time.Second,
"Graceful shutdown timeout. This should be less than the pod's terminationGracePeriodSeconds.")

cmd.PersistentFlags().DurationVar(&minDrainDuration, "min-drain-duration", 5*time.Second,
cmd.PersistentFlags().DurationVar(&minDrainDuration, "min-drain-duration", 10*time.Second,
"Minimum drain duration allowing time for endpoint deprogramming to complete.")

cmd.PersistentFlags().IntVar(&exitAtConnections, "exit-at-connections", 0,
Expand Down
5 changes: 4 additions & 1 deletion internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
args = append(args, fmt.Sprintf("--component-log-level %s", componentsLogLevel))
}

// Default
drainTimeout := 60.0
if shutdownConfig != nil && shutdownConfig.DrainTimeout != nil {
args = append(args, fmt.Sprintf("--drain-time-s %.0f", shutdownConfig.DrainTimeout.Seconds()))
drainTimeout = shutdownConfig.DrainTimeout.Seconds()
}
args = append(args, fmt.Sprintf("--drain-time-s %.0f", drainTimeout))

if infra.Config != nil {
args = append(args, infra.Config.Spec.ExtraArgs...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (r *ResourceRender) HorizontalPodAutoscaler() (*autoscalingv2.HorizontalPod
}

func expectedTerminationGracePeriodSeconds(cfg *egv1a1.ShutdownConfig) *int64 {
s := 900 // default
s := 360 // default
if cfg != nil && cfg.DrainTimeout != nil {
s = int(cfg.DrainTimeout.Seconds() + 300) // 5 minutes longer than drain timeout
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ spec:
- --cpuset-threads
- --drain-strategy immediate
- --component-log-level filter:info
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -185,7 +186,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -366,7 +367,7 @@ spec:
securityContext:
runAsUser: 1000
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -365,7 +366,7 @@ spec:
securityContext:
runAsUser: 1000
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -352,7 +353,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -323,7 +324,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -369,7 +370,7 @@ spec:
securityContext:
runAsUser: 1000
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -361,7 +362,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -353,7 +354,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -369,7 +370,7 @@ spec:
securityContext:
runAsUser: 1000
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -357,7 +358,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ spec:
- --cpuset-threads
- --drain-strategy immediate
- --concurrency 4
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -185,7 +186,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
- --key1 val1
- --key2 val2
command:
Expand Down Expand Up @@ -354,7 +355,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -355,7 +356,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -352,7 +353,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -355,7 +356,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -352,7 +353,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
topologySpreadConstraints:
- labelSelector:
matchLabels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -188,7 +189,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ spec:
- --cpuset-threads
- --drain-strategy immediate
- --component-log-level filter:info
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -189,7 +190,7 @@ spec:
restartPolicy: Always
schedulerName: default-scheduler
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ spec:
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 60
command:
- envoy
env:
Expand Down Expand Up @@ -371,7 +372,7 @@ spec:
securityContext:
runAsUser: 1000
serviceAccountName: envoy-default-37a8eec1
terminationGracePeriodSeconds: 900
terminationGracePeriodSeconds: 360
volumes:
- name: certs
secret:
Expand Down
Loading

0 comments on commit 475cd61

Please sign in to comment.