-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (42 loc) · 1.35 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
package main
import (
"fmt"
utils "github.com/coveros/genoa-webhook/pkg"
"github.com/coveros/genoa-webhook/pkg/gitSync"
coverosv1alpha1 "github.com/coveros/genoa/api/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"net/http"
"os"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
var (
scheme = runtime.NewScheme()
logger = ctrl.Log.WithName("gitWebhook")
)
func init() {
_ = clientgoscheme.AddToScheme(scheme)
_ = coverosv1alpha1.AddToScheme(scheme)
}
func main() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
k8sClient, err := client.New(config.GetConfigOrDie(), client.Options{Scheme: scheme})
if err != nil {
logger.Error(err, "Failed to create a k8s client")
os.Exit(1)
}
logger.Info("Starting webhook server on port :8081...")
gitWebhook := gitSync.WebhookHandler{Client: k8sClient, Logger: logger, Notify: utils.NewNotifier()}
http.HandleFunc("/health", healthCheck)
http.HandleFunc("/webhook", gitWebhook.HandleWebhook)
if err := http.ListenAndServe(":8081", nil); err != nil {
logger.Error(err, "Failed to listen and serve for git webhooks on :8081")
os.Exit(1)
}
}
func healthCheck(wr http.ResponseWriter, req *http.Request) {
fmt.Fprintf(wr, "OK")
}