-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 佑祎 <zzw261520@alibaba-inc.com>
- Loading branch information
1 parent
9071d03
commit 1736159
Showing
7 changed files
with
1,275 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package koordetector | ||
|
||
import ( | ||
"flag" | ||
"github.com/koordinator-sh/koordetector/cmd/koordetector/options" | ||
"github.com/koordinator-sh/koordetector/pkg/features" | ||
"github.com/koordinator-sh/koordetector/pkg/koordetector" | ||
"github.com/koordinator-sh/koordetector/pkg/koordetector/config" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/klog/v2" | ||
"net/http" | ||
"os" | ||
"sigs.k8s.io/controller-runtime/pkg/manager/signals" | ||
"time" | ||
) | ||
|
||
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 *options.EnablePprof { | ||
go func() { | ||
klog.V(4).Infof("Starting pprof on %v", *options.PprofAddr) | ||
if err := http.ListenAndServe(*options.PprofAddr, nil); err != nil { | ||
klog.Errorf("Unable to start pprof on %v, error: %v", *options.PprofAddr, err) | ||
} | ||
}() | ||
} | ||
|
||
if err := features.DefaultMutableKoordetectorFeatureGate.SetFromMap(cfg.FeatureGates); err != nil { | ||
klog.Fatalf("Unable to setup feature-gates: %v", err) | ||
} | ||
|
||
stopCtx := signals.SetupSignalHandler() | ||
|
||
|
||
// 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 := koordetector.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()) | ||
// 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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package options | ||
|
||
import "flag" | ||
|
||
var ( | ||
ServerAddr = flag.String("addr", ":9416", "port of koordlet server") | ||
EnablePprof = flag.Bool("enable-pprof", false, "Enable pprof for controller manager.") | ||
PprofAddr = flag.String("pprof-addr", ":9417", "The address the pprof binds to.") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.