forked from postfinance/kubenurse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (50 loc) · 1.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"context"
"fmt"
"log"
"os/signal"
"syscall"
"time"
"github.com/postfinance/kubenurse/internal/kubenurse"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
const (
nurse = "I'm ready to help you!"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
// create in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
log.Printf("creating in-cluster configuration: %s", err)
return
}
cliset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Printf("creating clientset: %s", err)
return
}
server, err := kubenurse.New(ctx, cliset)
if err != nil {
log.Printf("%s", err)
return
}
go func() {
<-ctx.Done() // blocks until ctx is canceled
log.Println("shutting down, received signal to stop")
// background ctx since, the "root" context is already canceled
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer shutdownCancel()
if err := server.Shutdown(shutdownCtx); err != nil {
log.Printf("gracefully halting kubenurse server: %s", err)
}
}()
fmt.Println(nurse) // most important line of this project
// blocks, until the server is stopped by calling Shutdown()
if err := server.Run(); err != nil {
log.Printf("running kubenurse: %s", err)
}
}