Skip to content

Commit 809b33b

Browse files
committed
Resolve apply options issues for Apply for client-go KEP
1 parent 93431db commit 809b33b

File tree

1 file changed

+25
-46
lines changed
  • keps/sig-api-machinery/2144-clientgo-apply

1 file changed

+25
-46
lines changed

keps/sig-api-machinery/2144-clientgo-apply/README.md

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -159,69 +159,48 @@ take an aligned approach to adding apply to clients in a typesafe way.
159159
The client-go typed clients will be extended to include Apply functions, e.g.:
160160

161161
```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)
165165
```
166166

167167
`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:
170169

171170
```go
172171
type ApplyOptions struct {
173172
DryRun []string `json:"dryRun,omitempty" protobuf:"bytes,1,rep,name=dryRun"`
174-
Force *bool `json:"force,omitempty" protobuf:"varint,2,opt,name=force"`
175-
}
176173

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+
}
178181
```
179182

180-
<<[UNRESOLVED @jpbetz ]>>
183+
`ApplyOptions` is introduced to allow us to:
181184

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.
183190

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.
189198

190199
Create and Update methods default the fieldmanager to a user-agent
191200
based string. But unlike Apply, Updates succeed even if there are
192201
conflicts, so the fieldmanager name is almost entirely
193202
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.
225204

226205
### Generated apply configuration types
227206

0 commit comments

Comments
 (0)