1
16
17
18
19 package v1beta1
20
21 import (
22 "context"
23 json "encoding/json"
24 "fmt"
25 "time"
26
27 v1beta1 "k8s.io/api/discovery/v1beta1"
28 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29 types "k8s.io/apimachinery/pkg/types"
30 watch "k8s.io/apimachinery/pkg/watch"
31 discoveryv1beta1 "k8s.io/client-go/applyconfigurations/discovery/v1beta1"
32 scheme "k8s.io/client-go/kubernetes/scheme"
33 rest "k8s.io/client-go/rest"
34 )
35
36
37
38 type EndpointSlicesGetter interface {
39 EndpointSlices(namespace string) EndpointSliceInterface
40 }
41
42
43 type EndpointSliceInterface interface {
44 Create(ctx context.Context, endpointSlice *v1beta1.EndpointSlice, opts v1.CreateOptions) (*v1beta1.EndpointSlice, error)
45 Update(ctx context.Context, endpointSlice *v1beta1.EndpointSlice, opts v1.UpdateOptions) (*v1beta1.EndpointSlice, error)
46 Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
47 DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
48 Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.EndpointSlice, error)
49 List(ctx context.Context, opts v1.ListOptions) (*v1beta1.EndpointSliceList, error)
50 Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
51 Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.EndpointSlice, err error)
52 Apply(ctx context.Context, endpointSlice *discoveryv1beta1.EndpointSliceApplyConfiguration, opts v1.ApplyOptions) (result *v1beta1.EndpointSlice, err error)
53 EndpointSliceExpansion
54 }
55
56
57 type endpointSlices struct {
58 client rest.Interface
59 ns string
60 }
61
62
63 func newEndpointSlices(c *DiscoveryV1beta1Client, namespace string) *endpointSlices {
64 return &endpointSlices{
65 client: c.RESTClient(),
66 ns: namespace,
67 }
68 }
69
70
71 func (c *endpointSlices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.EndpointSlice, err error) {
72 result = &v1beta1.EndpointSlice{}
73 err = c.client.Get().
74 Namespace(c.ns).
75 Resource("endpointslices").
76 Name(name).
77 VersionedParams(&options, scheme.ParameterCodec).
78 Do(ctx).
79 Into(result)
80 return
81 }
82
83
84 func (c *endpointSlices) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.EndpointSliceList, err error) {
85 var timeout time.Duration
86 if opts.TimeoutSeconds != nil {
87 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
88 }
89 result = &v1beta1.EndpointSliceList{}
90 err = c.client.Get().
91 Namespace(c.ns).
92 Resource("endpointslices").
93 VersionedParams(&opts, scheme.ParameterCodec).
94 Timeout(timeout).
95 Do(ctx).
96 Into(result)
97 return
98 }
99
100
101 func (c *endpointSlices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
102 var timeout time.Duration
103 if opts.TimeoutSeconds != nil {
104 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
105 }
106 opts.Watch = true
107 return c.client.Get().
108 Namespace(c.ns).
109 Resource("endpointslices").
110 VersionedParams(&opts, scheme.ParameterCodec).
111 Timeout(timeout).
112 Watch(ctx)
113 }
114
115
116 func (c *endpointSlices) Create(ctx context.Context, endpointSlice *v1beta1.EndpointSlice, opts v1.CreateOptions) (result *v1beta1.EndpointSlice, err error) {
117 result = &v1beta1.EndpointSlice{}
118 err = c.client.Post().
119 Namespace(c.ns).
120 Resource("endpointslices").
121 VersionedParams(&opts, scheme.ParameterCodec).
122 Body(endpointSlice).
123 Do(ctx).
124 Into(result)
125 return
126 }
127
128
129 func (c *endpointSlices) Update(ctx context.Context, endpointSlice *v1beta1.EndpointSlice, opts v1.UpdateOptions) (result *v1beta1.EndpointSlice, err error) {
130 result = &v1beta1.EndpointSlice{}
131 err = c.client.Put().
132 Namespace(c.ns).
133 Resource("endpointslices").
134 Name(endpointSlice.Name).
135 VersionedParams(&opts, scheme.ParameterCodec).
136 Body(endpointSlice).
137 Do(ctx).
138 Into(result)
139 return
140 }
141
142
143 func (c *endpointSlices) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
144 return c.client.Delete().
145 Namespace(c.ns).
146 Resource("endpointslices").
147 Name(name).
148 Body(&opts).
149 Do(ctx).
150 Error()
151 }
152
153
154 func (c *endpointSlices) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
155 var timeout time.Duration
156 if listOpts.TimeoutSeconds != nil {
157 timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
158 }
159 return c.client.Delete().
160 Namespace(c.ns).
161 Resource("endpointslices").
162 VersionedParams(&listOpts, scheme.ParameterCodec).
163 Timeout(timeout).
164 Body(&opts).
165 Do(ctx).
166 Error()
167 }
168
169
170 func (c *endpointSlices) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.EndpointSlice, err error) {
171 result = &v1beta1.EndpointSlice{}
172 err = c.client.Patch(pt).
173 Namespace(c.ns).
174 Resource("endpointslices").
175 Name(name).
176 SubResource(subresources...).
177 VersionedParams(&opts, scheme.ParameterCodec).
178 Body(data).
179 Do(ctx).
180 Into(result)
181 return
182 }
183
184
185 func (c *endpointSlices) Apply(ctx context.Context, endpointSlice *discoveryv1beta1.EndpointSliceApplyConfiguration, opts v1.ApplyOptions) (result *v1beta1.EndpointSlice, err error) {
186 if endpointSlice == nil {
187 return nil, fmt.Errorf("endpointSlice provided to Apply must not be nil")
188 }
189 patchOpts := opts.ToPatchOptions()
190 data, err := json.Marshal(endpointSlice)
191 if err != nil {
192 return nil, err
193 }
194 name := endpointSlice.Name
195 if name == nil {
196 return nil, fmt.Errorf("endpointSlice.Name must be provided to Apply")
197 }
198 result = &v1beta1.EndpointSlice{}
199 err = c.client.Patch(types.ApplyPatchType).
200 Namespace(c.ns).
201 Resource("endpointslices").
202 Name(*name).
203 VersionedParams(&patchOpts, scheme.ParameterCodec).
204 Body(data).
205 Do(ctx).
206 Into(result)
207 return
208 }
209
View as plain text