forked from kubernetes/node-problem-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_problem_detector.go
More file actions
82 lines (66 loc) · 2.7 KB
/
node_problem_detector.go
File metadata and controls
82 lines (66 loc) · 2.7 KB
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
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 (
"context"
"k8s.io/klog/v2"
_ "k8s.io/node-problem-detector/cmd/nodeproblemdetector/exporterplugins"
_ "k8s.io/node-problem-detector/cmd/nodeproblemdetector/problemdaemonplugins"
"k8s.io/node-problem-detector/cmd/options"
"k8s.io/node-problem-detector/pkg/exporters"
"k8s.io/node-problem-detector/pkg/exporters/k8sexporter"
"k8s.io/node-problem-detector/pkg/exporters/prometheusexporter"
"k8s.io/node-problem-detector/pkg/problemdaemon"
"k8s.io/node-problem-detector/pkg/problemdetector"
"k8s.io/node-problem-detector/pkg/types"
"k8s.io/node-problem-detector/pkg/util/metrics"
"k8s.io/node-problem-detector/pkg/version"
)
func npdMain(ctx context.Context, npdo *options.NodeProblemDetectorOptions) error {
if npdo.PrintVersion {
version.PrintVersion()
return nil
}
npdo.SetNodeNameOrDie()
npdo.SetConfigFromDeprecatedOptionsOrDie()
npdo.ValidOrDie()
// Initialize exporters first so that metric readers are registered before
// the meter provider is set up.
defaultExporters := []types.Exporter{}
if ke := k8sexporter.NewExporterOrDie(ctx, npdo); ke != nil {
defaultExporters = append(defaultExporters, ke)
klog.Info("K8s exporter started.")
}
if pe := prometheusexporter.NewExporterOrDie(npdo); pe != nil {
defaultExporters = append(defaultExporters, pe)
klog.Info("Prometheus exporter started.")
}
plugableExporters := exporters.NewExporters()
npdExporters := []types.Exporter{}
npdExporters = append(npdExporters, defaultExporters...)
npdExporters = append(npdExporters, plugableExporters...)
if len(npdExporters) == 0 {
klog.Fatalf("No exporter is successfully setup")
}
// Setup the meter provider after all exporters have registered their readers.
// This ensures metrics are properly exported to all configured backends.
metrics.SetupMeterProvider()
// Initialize problem daemons after meter provider is set up.
problemDaemons := problemdaemon.NewProblemDaemons(npdo.MonitorConfigPaths)
if len(problemDaemons) == 0 {
klog.Fatalf("No problem daemon is configured")
}
// Initialize NPD core.
p := problemdetector.NewProblemDetector(problemDaemons, npdExporters)
return p.Run(ctx)
}