@@ -64,7 +64,7 @@ type Writer interface {
64
64
65
65
// Update updates the given obj in the Kubernetes cluster. obj must be a
66
66
// struct pointer so that obj can be updated with the content returned by the Server.
67
- Update (ctx context.Context , obj runtime.Object ) error
67
+ Update (ctx context.Context , obj runtime.Object , opts ... UpdateOptionFunc ) error
68
68
}
69
69
70
70
// StatusClient knows how to create a client which can update status subresource
@@ -149,9 +149,9 @@ func (o *CreateOptions) ApplyOptions(optFuncs []CreateOptionFunc) *CreateOptions
149
149
// https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md.
150
150
type CreateOptionFunc func (* CreateOptions )
151
151
152
- // DryRunAll is a functional option that sets the DryRun
152
+ // CreateDryRunAll is a functional option that sets the DryRun
153
153
// field of a CreateOptions struct to metav1.DryRunAll.
154
- func DryRunAll () CreateOptionFunc {
154
+ func CreateDryRunAll () CreateOptionFunc {
155
155
return func (opts * CreateOptions ) {
156
156
opts .DryRun = []string {metav1 .DryRunAll }
157
157
}
@@ -377,3 +377,54 @@ func UseListOptions(newOpts *ListOptions) ListOptionFunc {
377
377
* opts = * newOpts
378
378
}
379
379
}
380
+
381
+ // UpdateOptions contains options for create requests. It's generally a subset
382
+ // of metav1.UpdateOptions.
383
+ type UpdateOptions struct {
384
+ // When present, indicates that modifications should not be
385
+ // persisted. An invalid or unrecognized dryRun directive will
386
+ // result in an error response and no further processing of the
387
+ // request. Valid values are:
388
+ // - All: all dry run stages will be processed
389
+ DryRun []string
390
+
391
+ // Raw represents raw UpdateOptions, as passed to the API server.
392
+ Raw * metav1.UpdateOptions
393
+ }
394
+
395
+ // AsUpdateOptions returns these options as a metav1.UpdateOptions.
396
+ // This may mutate the Raw field.
397
+ func (o * UpdateOptions ) AsUpdateOptions () * metav1.UpdateOptions {
398
+
399
+ if o == nil {
400
+ return & metav1.UpdateOptions {}
401
+ }
402
+ if o .Raw == nil {
403
+ o .Raw = & metav1.UpdateOptions {}
404
+ }
405
+
406
+ o .Raw .DryRun = o .DryRun
407
+ return o .Raw
408
+ }
409
+
410
+ // ApplyOptions executes the given UpdateOptionFuncs and returns the mutated
411
+ // UpdateOptions.
412
+ func (o * UpdateOptions ) ApplyOptions (optFuncs []UpdateOptionFunc ) * UpdateOptions {
413
+ for _ , optFunc := range optFuncs {
414
+ optFunc (o )
415
+ }
416
+ return o
417
+ }
418
+
419
+ // UpdateOptionFunc is a function that mutates a UpdateOptions struct. It implements
420
+ // the functional options pattern. See
421
+ // https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md.
422
+ type UpdateOptionFunc func (* UpdateOptions )
423
+
424
+ // UpdateDryRunAll is a functional option that sets the DryRun
425
+ // field of a UpdateOptions struct to metav1.DryRunAll.
426
+ func UpdateDryRunAll () UpdateOptionFunc {
427
+ return func (opts * UpdateOptions ) {
428
+ opts .DryRun = []string {metav1 .DryRunAll }
429
+ }
430
+ }
0 commit comments