File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,9 @@ import (
26
26
"net/http"
27
27
_ "net/http/pprof"
28
28
"os"
29
+ "os/signal"
29
30
"path/filepath"
31
+ "syscall"
30
32
"time"
31
33
32
34
"github.com/go-logr/zapr"
@@ -319,9 +321,30 @@ func innerMain() int {
319
321
}
320
322
}
321
323
324
+ setupLog .Error (errors .New ("Canary" ), "Canary" )
325
+
322
326
// Setup controllers asynchronously, they will block for certificate generation if needed.
323
327
setupErr := make (chan error )
324
- ctx := ctrl .SetupSignalHandler ()
328
+
329
+ // Setup termination with grace period. Required to give K8s Services time to disconnect the Pod endpoint on termination.
330
+ // Derived from how the controller-runtime sets up a signal handler with ctrl.SetupSignalHandler()
331
+ ctx , cancel := context .WithCancel (context .Background ())
332
+
333
+ c := make (chan os.Signal , 2 )
334
+ signal .Notify (c , []os.Signal {os .Interrupt , syscall .SIGTERM }... )
335
+ go func () {
336
+ <- c
337
+ setupLog .Info ("Shutting Down, waiting for 10s" )
338
+ go func () {
339
+ time .Sleep (10 * time .Second )
340
+ setupLog .Info ("Shutdown grace period finished" )
341
+ cancel ()
342
+ }()
343
+ <- c
344
+ setupLog .Info ("Second signal received, killing now" )
345
+ os .Exit (1 ) // second signal. Exit directly.
346
+ }()
347
+
325
348
go func () {
326
349
setupErr <- setupControllers (ctx , mgr , tracker , setupFinished )
327
350
}()
You can’t perform that action at this time.
0 commit comments