1/*
2Copyright The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17// Code generated by client-gen. DO NOT EDIT.
18
19package fake
20
21import (
22	"context"
23	json "encoding/json"
24	"fmt"
25
26	v1beta1 "k8s.io/api/coordination/v1beta1"
27	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28	labels "k8s.io/apimachinery/pkg/labels"
29	schema "k8s.io/apimachinery/pkg/runtime/schema"
30	types "k8s.io/apimachinery/pkg/types"
31	watch "k8s.io/apimachinery/pkg/watch"
32	coordinationv1beta1 "k8s.io/client-go/applyconfigurations/coordination/v1beta1"
33	testing "k8s.io/client-go/testing"
34)
35
36// FakeLeases implements LeaseInterface
37type FakeLeases struct {
38	Fake *FakeCoordinationV1beta1
39	ns   string
40}
41
42var leasesResource = schema.GroupVersionResource{Group: "coordination.k8s.io", Version: "v1beta1", Resource: "leases"}
43
44var leasesKind = schema.GroupVersionKind{Group: "coordination.k8s.io", Version: "v1beta1", Kind: "Lease"}
45
46// Get takes name of the lease, and returns the corresponding lease object, and an error if there is any.
47func (c *FakeLeases) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Lease, err error) {
48	obj, err := c.Fake.
49		Invokes(testing.NewGetAction(leasesResource, c.ns, name), &v1beta1.Lease{})
50
51	if obj == nil {
52		return nil, err
53	}
54	return obj.(*v1beta1.Lease), err
55}
56
57// List takes label and field selectors, and returns the list of Leases that match those selectors.
58func (c *FakeLeases) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.LeaseList, err error) {
59	obj, err := c.Fake.
60		Invokes(testing.NewListAction(leasesResource, leasesKind, c.ns, opts), &v1beta1.LeaseList{})
61
62	if obj == nil {
63		return nil, err
64	}
65
66	label, _, _ := testing.ExtractFromListOptions(opts)
67	if label == nil {
68		label = labels.Everything()
69	}
70	list := &v1beta1.LeaseList{ListMeta: obj.(*v1beta1.LeaseList).ListMeta}
71	for _, item := range obj.(*v1beta1.LeaseList).Items {
72		if label.Matches(labels.Set(item.Labels)) {
73			list.Items = append(list.Items, item)
74		}
75	}
76	return list, err
77}
78
79// Watch returns a watch.Interface that watches the requested leases.
80func (c *FakeLeases) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
81	return c.Fake.
82		InvokesWatch(testing.NewWatchAction(leasesResource, c.ns, opts))
83
84}
85
86// Create takes the representation of a lease and creates it.  Returns the server's representation of the lease, and an error, if there is any.
87func (c *FakeLeases) Create(ctx context.Context, lease *v1beta1.Lease, opts v1.CreateOptions) (result *v1beta1.Lease, err error) {
88	obj, err := c.Fake.
89		Invokes(testing.NewCreateAction(leasesResource, c.ns, lease), &v1beta1.Lease{})
90
91	if obj == nil {
92		return nil, err
93	}
94	return obj.(*v1beta1.Lease), err
95}
96
97// Update takes the representation of a lease and updates it. Returns the server's representation of the lease, and an error, if there is any.
98func (c *FakeLeases) Update(ctx context.Context, lease *v1beta1.Lease, opts v1.UpdateOptions) (result *v1beta1.Lease, err error) {
99	obj, err := c.Fake.
100		Invokes(testing.NewUpdateAction(leasesResource, c.ns, lease), &v1beta1.Lease{})
101
102	if obj == nil {
103		return nil, err
104	}
105	return obj.(*v1beta1.Lease), err
106}
107
108// Delete takes name of the lease and deletes it. Returns an error if one occurs.
109func (c *FakeLeases) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
110	_, err := c.Fake.
111		Invokes(testing.NewDeleteAction(leasesResource, c.ns, name), &v1beta1.Lease{})
112
113	return err
114}
115
116// DeleteCollection deletes a collection of objects.
117func (c *FakeLeases) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
118	action := testing.NewDeleteCollectionAction(leasesResource, c.ns, listOpts)
119
120	_, err := c.Fake.Invokes(action, &v1beta1.LeaseList{})
121	return err
122}
123
124// Patch applies the patch and returns the patched lease.
125func (c *FakeLeases) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Lease, err error) {
126	obj, err := c.Fake.
127		Invokes(testing.NewPatchSubresourceAction(leasesResource, c.ns, name, pt, data, subresources...), &v1beta1.Lease{})
128
129	if obj == nil {
130		return nil, err
131	}
132	return obj.(*v1beta1.Lease), err
133}
134
135// Apply takes the given apply declarative configuration, applies it and returns the applied lease.
136func (c *FakeLeases) Apply(ctx context.Context, lease *coordinationv1beta1.LeaseApplyConfiguration, opts v1.ApplyOptions) (result *v1beta1.Lease, err error) {
137	if lease == nil {
138		return nil, fmt.Errorf("lease provided to Apply must not be nil")
139	}
140	data, err := json.Marshal(lease)
141	if err != nil {
142		return nil, err
143	}
144	name := lease.Name
145	if name == nil {
146		return nil, fmt.Errorf("lease.Name must be provided to Apply")
147	}
148	obj, err := c.Fake.
149		Invokes(testing.NewPatchSubresourceAction(leasesResource, c.ns, *name, types.ApplyPatchType, data), &v1beta1.Lease{})
150
151	if obj == nil {
152		return nil, err
153	}
154	return obj.(*v1beta1.Lease), err
155}
156