-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
84 lines (68 loc) · 1.75 KB
/
Copy pathmain.go
File metadata and controls
84 lines (68 loc) · 1.75 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"context"
"flag"
"net/http"
"os"
"os/signal"
"sync"
"syscall"
"github.com/rs/zerolog/log"
"github.com/drorivry/rego/config"
"github.com/drorivry/rego/initializers"
k8s_client "github.com/drorivry/rego/k8s"
"github.com/drorivry/rego/poller"
"github.com/drorivry/rego/tasker"
)
func runServer(server *http.Server, wg *sync.WaitGroup) {
server.ListenAndServe()
defer wg.Done()
}
func runPoller(p *poller.Poller, wg *sync.WaitGroup) {
p.Run()
defer wg.Done()
}
func handleInterrupt(c chan os.Signal, server *http.Server, p *poller.Poller) {
<-c
log.Info().Msg("Received Ctrl+C")
log.Info().Msg("Shutting down api server")
server.Shutdown(context.Background())
log.Info().Msg("Shutting down poller")
p.Shutdown()
}
func init() {
initializers.LoadEnvVars()
config.InitConfig()
initializers.InitDBConnection()
}
// @title Rego
// @version 1.0
// @description Schedualing workloads made easy.
// @contact.name XXXX
// @contact.email XXX@gmail.com
// @license.name MIT
// @license.url https://opensource.org/license/mit/
// @host localhost:3000
// @BasePath /api/v1
func main() {
kubeConfigPath := flag.String("kubeConfigPath", "", "The path to the kubeconfig")
pollInterval := flag.Int("interval", 1, "The polling interval")
k8s_client.InitK8SClientSet(kubeConfigPath)
//todo replace that with cobra
flag.Parse()
var wg sync.WaitGroup
wg.Add(1)
server := tasker.GetServer(config.SERVER_PORT)
log.Info().Int(
"server_port",
config.SERVER_PORT,
).Msg("Starting server on port")
go runServer(server, &wg)
wg.Add(1)
p := poller.NewPoller(*pollInterval)
go runPoller(p, &wg)
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go handleInterrupt(c, server, p)
wg.Wait()
}