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