From 4be02881f530870e364c9975e00777de769061c4 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Fri, 18 Oct 2024 15:46:57 +0200 Subject: [PATCH] fix metrics aggregate controller --- .mockery.yaml | 9 +- internal/controller/metricsaggregate.go | 20 +- .../metricsaggregate_controller_test.go | 68 ++++-- pkg/test/mocks/Interface_mock.go | 180 ++++++++++++++ .../mocks/MetricsV1beta1Interface_mock.go | 179 ++++++++++++++ pkg/test/mocks/NodeMetricsInterface_mock.go | 220 ++++++++++++++++++ 6 files changed, 653 insertions(+), 23 deletions(-) create mode 100644 pkg/test/mocks/Interface_mock.go create mode 100644 pkg/test/mocks/MetricsV1beta1Interface_mock.go create mode 100644 pkg/test/mocks/NodeMetricsInterface_mock.go diff --git a/.mockery.yaml b/.mockery.yaml index 659e1d15..9b686caa 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -8,4 +8,11 @@ packages: Client: k8s.io/client-go/discovery: interfaces: - DiscoveryInterface: \ No newline at end of file + DiscoveryInterface: + k8s.io/metrics/pkg/client/clientset/versioned: + interfaces: + Interface: + k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1: + interfaces: + MetricsV1beta1Interface: + NodeMetricsInterface: \ No newline at end of file diff --git a/internal/controller/metricsaggregate.go b/internal/controller/metricsaggregate.go index 16e4f680..495c6a24 100644 --- a/internal/controller/metricsaggregate.go +++ b/internal/controller/metricsaggregate.go @@ -92,7 +92,8 @@ func (r *MetricsAggregateReconciler) Reconcile(ctx context.Context, req ctrl.Req availableResources := make(map[string]corev1.ResourceList) for _, n := range nodeList.Items { - availableResources[n.Name] = n.Status.Allocatable + // Total number, contains system reserved resources + availableResources[n.Name] = n.Status.Capacity } nodeDeploymentNodesMetrics := make([]v1beta1.NodeMetrics, 0) @@ -114,12 +115,17 @@ func (r *MetricsAggregateReconciler) Reconcile(ctx context.Context, req ctrl.Req // save metrics metrics.Status.Nodes = len(nodeList.Items) + var cpuAvailableMillicores, cpuTotalMillicores, memoryAvailableBytes, memoryTotalBytes int64 for _, nm := range nodeMetrics { - metrics.Status.CPUAvailableMillicores += nm.CPUAvailableMillicores - metrics.Status.CPUTotalMillicores += nm.CPUTotalMillicores - metrics.Status.MemoryAvailableBytes += nm.MemoryAvailableBytes - metrics.Status.MemoryTotalBytes += nm.MemoryTotalBytes + cpuAvailableMillicores += nm.CPUAvailableMillicores + cpuTotalMillicores += nm.CPUTotalMillicores + memoryAvailableBytes += nm.MemoryAvailableBytes + memoryTotalBytes += nm.MemoryTotalBytes } + metrics.Status.CPUAvailableMillicores = cpuAvailableMillicores + metrics.Status.CPUTotalMillicores = cpuTotalMillicores + metrics.Status.MemoryAvailableBytes = memoryAvailableBytes + metrics.Status.MemoryTotalBytes = memoryTotalBytes fraction := float64(metrics.Status.CPUTotalMillicores) / float64(metrics.Status.CPUAvailableMillicores) * 100 metrics.Status.CPUUsedPercentage = int64(fraction) @@ -191,8 +197,8 @@ func ConvertNodeMetrics(metrics []v1beta1.NodeMetrics, availableResources map[st if available, found := resourceMetricsInfo.Available[corev1.ResourceMemory]; found { quantityM := resourceMetricsInfo.Metrics[corev1.ResourceMemory] // memory in bytes - nodeMetric.MemoryTotalBytes = quantityM.Value() / (1024 * 1024) - nodeMetric.MemoryAvailableBytes = available.Value() / (1024 * 1024) + nodeMetric.MemoryTotalBytes = quantityM.Value() // in Bytes + nodeMetric.MemoryAvailableBytes = available.Value() // in Bytes } nodeMetrics = append(nodeMetrics, nodeMetric) } diff --git a/internal/controller/metricsaggregate_controller_test.go b/internal/controller/metricsaggregate_controller_test.go index 66cf4819..de40bcd4 100644 --- a/internal/controller/metricsaggregate_controller_test.go +++ b/internal/controller/metricsaggregate_controller_test.go @@ -5,6 +5,7 @@ import ( "github.com/pluralsh/deployment-operator/api/v1alpha1" "github.com/pluralsh/deployment-operator/pkg/test/mocks" + "github.com/stretchr/testify/mock" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -20,7 +21,6 @@ import ( var _ = Describe("MetricsAggregate Controller", Ordered, func() { Context("When reconciling a resource", func() { const ( - nodeMetricsName = "node-metrics" nodeName = "node" metricsAggregateName = "global" namespace = "default" @@ -39,28 +39,35 @@ var _ = Describe("MetricsAggregate Controller", Ordered, func() { }, } - nodeMetrics := types.NamespacedName{Name: nodeMetricsName, Namespace: namespace} + nodeMetrics := types.NamespacedName{Name: nodeName, Namespace: namespace} node := types.NamespacedName{Name: nodeName, Namespace: namespace} metricsAggregate := types.NamespacedName{Name: metricsAggregateName, Namespace: namespace} + defaultNodeMetrics := v1beta1.NodeMetrics{ + ObjectMeta: metav1.ObjectMeta{ + Name: nodeName, + Namespace: namespace, + }, + Timestamp: metav1.Time{}, + Window: metav1.Duration{}, + Usage: map[corev1.ResourceName]resource.Quantity{ + "cpu": resource.MustParse("100m"), + "memory": resource.MustParse("100Mi"), + }, + } + defaultNodeMetricsList := &v1beta1.NodeMetricsList{ + Items: []v1beta1.NodeMetrics{ + defaultNodeMetrics, + }, + } + nm := &v1beta1.NodeMetrics{} n := &corev1.Node{} BeforeAll(func() { By("Creating node metrics") err := kClient.Get(ctx, nodeMetrics, nm) if err != nil && errors.IsNotFound(err) { - Expect(kClient.Create(ctx, &v1beta1.NodeMetrics{ - ObjectMeta: metav1.ObjectMeta{ - Name: nodeMetricsName, - Namespace: namespace, - }, - Timestamp: metav1.Time{}, - Window: metav1.Duration{}, - Usage: map[corev1.ResourceName]resource.Quantity{ - "cpu": resource.MustParse("100m"), - "memory": resource.MustParse("100Mi"), - }, - })).To(Succeed()) + Expect(kClient.Create(ctx, &defaultNodeMetrics)).To(Succeed()) } By("Creating Node") @@ -74,7 +81,8 @@ var _ = Describe("MetricsAggregate Controller", Ordered, func() { Spec: corev1.NodeSpec{}, Status: corev1.NodeStatus{ Capacity: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("100m"), + corev1.ResourceCPU: resource.MustParse("1"), + corev1.ResourceMemory: resource.MustParse("1Gi"), }, }, } @@ -104,5 +112,35 @@ var _ = Describe("MetricsAggregate Controller", Ordered, func() { metrics := &v1alpha1.MetricsAggregate{} Expect(kClient.Get(ctx, metricsAggregate, metrics)).NotTo(HaveOccurred()) }) + + It("should create global metrics aggregate", func() { + metricsClient := mocks.NewInterfaceMock(mocks.TestingT) + metricsV1beta1 := mocks.NewMetricsV1beta1InterfaceMock(mocks.TestingT) + nodeMetricses := mocks.NewNodeMetricsInterfaceMock(mocks.TestingT) + metricsClient.On("MetricsV1beta1").Return(metricsV1beta1) + metricsV1beta1.On("NodeMetricses").Return(nodeMetricses) + nodeMetricses.On("List", mock.Anything, mock.Anything).Return(defaultNodeMetricsList, nil) + + discoveryClient := mocks.NewDiscoveryInterfaceMock(mocks.TestingT) + discoveryClient.On("ServerGroups").Return(apiGroups, nil) + + r := MetricsAggregateReconciler{ + Client: kClient, + Scheme: kClient.Scheme(), + DiscoveryClient: discoveryClient, + MetricsClient: metricsClient, + } + _, err := r.Reconcile(ctx, reconcile.Request{NamespacedName: metricsAggregate}) + Expect(err).NotTo(HaveOccurred()) + metrics := &v1alpha1.MetricsAggregate{} + Expect(kClient.Get(ctx, metricsAggregate, metrics)).NotTo(HaveOccurred()) + Expect(metrics.Status.Nodes).Should(Equal(1)) + Expect(metrics.Status.CPUAvailableMillicores).Should(Equal(int64(1000))) + Expect(metrics.Status.CPUTotalMillicores).Should(Equal(int64(100))) + Expect(metrics.Status.CPUUsedPercentage).Should(Equal(int64(10))) + Expect(metrics.Status.MemoryAvailableBytes).Should(Equal(int64(1073741824))) + Expect(metrics.Status.MemoryTotalBytes).Should(Equal(int64(104857600))) + Expect(metrics.Status.MemoryUsedPercentage).Should(Equal(int64(9))) + }) }) }) diff --git a/pkg/test/mocks/Interface_mock.go b/pkg/test/mocks/Interface_mock.go new file mode 100644 index 00000000..eb92fb53 --- /dev/null +++ b/pkg/test/mocks/Interface_mock.go @@ -0,0 +1,180 @@ +// Code generated by mockery v2.45.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + discovery "k8s.io/client-go/discovery" + + v1alpha1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1alpha1" + + v1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" +) + +// InterfaceMock is an autogenerated mock type for the Interface type +type InterfaceMock struct { + mock.Mock +} + +type InterfaceMock_Expecter struct { + mock *mock.Mock +} + +func (_m *InterfaceMock) EXPECT() *InterfaceMock_Expecter { + return &InterfaceMock_Expecter{mock: &_m.Mock} +} + +// Discovery provides a mock function with given fields: +func (_m *InterfaceMock) Discovery() discovery.DiscoveryInterface { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Discovery") + } + + var r0 discovery.DiscoveryInterface + if rf, ok := ret.Get(0).(func() discovery.DiscoveryInterface); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(discovery.DiscoveryInterface) + } + } + + return r0 +} + +// InterfaceMock_Discovery_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Discovery' +type InterfaceMock_Discovery_Call struct { + *mock.Call +} + +// Discovery is a helper method to define mock.On call +func (_e *InterfaceMock_Expecter) Discovery() *InterfaceMock_Discovery_Call { + return &InterfaceMock_Discovery_Call{Call: _e.mock.On("Discovery")} +} + +func (_c *InterfaceMock_Discovery_Call) Run(run func()) *InterfaceMock_Discovery_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *InterfaceMock_Discovery_Call) Return(_a0 discovery.DiscoveryInterface) *InterfaceMock_Discovery_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *InterfaceMock_Discovery_Call) RunAndReturn(run func() discovery.DiscoveryInterface) *InterfaceMock_Discovery_Call { + _c.Call.Return(run) + return _c +} + +// MetricsV1alpha1 provides a mock function with given fields: +func (_m *InterfaceMock) MetricsV1alpha1() v1alpha1.MetricsV1alpha1Interface { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MetricsV1alpha1") + } + + var r0 v1alpha1.MetricsV1alpha1Interface + if rf, ok := ret.Get(0).(func() v1alpha1.MetricsV1alpha1Interface); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(v1alpha1.MetricsV1alpha1Interface) + } + } + + return r0 +} + +// InterfaceMock_MetricsV1alpha1_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MetricsV1alpha1' +type InterfaceMock_MetricsV1alpha1_Call struct { + *mock.Call +} + +// MetricsV1alpha1 is a helper method to define mock.On call +func (_e *InterfaceMock_Expecter) MetricsV1alpha1() *InterfaceMock_MetricsV1alpha1_Call { + return &InterfaceMock_MetricsV1alpha1_Call{Call: _e.mock.On("MetricsV1alpha1")} +} + +func (_c *InterfaceMock_MetricsV1alpha1_Call) Run(run func()) *InterfaceMock_MetricsV1alpha1_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *InterfaceMock_MetricsV1alpha1_Call) Return(_a0 v1alpha1.MetricsV1alpha1Interface) *InterfaceMock_MetricsV1alpha1_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *InterfaceMock_MetricsV1alpha1_Call) RunAndReturn(run func() v1alpha1.MetricsV1alpha1Interface) *InterfaceMock_MetricsV1alpha1_Call { + _c.Call.Return(run) + return _c +} + +// MetricsV1beta1 provides a mock function with given fields: +func (_m *InterfaceMock) MetricsV1beta1() v1beta1.MetricsV1beta1Interface { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MetricsV1beta1") + } + + var r0 v1beta1.MetricsV1beta1Interface + if rf, ok := ret.Get(0).(func() v1beta1.MetricsV1beta1Interface); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(v1beta1.MetricsV1beta1Interface) + } + } + + return r0 +} + +// InterfaceMock_MetricsV1beta1_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MetricsV1beta1' +type InterfaceMock_MetricsV1beta1_Call struct { + *mock.Call +} + +// MetricsV1beta1 is a helper method to define mock.On call +func (_e *InterfaceMock_Expecter) MetricsV1beta1() *InterfaceMock_MetricsV1beta1_Call { + return &InterfaceMock_MetricsV1beta1_Call{Call: _e.mock.On("MetricsV1beta1")} +} + +func (_c *InterfaceMock_MetricsV1beta1_Call) Run(run func()) *InterfaceMock_MetricsV1beta1_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *InterfaceMock_MetricsV1beta1_Call) Return(_a0 v1beta1.MetricsV1beta1Interface) *InterfaceMock_MetricsV1beta1_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *InterfaceMock_MetricsV1beta1_Call) RunAndReturn(run func() v1beta1.MetricsV1beta1Interface) *InterfaceMock_MetricsV1beta1_Call { + _c.Call.Return(run) + return _c +} + +// NewInterfaceMock creates a new instance of InterfaceMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewInterfaceMock(t interface { + mock.TestingT + Cleanup(func()) +}) *InterfaceMock { + mock := &InterfaceMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/test/mocks/MetricsV1beta1Interface_mock.go b/pkg/test/mocks/MetricsV1beta1Interface_mock.go new file mode 100644 index 00000000..e035b481 --- /dev/null +++ b/pkg/test/mocks/MetricsV1beta1Interface_mock.go @@ -0,0 +1,179 @@ +// Code generated by mockery v2.45.1. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + rest "k8s.io/client-go/rest" + + v1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" +) + +// MetricsV1beta1InterfaceMock is an autogenerated mock type for the MetricsV1beta1Interface type +type MetricsV1beta1InterfaceMock struct { + mock.Mock +} + +type MetricsV1beta1InterfaceMock_Expecter struct { + mock *mock.Mock +} + +func (_m *MetricsV1beta1InterfaceMock) EXPECT() *MetricsV1beta1InterfaceMock_Expecter { + return &MetricsV1beta1InterfaceMock_Expecter{mock: &_m.Mock} +} + +// NodeMetricses provides a mock function with given fields: +func (_m *MetricsV1beta1InterfaceMock) NodeMetricses() v1beta1.NodeMetricsInterface { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for NodeMetricses") + } + + var r0 v1beta1.NodeMetricsInterface + if rf, ok := ret.Get(0).(func() v1beta1.NodeMetricsInterface); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(v1beta1.NodeMetricsInterface) + } + } + + return r0 +} + +// MetricsV1beta1InterfaceMock_NodeMetricses_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeMetricses' +type MetricsV1beta1InterfaceMock_NodeMetricses_Call struct { + *mock.Call +} + +// NodeMetricses is a helper method to define mock.On call +func (_e *MetricsV1beta1InterfaceMock_Expecter) NodeMetricses() *MetricsV1beta1InterfaceMock_NodeMetricses_Call { + return &MetricsV1beta1InterfaceMock_NodeMetricses_Call{Call: _e.mock.On("NodeMetricses")} +} + +func (_c *MetricsV1beta1InterfaceMock_NodeMetricses_Call) Run(run func()) *MetricsV1beta1InterfaceMock_NodeMetricses_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MetricsV1beta1InterfaceMock_NodeMetricses_Call) Return(_a0 v1beta1.NodeMetricsInterface) *MetricsV1beta1InterfaceMock_NodeMetricses_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MetricsV1beta1InterfaceMock_NodeMetricses_Call) RunAndReturn(run func() v1beta1.NodeMetricsInterface) *MetricsV1beta1InterfaceMock_NodeMetricses_Call { + _c.Call.Return(run) + return _c +} + +// PodMetricses provides a mock function with given fields: namespace +func (_m *MetricsV1beta1InterfaceMock) PodMetricses(namespace string) v1beta1.PodMetricsInterface { + ret := _m.Called(namespace) + + if len(ret) == 0 { + panic("no return value specified for PodMetricses") + } + + var r0 v1beta1.PodMetricsInterface + if rf, ok := ret.Get(0).(func(string) v1beta1.PodMetricsInterface); ok { + r0 = rf(namespace) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(v1beta1.PodMetricsInterface) + } + } + + return r0 +} + +// MetricsV1beta1InterfaceMock_PodMetricses_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PodMetricses' +type MetricsV1beta1InterfaceMock_PodMetricses_Call struct { + *mock.Call +} + +// PodMetricses is a helper method to define mock.On call +// - namespace string +func (_e *MetricsV1beta1InterfaceMock_Expecter) PodMetricses(namespace interface{}) *MetricsV1beta1InterfaceMock_PodMetricses_Call { + return &MetricsV1beta1InterfaceMock_PodMetricses_Call{Call: _e.mock.On("PodMetricses", namespace)} +} + +func (_c *MetricsV1beta1InterfaceMock_PodMetricses_Call) Run(run func(namespace string)) *MetricsV1beta1InterfaceMock_PodMetricses_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MetricsV1beta1InterfaceMock_PodMetricses_Call) Return(_a0 v1beta1.PodMetricsInterface) *MetricsV1beta1InterfaceMock_PodMetricses_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MetricsV1beta1InterfaceMock_PodMetricses_Call) RunAndReturn(run func(string) v1beta1.PodMetricsInterface) *MetricsV1beta1InterfaceMock_PodMetricses_Call { + _c.Call.Return(run) + return _c +} + +// RESTClient provides a mock function with given fields: +func (_m *MetricsV1beta1InterfaceMock) RESTClient() rest.Interface { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RESTClient") + } + + var r0 rest.Interface + if rf, ok := ret.Get(0).(func() rest.Interface); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(rest.Interface) + } + } + + return r0 +} + +// MetricsV1beta1InterfaceMock_RESTClient_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RESTClient' +type MetricsV1beta1InterfaceMock_RESTClient_Call struct { + *mock.Call +} + +// RESTClient is a helper method to define mock.On call +func (_e *MetricsV1beta1InterfaceMock_Expecter) RESTClient() *MetricsV1beta1InterfaceMock_RESTClient_Call { + return &MetricsV1beta1InterfaceMock_RESTClient_Call{Call: _e.mock.On("RESTClient")} +} + +func (_c *MetricsV1beta1InterfaceMock_RESTClient_Call) Run(run func()) *MetricsV1beta1InterfaceMock_RESTClient_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MetricsV1beta1InterfaceMock_RESTClient_Call) Return(_a0 rest.Interface) *MetricsV1beta1InterfaceMock_RESTClient_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MetricsV1beta1InterfaceMock_RESTClient_Call) RunAndReturn(run func() rest.Interface) *MetricsV1beta1InterfaceMock_RESTClient_Call { + _c.Call.Return(run) + return _c +} + +// NewMetricsV1beta1InterfaceMock creates a new instance of MetricsV1beta1InterfaceMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMetricsV1beta1InterfaceMock(t interface { + mock.TestingT + Cleanup(func()) +}) *MetricsV1beta1InterfaceMock { + mock := &MetricsV1beta1InterfaceMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/test/mocks/NodeMetricsInterface_mock.go b/pkg/test/mocks/NodeMetricsInterface_mock.go new file mode 100644 index 00000000..1d75ae44 --- /dev/null +++ b/pkg/test/mocks/NodeMetricsInterface_mock.go @@ -0,0 +1,220 @@ +// Code generated by mockery v2.45.1. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" + + watch "k8s.io/apimachinery/pkg/watch" +) + +// NodeMetricsInterfaceMock is an autogenerated mock type for the NodeMetricsInterface type +type NodeMetricsInterfaceMock struct { + mock.Mock +} + +type NodeMetricsInterfaceMock_Expecter struct { + mock *mock.Mock +} + +func (_m *NodeMetricsInterfaceMock) EXPECT() *NodeMetricsInterfaceMock_Expecter { + return &NodeMetricsInterfaceMock_Expecter{mock: &_m.Mock} +} + +// Get provides a mock function with given fields: ctx, name, opts +func (_m *NodeMetricsInterfaceMock) Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.NodeMetrics, error) { + ret := _m.Called(ctx, name, opts) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *v1beta1.NodeMetrics + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, v1.GetOptions) (*v1beta1.NodeMetrics, error)); ok { + return rf(ctx, name, opts) + } + if rf, ok := ret.Get(0).(func(context.Context, string, v1.GetOptions) *v1beta1.NodeMetrics); ok { + r0 = rf(ctx, name, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1beta1.NodeMetrics) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, v1.GetOptions) error); ok { + r1 = rf(ctx, name, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeMetricsInterfaceMock_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type NodeMetricsInterfaceMock_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - opts v1.GetOptions +func (_e *NodeMetricsInterfaceMock_Expecter) Get(ctx interface{}, name interface{}, opts interface{}) *NodeMetricsInterfaceMock_Get_Call { + return &NodeMetricsInterfaceMock_Get_Call{Call: _e.mock.On("Get", ctx, name, opts)} +} + +func (_c *NodeMetricsInterfaceMock_Get_Call) Run(run func(ctx context.Context, name string, opts v1.GetOptions)) *NodeMetricsInterfaceMock_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(v1.GetOptions)) + }) + return _c +} + +func (_c *NodeMetricsInterfaceMock_Get_Call) Return(_a0 *v1beta1.NodeMetrics, _a1 error) *NodeMetricsInterfaceMock_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeMetricsInterfaceMock_Get_Call) RunAndReturn(run func(context.Context, string, v1.GetOptions) (*v1beta1.NodeMetrics, error)) *NodeMetricsInterfaceMock_Get_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, opts +func (_m *NodeMetricsInterfaceMock) List(ctx context.Context, opts v1.ListOptions) (*v1beta1.NodeMetricsList, error) { + ret := _m.Called(ctx, opts) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 *v1beta1.NodeMetricsList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, v1.ListOptions) (*v1beta1.NodeMetricsList, error)); ok { + return rf(ctx, opts) + } + if rf, ok := ret.Get(0).(func(context.Context, v1.ListOptions) *v1beta1.NodeMetricsList); ok { + r0 = rf(ctx, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1beta1.NodeMetricsList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, v1.ListOptions) error); ok { + r1 = rf(ctx, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeMetricsInterfaceMock_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type NodeMetricsInterfaceMock_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - opts v1.ListOptions +func (_e *NodeMetricsInterfaceMock_Expecter) List(ctx interface{}, opts interface{}) *NodeMetricsInterfaceMock_List_Call { + return &NodeMetricsInterfaceMock_List_Call{Call: _e.mock.On("List", ctx, opts)} +} + +func (_c *NodeMetricsInterfaceMock_List_Call) Run(run func(ctx context.Context, opts v1.ListOptions)) *NodeMetricsInterfaceMock_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(v1.ListOptions)) + }) + return _c +} + +func (_c *NodeMetricsInterfaceMock_List_Call) Return(_a0 *v1beta1.NodeMetricsList, _a1 error) *NodeMetricsInterfaceMock_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeMetricsInterfaceMock_List_Call) RunAndReturn(run func(context.Context, v1.ListOptions) (*v1beta1.NodeMetricsList, error)) *NodeMetricsInterfaceMock_List_Call { + _c.Call.Return(run) + return _c +} + +// Watch provides a mock function with given fields: ctx, opts +func (_m *NodeMetricsInterfaceMock) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + ret := _m.Called(ctx, opts) + + if len(ret) == 0 { + panic("no return value specified for Watch") + } + + var r0 watch.Interface + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, v1.ListOptions) (watch.Interface, error)); ok { + return rf(ctx, opts) + } + if rf, ok := ret.Get(0).(func(context.Context, v1.ListOptions) watch.Interface); ok { + r0 = rf(ctx, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(watch.Interface) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, v1.ListOptions) error); ok { + r1 = rf(ctx, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeMetricsInterfaceMock_Watch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Watch' +type NodeMetricsInterfaceMock_Watch_Call struct { + *mock.Call +} + +// Watch is a helper method to define mock.On call +// - ctx context.Context +// - opts v1.ListOptions +func (_e *NodeMetricsInterfaceMock_Expecter) Watch(ctx interface{}, opts interface{}) *NodeMetricsInterfaceMock_Watch_Call { + return &NodeMetricsInterfaceMock_Watch_Call{Call: _e.mock.On("Watch", ctx, opts)} +} + +func (_c *NodeMetricsInterfaceMock_Watch_Call) Run(run func(ctx context.Context, opts v1.ListOptions)) *NodeMetricsInterfaceMock_Watch_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(v1.ListOptions)) + }) + return _c +} + +func (_c *NodeMetricsInterfaceMock_Watch_Call) Return(_a0 watch.Interface, _a1 error) *NodeMetricsInterfaceMock_Watch_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeMetricsInterfaceMock_Watch_Call) RunAndReturn(run func(context.Context, v1.ListOptions) (watch.Interface, error)) *NodeMetricsInterfaceMock_Watch_Call { + _c.Call.Return(run) + return _c +} + +// NewNodeMetricsInterfaceMock creates a new instance of NodeMetricsInterfaceMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewNodeMetricsInterfaceMock(t interface { + mock.TestingT + Cleanup(func()) +}) *NodeMetricsInterfaceMock { + mock := &NodeMetricsInterfaceMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}