Debian Codegraph @

pkg/client/external_metrics/fake/fake_client.go

raw symbols SCIP
1 /*
2 Copyright 2017 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package fake
18
19 import (
20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21 "k8s.io/apimachinery/pkg/labels"
22 "k8s.io/apimachinery/pkg/runtime/schema"
23 "k8s.io/client-go/testing"
24 "k8s.io/metrics/pkg/apis/external_metrics/v1beta1"
25 eclient "k8s.io/metrics/pkg/client/external_metrics"
26 )
27
28 type FakeExternalMetricsClient struct {
29 testing.Fake
30 }
31
32 func (c *FakeExternalMetricsClient) NamespacedMetrics(namespace string) eclient.MetricsInterface {
33 return &fakeNamespacedMetrics{
34 Fake: c,
35 ns: namespace,
36 }
37 }
38
39 type fakeNamespacedMetrics struct {
40 Fake *FakeExternalMetricsClient
41 ns string
42 }
43
44 func (m *fakeNamespacedMetrics) List(metricName string, metricSelector labels.Selector) (*v1beta1.ExternalMetricValueList, error) {
45 resource := schema.GroupResource{
46 Group: v1beta1.SchemeGroupVersion.Group,
47 Resource: metricName,
48 }
49 kind := schema.GroupKind{
50 Group: v1beta1.SchemeGroupVersion.Group,
51 Kind: "ExternalMetricValue",
52 }
53 action := testing.NewListAction(resource.WithVersion(""), kind.WithVersion(""), m.ns, metav1.ListOptions{LabelSelector: metricSelector.String()})
54 obj, err := m.Fake.
55 Invokes(action, &v1beta1.ExternalMetricValueList{})
56
57 if obj == nil {
58 return nil, err
59 }
60
61 return obj.(*v1beta1.ExternalMetricValueList), err
62 }