-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
74 lines (60 loc) · 2.2 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
68
69
70
71
72
73
74
package main
import (
"errors"
"fmt"
"github.com/port-labs/port-k8s-exporter/pkg/config"
"github.com/port-labs/port-k8s-exporter/pkg/defaults"
"github.com/port-labs/port-k8s-exporter/pkg/event_handler"
"github.com/port-labs/port-k8s-exporter/pkg/handlers"
"github.com/port-labs/port-k8s-exporter/pkg/k8s"
"github.com/port-labs/port-k8s-exporter/pkg/port"
"github.com/port-labs/port-k8s-exporter/pkg/port/cli"
"github.com/port-labs/port-k8s-exporter/pkg/port/integration"
"k8s.io/klog/v2"
)
func initiateHandler(exporterConfig *port.Config, k8sClient *k8s.Client, portClient *cli.PortClient) (*handlers.ControllersHandler, error) {
i, err := integration.GetIntegration(portClient, exporterConfig.StateKey)
if err != nil {
return nil, fmt.Errorf("error getting Port integration: %v", err)
}
if i.Config == nil {
return nil, errors.New("integration config is nil")
}
newHandler := handlers.NewControllersHandler(exporterConfig, i.Config, k8sClient, portClient)
newHandler.Handle()
return newHandler, nil
}
func main() {
k8sConfig := k8s.NewKubeConfig()
applicationConfig, err := config.NewConfiguration()
if err != nil {
klog.Fatalf("Error getting application config: %s", err.Error())
}
clientConfig, err := k8sConfig.ClientConfig()
if err != nil {
klog.Fatalf("Error getting K8s client config: %s", err.Error())
}
k8sClient, err := k8s.NewClient(clientConfig)
if err != nil {
klog.Fatalf("Error building K8s client: %s", err.Error())
}
portClient := cli.New(config.ApplicationConfig)
if err := defaults.InitIntegration(portClient, applicationConfig); err != nil {
klog.Fatalf("Error initializing Port integration: %s", err.Error())
}
eventListener, err := event_handler.CreateEventListener(applicationConfig.StateKey, applicationConfig.EventListenerType, portClient)
if err != nil {
klog.Fatalf("Error creating event listener: %s", err.Error())
}
klog.Info("Starting controllers handler")
err = event_handler.Start(eventListener, func() (event_handler.IStoppableRsync, error) {
return initiateHandler(applicationConfig, k8sClient, portClient)
})
if err != nil {
klog.Fatalf("Error starting event listener: %s", err.Error())
}
}
func init() {
klog.InitFlags(nil)
config.Init()
}