@@ -38,40 +38,48 @@ const (
38
38
// kubeControllerManagerPort is the default port for the controller manager status server.
39
39
kubeControllerManagerPort = 10257
40
40
metricsProxyPod = "metrics-proxy"
41
+ // snapshotControllerPort is the port for the snapshot controller
42
+ snapshotControllerPort = 9102
41
43
)
42
44
43
45
// Collection is metrics collection of components
44
46
type Collection struct {
45
- APIServerMetrics APIServerMetrics
46
- ControllerManagerMetrics ControllerManagerMetrics
47
- KubeletMetrics map [string ]KubeletMetrics
48
- SchedulerMetrics SchedulerMetrics
49
- ClusterAutoscalerMetrics ClusterAutoscalerMetrics
47
+ APIServerMetrics APIServerMetrics
48
+ ControllerManagerMetrics ControllerManagerMetrics
49
+ SnapshotControllerMetrics SnapshotControllerMetrics
50
+ KubeletMetrics map [string ]KubeletMetrics
51
+ SchedulerMetrics SchedulerMetrics
52
+ ClusterAutoscalerMetrics ClusterAutoscalerMetrics
50
53
}
51
54
52
55
// Grabber provides functions which grab metrics from components
53
56
type Grabber struct {
54
- client clientset.Interface
55
- externalClient clientset.Interface
56
- grabFromAPIServer bool
57
- grabFromControllerManager bool
58
- grabFromKubelets bool
59
- grabFromScheduler bool
60
- grabFromClusterAutoscaler bool
61
- kubeScheduler string
62
- waitForSchedulerReadyOnce sync.Once
63
- kubeControllerManager string
64
- waitForControllerManagerReadyOnce sync.Once
57
+ client clientset.Interface
58
+ externalClient clientset.Interface
59
+ grabFromAPIServer bool
60
+ grabFromControllerManager bool
61
+ grabFromKubelets bool
62
+ grabFromScheduler bool
63
+ grabFromClusterAutoscaler bool
64
+ grabFromSnapshotController bool
65
+ kubeScheduler string
66
+ waitForSchedulerReadyOnce sync.Once
67
+ kubeControllerManager string
68
+ waitForControllerManagerReadyOnce sync.Once
69
+ snapshotController string
70
+ waitForSnapshotControllerReadyOnce sync.Once
65
71
}
66
72
67
73
// NewMetricsGrabber returns new metrics which are initialized.
68
- func NewMetricsGrabber (c clientset.Interface , ec clientset.Interface , kubelets bool , scheduler bool , controllers bool , apiServer bool , clusterAutoscaler bool ) (* Grabber , error ) {
74
+ func NewMetricsGrabber (c clientset.Interface , ec clientset.Interface , kubelets bool , scheduler bool , controllers bool , apiServer bool , clusterAutoscaler bool , snapshotController bool ) (* Grabber , error ) {
69
75
70
76
kubeScheduler := ""
71
77
kubeControllerManager := ""
78
+ snapshotControllerManager := ""
72
79
73
80
regKubeScheduler := regexp .MustCompile ("kube-scheduler-.*" )
74
81
regKubeControllerManager := regexp .MustCompile ("kube-controller-manager-.*" )
82
+ regSnapshotController := regexp .MustCompile ("volume-snapshot-controller.*" )
75
83
76
84
podList , err := c .CoreV1 ().Pods (metav1 .NamespaceSystem ).List (context .TODO (), metav1.ListOptions {})
77
85
if err != nil {
@@ -87,7 +95,10 @@ func NewMetricsGrabber(c clientset.Interface, ec clientset.Interface, kubelets b
87
95
if regKubeControllerManager .MatchString (pod .Name ) {
88
96
kubeControllerManager = pod .Name
89
97
}
90
- if kubeScheduler != "" && kubeControllerManager != "" {
98
+ if regSnapshotController .MatchString (pod .Name ) {
99
+ snapshotControllerManager = pod .Name
100
+ }
101
+ if kubeScheduler != "" && kubeControllerManager != "" && snapshotControllerManager != "" {
91
102
break
92
103
}
93
104
}
@@ -99,20 +110,26 @@ func NewMetricsGrabber(c clientset.Interface, ec clientset.Interface, kubelets b
99
110
controllers = false
100
111
klog .Warningf ("Can't find kube-controller-manager pod. Grabbing metrics from kube-controller-manager is disabled." )
101
112
}
113
+ if snapshotControllerManager == "" {
114
+ snapshotController = false
115
+ klog .Warningf ("Can't find snapshot-controller pod. Grabbing metrics from snapshot-controller is disabled." )
116
+ }
102
117
if ec == nil {
103
118
klog .Warningf ("Did not receive an external client interface. Grabbing metrics from ClusterAutoscaler is disabled." )
104
119
}
105
120
106
121
return & Grabber {
107
- client : c ,
108
- externalClient : ec ,
109
- grabFromAPIServer : apiServer ,
110
- grabFromControllerManager : controllers ,
111
- grabFromKubelets : kubelets ,
112
- grabFromScheduler : scheduler ,
113
- grabFromClusterAutoscaler : clusterAutoscaler ,
114
- kubeScheduler : kubeScheduler ,
115
- kubeControllerManager : kubeControllerManager ,
122
+ client : c ,
123
+ externalClient : ec ,
124
+ grabFromAPIServer : apiServer ,
125
+ grabFromControllerManager : controllers ,
126
+ grabFromKubelets : kubelets ,
127
+ grabFromScheduler : scheduler ,
128
+ grabFromClusterAutoscaler : clusterAutoscaler ,
129
+ grabFromSnapshotController : snapshotController ,
130
+ kubeScheduler : kubeScheduler ,
131
+ kubeControllerManager : kubeControllerManager ,
132
+ snapshotController : snapshotControllerManager ,
116
133
}, nil
117
134
}
118
135
@@ -220,6 +237,48 @@ func (g *Grabber) GrabFromControllerManager() (ControllerManagerMetrics, error)
220
237
return parseControllerManagerMetrics (output )
221
238
}
222
239
240
+ // GrabFromSnapshotController returns metrics from controller manager
241
+ func (g * Grabber ) GrabFromSnapshotController (podName string , port int ) (SnapshotControllerMetrics , error ) {
242
+ if g .snapshotController == "" {
243
+ return SnapshotControllerMetrics {}, fmt .Errorf ("SnapshotController pod is not registered. Skipping SnapshotController's metrics gathering" )
244
+ }
245
+
246
+ // Use overrides if provided via test config flags.
247
+ // Otherwise, use the default snapshot controller pod name and port.
248
+ if podName == "" {
249
+ podName = g .snapshotController
250
+ }
251
+ if port == 0 {
252
+ port = snapshotControllerPort
253
+ }
254
+
255
+ var err error
256
+ g .waitForSnapshotControllerReadyOnce .Do (func () {
257
+ if readyErr := e2epod .WaitForPodsReady (g .client , metav1 .NamespaceSystem , podName , 0 ); readyErr != nil {
258
+ err = fmt .Errorf ("error waiting for snapshot controller pod to be ready: %w" , readyErr )
259
+ return
260
+ }
261
+
262
+ var lastMetricsFetchErr error
263
+ if metricsWaitErr := wait .PollImmediate (time .Second , time .Minute , func () (bool , error ) {
264
+ _ , lastMetricsFetchErr = g .getMetricsFromPod (g .client , podName , metav1 .NamespaceSystem , port )
265
+ return lastMetricsFetchErr == nil , nil
266
+ }); metricsWaitErr != nil {
267
+ err = fmt .Errorf ("error waiting for snapshot controller pod to expose metrics: %v; %v" , metricsWaitErr , lastMetricsFetchErr )
268
+ return
269
+ }
270
+ })
271
+ if err != nil {
272
+ return SnapshotControllerMetrics {}, err
273
+ }
274
+
275
+ output , err := g .getMetricsFromPod (g .client , podName , metav1 .NamespaceSystem , port )
276
+ if err != nil {
277
+ return SnapshotControllerMetrics {}, err
278
+ }
279
+ return parseSnapshotControllerMetrics (output )
280
+ }
281
+
223
282
// GrabFromAPIServer returns metrics from API server
224
283
func (g * Grabber ) GrabFromAPIServer () (APIServerMetrics , error ) {
225
284
output , err := g .getMetricsFromAPIServer ()
@@ -257,6 +316,14 @@ func (g *Grabber) Grab() (Collection, error) {
257
316
result .ControllerManagerMetrics = metrics
258
317
}
259
318
}
319
+ if g .grabFromSnapshotController {
320
+ metrics , err := g .GrabFromSnapshotController (g .snapshotController , snapshotControllerPort )
321
+ if err != nil {
322
+ errs = append (errs , err )
323
+ } else {
324
+ result .SnapshotControllerMetrics = metrics
325
+ }
326
+ }
260
327
if g .grabFromClusterAutoscaler {
261
328
metrics , err := g .GrabFromClusterAutoscaler ()
262
329
if err != nil {
0 commit comments