@@ -18,11 +18,12 @@ package custom_metrics
18
18
19
19
import (
20
20
"fmt"
21
+ "reflect"
21
22
22
23
"k8s.io/apimachinery/pkg/api/meta"
23
24
"k8s.io/apimachinery/pkg/labels"
24
25
"k8s.io/apimachinery/pkg/runtime/schema"
25
- serializer "k8s.io/apimachinery/pkg/runtime/serializer"
26
+ "k8s.io/apimachinery/pkg/runtime/serializer"
26
27
"k8s.io/client-go/rest"
27
28
"k8s.io/client-go/util/flowcontrol"
28
29
@@ -122,7 +123,11 @@ func (m *rootScopedMetrics) getForNamespace(namespace string, metricName string,
122
123
return nil , err
123
124
}
124
125
125
- res := metricObj .(* v1beta2.MetricValueList )
126
+ var res * v1beta2.MetricValueList
127
+ var ok bool
128
+ if res , ok = metricObj .(* v1beta2.MetricValueList ); ! ok {
129
+ return nil , fmt .Errorf ("the custom metrics API server didn't return MetricValueList, the type is %v" , reflect .TypeOf (metricObj ))
130
+ }
126
131
if len (res .Items ) != 1 {
127
132
return nil , fmt .Errorf ("the custom metrics API server returned %v results when we asked for exactly one" , len (res .Items ))
128
133
}
@@ -160,7 +165,11 @@ func (m *rootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string
160
165
return nil , err
161
166
}
162
167
163
- res := metricObj .(* v1beta2.MetricValueList )
168
+ var res * v1beta2.MetricValueList
169
+ var ok bool
170
+ if res , ok = metricObj .(* v1beta2.MetricValueList ); ! ok {
171
+ return nil , fmt .Errorf ("the custom metrics API server didn't return MetricValueList, the type is %v" , reflect .TypeOf (metricObj ))
172
+ }
164
173
if len (res .Items ) != 1 {
165
174
return nil , fmt .Errorf ("the custom metrics API server returned %v results when we asked for exactly one" , len (res .Items ))
166
175
}
@@ -199,7 +208,11 @@ func (m *rootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
199
208
return nil , err
200
209
}
201
210
202
- res := metricObj .(* v1beta2.MetricValueList )
211
+ var res * v1beta2.MetricValueList
212
+ var ok bool
213
+ if res , ok = metricObj .(* v1beta2.MetricValueList ); ! ok {
214
+ return nil , fmt .Errorf ("the custom metrics API server didn't return MetricValueList, the type is %v" , reflect .TypeOf (metricObj ))
215
+ }
203
216
return res , nil
204
217
}
205
218
@@ -234,7 +247,11 @@ func (m *namespacedMetrics) GetForObject(groupKind schema.GroupKind, name string
234
247
return nil , err
235
248
}
236
249
237
- res := metricObj .(* v1beta2.MetricValueList )
250
+ var res * v1beta2.MetricValueList
251
+ var ok bool
252
+ if res , ok = metricObj .(* v1beta2.MetricValueList ); ! ok {
253
+ return nil , fmt .Errorf ("the custom metrics API server didn't return MetricValueList, the type is %v" , reflect .TypeOf (metricObj ))
254
+ }
238
255
if len (res .Items ) != 1 {
239
256
return nil , fmt .Errorf ("the custom metrics API server returned %v results when we asked for exactly one" , len (res .Items ))
240
257
}
@@ -269,6 +286,10 @@ func (m *namespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
269
286
return nil , err
270
287
}
271
288
272
- res := metricObj .(* v1beta2.MetricValueList )
289
+ var res * v1beta2.MetricValueList
290
+ var ok bool
291
+ if res , ok = metricObj .(* v1beta2.MetricValueList ); ! ok {
292
+ return nil , fmt .Errorf ("the custom metrics API server didn't return MetricValueList, the type is %v" , reflect .TypeOf (metricObj ))
293
+ }
273
294
return res , nil
274
295
}
0 commit comments