This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
/
register.go
200 lines (187 loc) · 7.65 KB
/
register.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package register
import (
"context"
"fmt"
"github.com/go-logr/logr"
"github.com/gorilla/mux"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"
"github.com/kubediag/kubediag/pkg/features"
kubecollector "github.com/kubediag/kubediag/pkg/processors/collector/kubernetes"
logcollector "github.com/kubediag/kubediag/pkg/processors/collector/log"
runtimecollector "github.com/kubediag/kubediag/pkg/processors/collector/runtime"
systemcollector "github.com/kubediag/kubediag/pkg/processors/collector/system"
diagnoser "github.com/kubediag/kubediag/pkg/processors/diagnoser"
kubediagnoser "github.com/kubediag/kubediag/pkg/processors/diagnoser/kubernetes"
runtimediagnoser "github.com/kubediag/kubediag/pkg/processors/diagnoser/runtime"
kuberecover "github.com/kubediag/kubediag/pkg/processors/recover/kubernetes"
)
// RegistryOption contains options of all kinds of Processors, it might be append in the future.
type RegistryOption struct {
// NodeName specifies the node name.
NodeName string
// DockerEndpoint specifies the docker endpoint.
DockerEndpoint string
// DataRoot is root directory of persistent kubediag data.
DataRoot string
// BindAddress is the address on which to advertise.
BindAddress string
}
// RegisterProcessors will initialize all processors and add into router to provide HTTP service.
func RegisterProcessors(mgr manager.Manager,
opts *RegistryOption,
featureGate features.KubeDiagFeatureGate,
router *mux.Router,
setupLog logr.Logger) error {
// Setup operation processors.
podListCollector := kubecollector.NewPodListCollector(
context.Background(),
ctrl.Log.WithName("processor/podListCollector"),
mgr.GetCache(),
opts.NodeName,
featureGate.Enabled(features.PodCollector),
)
podDetailCollector := kubecollector.NewPodDetailCollector(
context.Background(),
ctrl.Log.WithName("processor/podDetailCollector"),
mgr.GetCache(),
opts.NodeName,
featureGate.Enabled(features.PodCollector),
)
containerCollector, err := kubecollector.NewContainerCollector(
context.Background(),
ctrl.Log.WithName("processor/containerCollector"),
opts.DockerEndpoint,
featureGate.Enabled(features.ContainerCollector),
)
if err != nil {
setupLog.Error(err, "unable to create processor", "processors", "containerCollector")
return fmt.Errorf("unable to create processor: %v", err)
}
processCollector := systemcollector.NewProcessCollector(
context.Background(),
ctrl.Log.WithName("processor/processCollector"),
featureGate.Enabled(features.ProcessCollector),
)
dockerInfoCollector, err := kubecollector.NewDockerInfoCollector(
context.Background(),
ctrl.Log.WithName("processor/dockerInfoCollector"),
opts.DockerEndpoint,
featureGate.Enabled(features.DockerInfoCollector),
)
if err != nil {
setupLog.Error(err, "unable to create processor", "processors", "dockerInfoCollector")
return fmt.Errorf("unable to create processor: %v", err)
}
dockerdGoroutineCollector := runtimecollector.NewDockerdGoroutineCollector(
context.Background(),
ctrl.Log.WithName("processor/dockerdGoroutineCollector"),
opts.DataRoot,
featureGate.Enabled(features.DockerdGoroutineCollector),
)
containerdGoroutineCollector := runtimecollector.NewContainerdGoroutineCollector(
context.Background(),
ctrl.Log.WithName("processor/containerdGoroutineCollector"),
featureGate.Enabled(features.ContainerdGoroutineCollector),
)
mountInfoCollector := systemcollector.NewMountInfoCollector(
context.Background(),
ctrl.Log.WithName("processor/mountInfoCollector"),
featureGate.Enabled(features.MountInfoCollector),
)
nodeCordon := kuberecover.NewNodeCordon(
context.Background(),
ctrl.Log.WithName("processor/nodeCordon"),
mgr.GetClient(),
opts.NodeName,
featureGate.Enabled(features.NodeCordon),
)
goProfiler := runtimediagnoser.NewGoProfiler(
context.Background(),
ctrl.Log.WithName("processor/goProfiler"),
mgr.GetCache(),
opts.DataRoot,
opts.BindAddress,
featureGate.Enabled(features.GoProfiler),
)
coreFileProfiler, err := runtimediagnoser.NewCoreFileProfiler(
context.Background(),
ctrl.Log.WithName("processor/coreFileProfiler"),
opts.DockerEndpoint,
featureGate.Enabled(features.CoreFileProfiler),
opts.DataRoot)
if err != nil {
setupLog.Error(err, "unable to create processor", "processors", "coreFileProfiler")
return fmt.Errorf("unable to create processor: %v", err)
}
tcpdumpProfiler, err := runtimediagnoser.NewTcpdumpProfiler(
context.Background(),
ctrl.Log.WithName("processor/tcpdumpProfiler"),
opts.DockerEndpoint,
mgr.GetCache(),
opts.DataRoot,
featureGate.Enabled(features.TcpdumpProfiler),
)
if err != nil {
setupLog.Error(err, "unable to create processor", "processors", "tcpdumpProfiler")
return fmt.Errorf("unable to create processor: %v", err)
}
subpathRemountDiagnoser := kubediagnoser.NewSubPathRemountDiagnoser(
context.Background(),
ctrl.Log.WithName("processor/subpathRemountDiagnoser"),
mgr.GetCache(),
featureGate.Enabled(features.SubpathRemountDiagnoser),
)
subpathRemountRecover := kuberecover.NewSubPathRemountRecover(
context.Background(),
ctrl.Log.WithName("processor/subpathRemountRecover"),
featureGate.Enabled(features.SubpathRemountDiagnoser),
)
elasticsearchCollector := logcollector.NewElasticsearchCollector(
context.Background(),
ctrl.Log.WithName("processor/elasticsearchCollector"),
featureGate.Enabled(features.ElasticsearchCollector),
)
sonobuoyResultDiagnoser := diagnoser.NewSonobuoyResultDiagnoser(
context.Background(),
ctrl.Log.WithName("processor/sonobuoyResultDiagnoser"),
opts.DataRoot,
opts.BindAddress,
featureGate.Enabled(features.SonobuoyResultDiagnoser),
)
statefulsetDetailCollector := kubecollector.NewStatefuSetDetailCollector(
context.Background(),
ctrl.Log.WithName("/processor/statefulsetDetailCollector"),
mgr.GetCache(),
featureGate.Enabled(features.StatefulSetDetailCollector),
)
statefulsetStuck := kuberecover.NewStatefuSetStuck(
context.Background(),
ctrl.Log.WithName("/processor/statefulsetStuck"),
mgr.GetClient(),
featureGate.Enabled(features.StatefulSetStuck),
)
// Handlers for collecting information.
router.HandleFunc("/processor/podListCollector", podListCollector.Handler)
router.HandleFunc("/processor/podDetailCollector", podDetailCollector.Handler)
router.HandleFunc("/processor/containerCollector", containerCollector.Handler)
router.HandleFunc("/processor/processCollector", processCollector.Handler)
router.HandleFunc("/processor/dockerInfoCollector", dockerInfoCollector.Handler)
router.HandleFunc("/processor/dockerdGoroutineCollector", dockerdGoroutineCollector.Handler)
router.HandleFunc("/processor/containerdGoroutineCollector", containerdGoroutineCollector.Handler)
router.HandleFunc("/processor/mountInfoCollector", mountInfoCollector.Handler)
router.HandleFunc("/processor/elasticsearchCollector", elasticsearchCollector.Handler)
router.HandleFunc("/processor/statefulsetDetailCollector", statefulsetDetailCollector.Handler)
// Handlers for executing specified command.
router.HandleFunc("/processor/nodeCordon", nodeCordon.Handler)
// Handlers for profiling programs.
router.HandleFunc("/processor/coreFileProfiler", coreFileProfiler.Handler)
router.HandleFunc("/processor/goProfiler", goProfiler.Handler)
router.HandleFunc("/processor/tcpdumpProfiler", tcpdumpProfiler.Handler)
// Handlers for diagnosing programs
router.HandleFunc("/processor/subpathRemountDiagnoser", subpathRemountDiagnoser.Handler)
router.HandleFunc("/processor/subpathRemountRecover", subpathRemountRecover.Handler)
router.HandleFunc("/processor/statefulsetStuck", statefulsetStuck.Handler)
router.HandleFunc("/processor/sonobuoyResultDiagnoser", sonobuoyResultDiagnoser.Handler)
return nil
}