forked from keptn/keptn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (56 loc) · 1.56 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
package main
import (
"os"
"github.com/keptn/keptn/go-sdk/pkg/sdk"
"github.com/keptn/keptn/webhook-service/handler"
"github.com/keptn/keptn/webhook-service/lib"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
const eventTypeWildcard = "*"
const serviceName = "webhook-service"
const envVarLogLevel = "LOG_LEVEL"
func main() {
if os.Getenv(envVarLogLevel) != "" {
logLevel, err := log.ParseLevel(os.Getenv(envVarLogLevel))
if err != nil {
log.WithError(err).Error("could not parse log level provided by 'LOG_LEVEL' env var")
} else {
log.SetLevel(logLevel)
}
}
kubeAPI, err := createKubeAPI()
if err != nil {
log.Fatalf("could not create kubernetes client: %s", err.Error())
}
secretReader := lib.NewK8sSecretReader(kubeAPI)
curlExecutor := lib.NewCmdCurlExecutor(
&lib.OSCmdExecutor{},
)
ipResolver := lib.NewIPResolver()
denyListProvider := lib.NewDenyListProvider(kubeAPI)
requestValidator := lib.NewRequestValidator(denyListProvider, ipResolver)
taskHandler := handler.NewTaskHandler(&lib.TemplateEngine{}, curlExecutor, requestValidator, secretReader)
log.Fatal(sdk.NewKeptn(
serviceName,
sdk.WithTaskHandler(
eventTypeWildcard,
taskHandler,
),
sdk.WithAutomaticResponse(false),
sdk.WithLogger(log.New()),
).Start())
}
func createKubeAPI() (*kubernetes.Clientset, error) {
var config *rest.Config
config, err := rest.InClusterConfig()
if err != nil {
return nil, err
}
kubeAPI, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
return kubeAPI, nil
}