-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
67 lines (58 loc) · 1.57 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
64
65
66
67
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/numberly/vault-db-injector/pkg/config"
"github.com/numberly/vault-db-injector/pkg/controller"
"github.com/numberly/vault-db-injector/pkg/k8s"
"github.com/numberly/vault-db-injector/pkg/logger"
"github.com/numberly/vault-db-injector/pkg/sentry"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
)
func main() {
errChan := make(chan error)
runSuccess := make(chan bool)
metricsSuccess := make(chan bool)
cfgFile := flag.String("config", "", "The config file to use.")
flag.Parse()
cfg, err := config.NewConfig(*cfgFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not parse config file: %s", err)
os.Exit(1)
}
logger.Initialize(*cfg)
log := logger.GetLogger()
sentryService := sentry.NewSentry(cfg.SentryDsn, cfg.Sentry)
sentryService.StartSentry()
k8sClient := k8s.NewClient()
clientset, err := k8sClient.GetKubernetesClient()
if err != nil {
log.Fatalf("Unable to create Kubernetes client error = %v", err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := controller.NewController(cfg, clientset)
switch cfg.Mode {
case "injector":
go c.RunInjector(ctx, errChan, runSuccess)
case "renewer":
go c.RunRenewer(ctx, metricsSuccess)
case "revoker":
go c.RunRevoker(ctx, metricsSuccess)
}
// Attendez le succès ou l'échec des fonctions run et runMetrics
successCount := 0
for {
select {
case err := <-errChan:
log.Errorf("error running app: %s", err)
os.Exit(1)
case <-runSuccess:
successCount++
case <-metricsSuccess:
successCount++
}
}
}