Skip to content

Commit 2b20db7

Browse files
author
Benjamin Ritter
committed
feat: add --shutdown-delay flag
Signed-off-by: Benjamin Ritter <[email protected]>
1 parent 0e8c79e commit 2b20db7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ var (
119119
enableK8sCel = flag.Bool("enable-k8s-native-validation", true, "enable the validating admission policy driver")
120120
externaldataProviderResponseCacheTTL = flag.Duration("external-data-provider-response-cache-ttl", 3*time.Minute, "TTL for the external data provider response cache. Specify the duration in 'h', 'm', or 's' for hours, minutes, or seconds respectively. Defaults to 3 minutes if unspecified. Setting the TTL to 0 disables the cache.")
121121
enableReferential = flag.Bool("enable-referential-rules", true, "Enable referential rules. This flag defaults to true. Set this value to false if you want to disallow referential constraints. Because referential constraints read objects other than the object-under-test, they may be subject to race conditions. Users concerned about this may want to disable referential rules")
122+
shutdownDelay = flag.Uint("shutdown-delay", 10, "Time in seconds the controller runtime shutdown gets delayed after receiving a pod termination event. Prevents failing webhooks on pod shutdown. default: 10")
122123
)
123124

124125
func init() {
@@ -326,6 +327,7 @@ func innerMain() int {
326327

327328
// Setup termination with grace period. Required to give K8s Services time to disconnect the Pod endpoint on termination.
328329
// Derived from how the controller-runtime sets up a signal handler with ctrl.SetupSignalHandler()
330+
// controller-runtime upstream issue: https://github.com/kubernetes-sigs/controller-runtime/issues/3113
329331
ctx, cancel := context.WithCancel(context.Background())
330332

331333
c := make(chan os.Signal, 2)
@@ -334,7 +336,7 @@ func innerMain() int {
334336
<-c
335337
setupLog.Info("Shutting Down, waiting for 10s")
336338
go func() {
337-
time.Sleep(10* time.Second)
339+
time.Sleep(time.Duration(*shutdownDelay) * time.Second)
338340
setupLog.Info("Shutdown grace period finished")
339341
cancel()
340342
}()

0 commit comments

Comments
 (0)