Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 56c3053

Browse files
committed
Context setup
1 parent f5dd5d4 commit 56c3053

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"fmt"
88
"log"
99
"os"
10+
"os/signal"
11+
"syscall"
1012

1113
"github.com/mariadb-operator/agent/pkg/logger"
1214
mariadbv1alpha1 "github.com/mariadb-operator/mariadb-operator/api/v1alpha1"
@@ -42,6 +44,15 @@ func main() {
4244

4345
flag.Parse()
4446

47+
ctx, cancel := signal.NotifyContext(context.Background(), []os.Signal{
48+
syscall.SIGINT,
49+
syscall.SIGTERM,
50+
syscall.SIGKILL,
51+
syscall.SIGHUP,
52+
syscall.SIGQUIT}...,
53+
)
54+
defer cancel()
55+
4556
logger, err := logger.NewLogger(
4657
logger.WithLogLevel(logLevel),
4758
logger.WithTimeEncoder(logTimeEncoder),
@@ -63,7 +74,7 @@ func main() {
6374
os.Exit(1)
6475
}
6576

66-
mdb, err := mariadb(context.TODO(), mariadbName, mariadbNamespace, clientset)
77+
mdb, err := mariadb(ctx, mariadbName, mariadbNamespace, clientset)
6778
if err != nil {
6879
logger.Error(err, "Error getting MariaDB")
6980
os.Exit(1)

0 commit comments

Comments
 (0)