-
Notifications
You must be signed in to change notification settings - Fork 315
/
main.go
91 lines (74 loc) · 2.71 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"flag"
"net/http"
"os"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/apimachinery/pkg/util/wait"
_ "k8s.io/component-base/logs"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"github.com/koordinator-sh/koordinator/cmd/koordlet/options"
"github.com/koordinator-sh/koordinator/pkg/features"
agent "github.com/koordinator-sh/koordinator/pkg/koordlet"
"github.com/koordinator-sh/koordinator/pkg/koordlet/audit"
"github.com/koordinator-sh/koordinator/pkg/koordlet/config"
"github.com/koordinator-sh/koordinator/pkg/koordlet/runtimehooks"
)
func init() {}
func main() {
cfg := config.NewConfiguration()
cfg.InitFlags(flag.CommandLine)
flag.Parse()
go wait.Forever(klog.Flush, 5*time.Second)
defer klog.Flush()
if err := features.DefaultMutableKoordletFeatureGate.SetFromMap(cfg.FeatureGates); err != nil {
klog.Fatalf("Unable to setup feature-gates: %v", err)
}
if err := runtimehooks.DefaultMutableRuntimeHooksFG.SetFromMap(cfg.RuntimeHookConf.FeatureGates); err != nil {
klog.Fatalf("Unable to setup runtime-hooks: %v", err)
}
stopCtx := signals.SetupSignalHandler()
// setup the default auditor
if features.DefaultKoordletFeatureGate.Enabled(features.AuditEvents) {
audit.SetupDefaultAuditor(cfg.AuditConf, stopCtx.Done())
}
// Get a config to talk to the apiserver
klog.Info("Setting up client for koordlet")
err := cfg.InitClient()
if err != nil {
klog.Error("Unable to setup client config: ", err)
os.Exit(1)
}
d, err := agent.NewDaemon(cfg)
if err != nil {
klog.Error("Unable to setup koordlet daemon: ", err)
os.Exit(1)
}
// Expose the Prometheus http endpoint
go func() {
klog.Infof("Starting prometheus server on %v", *options.ServerAddr)
http.Handle("/metrics", promhttp.Handler())
if features.DefaultKoordletFeatureGate.Enabled(features.AuditEventsHTTPHandler) {
http.HandleFunc("/events", audit.HttpHandler())
}
// http.HandleFunc("/healthz", d.HealthzHandler())
klog.Fatalf("Prometheus monitoring failed: %v", http.ListenAndServe(*options.ServerAddr, nil))
}()
// Start the Cmd
klog.Info("Starting the koordlet daemon")
d.Run(stopCtx.Done())
}