mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #80392 from tedyu/ver-client-cast
Check whether metricObj can be converted to *v1beta2.MetricValueList
This commit is contained in:
commit
c6101aba30
@ -18,11 +18,12 @@ package custom_metrics
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
"k8s.io/client-go/util/flowcontrol"
|
||||||
|
|
||||||
@ -122,7 +123,11 @@ func (m *rootScopedMetrics) getForNamespace(namespace string, metricName string,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res := metricObj.(*v1beta2.MetricValueList)
|
var res *v1beta2.MetricValueList
|
||||||
|
var ok bool
|
||||||
|
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
|
||||||
|
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
|
||||||
|
}
|
||||||
if len(res.Items) != 1 {
|
if len(res.Items) != 1 {
|
||||||
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
|
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
|
||||||
}
|
}
|
||||||
@ -160,7 +165,11 @@ func (m *rootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res := metricObj.(*v1beta2.MetricValueList)
|
var res *v1beta2.MetricValueList
|
||||||
|
var ok bool
|
||||||
|
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
|
||||||
|
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
|
||||||
|
}
|
||||||
if len(res.Items) != 1 {
|
if len(res.Items) != 1 {
|
||||||
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
|
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
|
||||||
}
|
}
|
||||||
@ -199,7 +208,11 @@ func (m *rootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res := metricObj.(*v1beta2.MetricValueList)
|
var res *v1beta2.MetricValueList
|
||||||
|
var ok bool
|
||||||
|
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
|
||||||
|
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
|
||||||
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +247,11 @@ func (m *namespacedMetrics) GetForObject(groupKind schema.GroupKind, name string
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res := metricObj.(*v1beta2.MetricValueList)
|
var res *v1beta2.MetricValueList
|
||||||
|
var ok bool
|
||||||
|
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
|
||||||
|
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
|
||||||
|
}
|
||||||
if len(res.Items) != 1 {
|
if len(res.Items) != 1 {
|
||||||
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
|
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
|
||||||
}
|
}
|
||||||
@ -269,6 +286,10 @@ func (m *namespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res := metricObj.(*v1beta2.MetricValueList)
|
var res *v1beta2.MetricValueList
|
||||||
|
var ok bool
|
||||||
|
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
|
||||||
|
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
|
||||||
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user