@@ -159,69 +159,48 @@ take an aligned approach to adding apply to clients in a typesafe way.
159
159
The client-go typed clients will be extended to include Apply functions, e.g.:
160
160
161
161
``` go
162
- func (c *deployments ) Apply (ctx Context , fieldManager string , deployment *appsv1apply .Deployment , opts metav1 .ApplyOptions ) (*Deployment , error )
163
- func (c *deployments) ApplyStatus(ctx Context, fieldManager string, deployment *appsv1apply.Deployment, opts metav1.ApplyOptions) (*Deployment, error)
164
- func (c *deployments) ApplyScale(ctx Context, fieldManager string, deployment *appsv1apply.Deployment, opts metav1.ApplyOptions) (*Deployment, error)
162
+ func (c *deployments ) Apply (ctx Context , deployment *appsv1apply .Deployment , opts metav1 .ApplyOptions ) (*Deployment , error )
163
+ func (c *deployments) ApplyStatus(ctx Context, deployment *appsv1apply.Deployment, opts metav1.ApplyOptions) (*Deployment, error)
164
+ func (c *deployments) ApplyScale(ctx Context, deployment *appsv1apply.Deployment, opts metav1.ApplyOptions) (*Deployment, error)
165
165
```
166
166
167
167
`ApplyOptions` will be added to metav1 even though `PatchOptions` will continue
168
- to be used over the wire. This will make it obvious in the Apply function
169
- signature that `fieldManager` is required.
168
+ to be used over the wire:
170
169
171
170
```go
172
171
type ApplyOptions struct {
173
172
DryRun []string ` json:"dryRun,omitempty" protobuf:"bytes,1,rep,name=dryRun"`
174
- Force *bool ` json:"force,omitempty" protobuf:"varint,2,opt,name=force"`
175
- }
176
173
177
- func (ApplyOptions ) ToPatchOptions (fieldManager string ) PatchOptions
174
+ // <apply specific Force godoc goes here>
175
+ // Note that this is different than PatchOptions, which has Force as an optional field (bool pointer).
176
+ Force bool ` json:"force,omitempty" protobuf:"varint,2,opt,name=force"`
177
+
178
+ // <apply specific FieldManager godoc goes here>
179
+ FieldManager string ` json:"fieldManager,omitempty" protobuf:"bytes,3,name=fieldManager"`
180
+ }
178
181
```
179
182
180
- <<[UNRESOLVED @jpbetz ]>>
183
+ ` ApplyOptions ` is introduced to allow us to:
181
184
182
- Should fieldManager be a parameter of Apply or should it be optional?
185
+ - Customize the godoc for the fieldManager and force fields to explain
186
+ them better in the context of apply.
187
+ - Switch ` Force ` from a ` *bool ` to a ` bool ` .
188
+ - Future proof the API, by allowing apply specific fields to
189
+ be added in the future.
183
190
184
- The main reason this KEP proposes fieldmanager be a required parameter
185
- for Apply is that some controllers have multiple code paths that
186
- update the same same object, but that update different field sets. If
187
- they used apply and the same field manager, fields could be
188
- accidentally removed or disowned.
191
+ We do not provide a default for fieldManager. This is the existing
192
+ behavior of apply from the apiserver perspective. This makes sense
193
+ since some controllers have multiple code paths that update the same
194
+ same object, but that update different field sets. If they used apply
195
+ and the same field manager, fields could be accidentally removed or
196
+ disowned. We also make force a required field since it should
197
+ typically be set to true for controllers but defaults to false.
189
198
190
199
Create and Update methods default the fieldmanager to a user-agent
191
200
based string. But unlike Apply, Updates succeed even if there are
192
201
conflicts, so the fieldmanager name is almost entirely
193
202
informational. For Apply, the fieldmanager name matters a lot more,
194
- and a user-agent string is almost certainly not a good default
195
- fieldmanager for Apply.
196
-
197
- If we require fieldManager, an alternative to making fieldManager a
198
- required parameter of `Apply` functions would be have a constructor
199
- for Apply options like `NewApplyOptions(fieldManager, force)` that
200
- makes the required field clear.
201
-
202
- <<[/UNRESOLVED]>>
203
-
204
- <<[UNRESOLVED @jpbetz ]>>
205
- Should the Force field also be made a required field like fieldManager is?
206
- @lavalamp pointed out that user things typically want false but
207
- controller-things typically want true, so false isn't a great default.
208
-
209
- Also, can we structure this so that we don't have so many positional params?
210
- Moving two params from options to the top level positional params results in a
211
- longer function signature. Alternative proposed by @lavalamp was to do something
212
- more like this (ordering or parameters and function names TBD):
213
-
214
- ```go
215
- client.Deployments().BeginApply("field-manager-name", options).Body(
216
- appsv1apply.Deployment().
217
- SetObjectMeta(&metav1apply.ObjectMeta()). ...
218
- ).Apply(ctx)
219
- ```
220
-
221
- <<[/UNRESOLVED]>>
222
-
223
- Apply will combine the `fieldManager` argument with `ApplyOptions` to create the
224
- `PatchOptions`.
203
+ and a user-agent string is not a good default for many use cases.
225
204
226
205
### Generated apply configuration types
227
206
0 commit comments