Skip to content

Commit 5804716

Browse files
authored
📖 Add documentation note describing behavior with status (#2635)
* Add documentation note describing behavior with status * update text
1 parent 91f642b commit 5804716

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/controller/controllerutil/controllerutil.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ const ( // They should complete the sentence "Deployment default/foo has been ..
270270
// The MutateFn is called regardless of creating or updating an object.
271271
//
272272
// It returns the executed operation and an error.
273+
//
274+
// Note: changes made by MutateFn to any sub-resource (status...), will be
275+
// discarded.
273276
func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f MutateFn) (OperationResult, error) {
274277
key := client.ObjectKeyFromObject(obj)
275278
if err := c.Get(ctx, key, obj); err != nil {
@@ -307,6 +310,12 @@ func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f M
307310
// The MutateFn is called regardless of creating or updating an object.
308311
//
309312
// It returns the executed operation and an error.
313+
//
314+
// Note: changes to any sub-resource other than status will be ignored.
315+
// Changes to the status sub-resource will only be applied if the object
316+
// already exist. To change the status on object creation, the easiest
317+
// way is to requeue the object in the controller if OperationResult is
318+
// OperationResultCreated
310319
func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, f MutateFn) (OperationResult, error) {
311320
key := client.ObjectKeyFromObject(obj)
312321
if err := c.Get(ctx, key, obj); err != nil {

0 commit comments

Comments
 (0)