Skip to content

Commit 4ec75b4

Browse files
hyschumiliudongsheng
authored and
liudongsheng
committed
refactor: client keep same code style
1 parent 273e608 commit 4ec75b4

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

pkg/client/typed_client.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (c *typedClient) Create(ctx context.Context, obj Object, opts ...CreateOpti
4242

4343
createOpts := &CreateOptions{}
4444
createOpts.ApplyOptions(opts)
45+
4546
return o.Post().
4647
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
4748
Resource(o.resource()).
@@ -60,6 +61,7 @@ func (c *typedClient) Update(ctx context.Context, obj Object, opts ...UpdateOpti
6061

6162
updateOpts := &UpdateOptions{}
6263
updateOpts.ApplyOptions(opts)
64+
6365
return o.Put().
6466
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
6567
Resource(o.resource()).
@@ -121,11 +123,13 @@ func (c *typedClient) Patch(ctx context.Context, obj Object, patch Patch, opts .
121123
}
122124

123125
patchOpts := &PatchOptions{}
126+
patchOpts.ApplyOptions(opts)
127+
124128
return o.Patch(patch.Type()).
125129
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
126130
Resource(o.resource()).
127131
Name(o.GetName()).
128-
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), c.paramCodec).
132+
VersionedParams(patchOpts.AsPatchOptions(), c.paramCodec).
129133
Body(data).
130134
Do(ctx).
131135
Into(obj)
@@ -149,8 +153,10 @@ func (c *typedClient) List(ctx context.Context, obj ObjectList, opts ...ListOpti
149153
if err != nil {
150154
return err
151155
}
156+
152157
listOpts := ListOptions{}
153158
listOpts.ApplyOptions(opts)
159+
154160
return r.Get().
155161
NamespaceIfScoped(listOpts.Namespace, r.isNamespaced()).
156162
Resource(r.resource()).
@@ -169,13 +175,16 @@ func (c *typedClient) UpdateStatus(ctx context.Context, obj Object, opts ...Upda
169175
// wrapped to improve the UX ?
170176
// It will be nice to receive an error saying the object doesn't implement
171177
// status subresource and check CRD definition
178+
updateOpts := &UpdateOptions{}
179+
updateOpts.ApplyOptions(opts)
180+
172181
return o.Put().
173182
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
174183
Resource(o.resource()).
175184
Name(o.GetName()).
176185
SubResource("status").
177186
Body(obj).
178-
VersionedParams((&UpdateOptions{}).ApplyOptions(opts).AsUpdateOptions(), c.paramCodec).
187+
VersionedParams(updateOpts.AsUpdateOptions(), c.paramCodec).
179188
Do(ctx).
180189
Into(obj)
181190
}
@@ -193,13 +202,15 @@ func (c *typedClient) PatchStatus(ctx context.Context, obj Object, patch Patch,
193202
}
194203

195204
patchOpts := &PatchOptions{}
205+
patchOpts.ApplyOptions(opts)
206+
196207
return o.Patch(patch.Type()).
197208
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
198209
Resource(o.resource()).
199210
Name(o.GetName()).
200211
SubResource("status").
201212
Body(data).
202-
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), c.paramCodec).
213+
VersionedParams(patchOpts.AsPatchOptions(), c.paramCodec).
203214
Do(ctx).
204215
Into(obj)
205216
}

pkg/client/unstructured_client.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (uc *unstructuredClient) Create(ctx context.Context, obj Object, opts ...Cr
5252

5353
createOpts := &CreateOptions{}
5454
createOpts.ApplyOptions(opts)
55+
5556
result := o.Post().
5657
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
5758
Resource(o.resource()).
@@ -80,6 +81,7 @@ func (uc *unstructuredClient) Update(ctx context.Context, obj Object, opts ...Up
8081

8182
updateOpts := UpdateOptions{}
8283
updateOpts.ApplyOptions(opts)
84+
8385
result := o.Put().
8486
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
8587
Resource(o.resource()).
@@ -107,6 +109,7 @@ func (uc *unstructuredClient) Delete(ctx context.Context, obj Object, opts ...De
107109

108110
deleteOpts := DeleteOptions{}
109111
deleteOpts.ApplyOptions(opts)
112+
110113
return o.Delete().
111114
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
112115
Resource(o.resource()).
@@ -130,6 +133,7 @@ func (uc *unstructuredClient) DeleteAllOf(ctx context.Context, obj Object, opts
130133

131134
deleteAllOfOpts := DeleteAllOfOptions{}
132135
deleteAllOfOpts.ApplyOptions(opts)
136+
133137
return o.Delete().
134138
NamespaceIfScoped(deleteAllOfOpts.ListOptions.Namespace, o.isNamespaced()).
135139
Resource(o.resource()).
@@ -157,11 +161,13 @@ func (uc *unstructuredClient) Patch(ctx context.Context, obj Object, patch Patch
157161
}
158162

159163
patchOpts := &PatchOptions{}
164+
patchOpts.ApplyOptions(opts)
165+
160166
return o.Patch(patch.Type()).
161167
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
162168
Resource(o.resource()).
163169
Name(o.GetName()).
164-
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), uc.paramCodec).
170+
VersionedParams(patchOpts.AsPatchOptions(), uc.paramCodec).
165171
Body(data).
166172
Do(ctx).
167173
Into(obj)
@@ -205,14 +211,14 @@ func (uc *unstructuredClient) List(ctx context.Context, obj ObjectList, opts ...
205211
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
206212
}
207213

208-
listOpts := ListOptions{}
209-
listOpts.ApplyOptions(opts)
210-
211214
r, err := uc.cache.getResource(obj)
212215
if err != nil {
213216
return err
214217
}
215218

219+
listOpts := ListOptions{}
220+
listOpts.ApplyOptions(opts)
221+
216222
return r.Get().
217223
NamespaceIfScoped(listOpts.Namespace, r.isNamespaced()).
218224
Resource(r.resource()).
@@ -232,13 +238,16 @@ func (uc *unstructuredClient) UpdateStatus(ctx context.Context, obj Object, opts
232238
return err
233239
}
234240

241+
updateOpts := UpdateOptions{}
242+
updateOpts.ApplyOptions(opts)
243+
235244
return o.Put().
236245
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
237246
Resource(o.resource()).
238247
Name(o.GetName()).
239248
SubResource("status").
240249
Body(obj).
241-
VersionedParams((&UpdateOptions{}).ApplyOptions(opts).AsUpdateOptions(), uc.paramCodec).
250+
VersionedParams(updateOpts.AsUpdateOptions(), uc.paramCodec).
242251
Do(ctx).
243252
Into(obj)
244253
}
@@ -262,13 +271,15 @@ func (uc *unstructuredClient) PatchStatus(ctx context.Context, obj Object, patch
262271
}
263272

264273
patchOpts := &PatchOptions{}
274+
patchOpts.ApplyOptions(opts)
275+
265276
result := o.Patch(patch.Type()).
266277
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
267278
Resource(o.resource()).
268279
Name(o.GetName()).
269280
SubResource("status").
270281
Body(data).
271-
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), uc.paramCodec).
282+
VersionedParams(patchOpts.AsPatchOptions(), uc.paramCodec).
272283
Do(ctx).
273284
Into(u)
274285

0 commit comments

Comments
 (0)