Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllerutil.CreateOrPatch doesn't update not empty Status fields if Spec fields are specified #1392

Closed
dmvolod opened this issue Feb 23, 2021 · 5 comments · Fixed by #1403

Comments

@dmvolod
Copy link
Contributor

dmvolod commented Feb 23, 2021

If we would like to patch custom resource with some Spec fields and Status which are not empty, the controllerutil.CreateOrPatch patches Spec only fields, but any Status keep unchanged,
result returns OperationResultUpdatedStatus which means that both Spec and Status where updated
The reason why this happens is that the original Status of the object is returned when the" Patch "procedure is exited and, as a result, no Status fields are updated

@dmvolod
Copy link
Contributor Author

dmvolod commented Feb 23, 2021

Reproducer created. See linked commit

@coderanger
Copy link
Contributor

Do you have the status subresource enabled? If so, you need to specifically use a status writer call.

@dmvolod
Copy link
Contributor Author

dmvolod commented Feb 23, 2021

@coderanger are you mean // +kubebuilder:subresource:status instruction? Yes, we have it.
What does status writer call means. This function works fine with Spec and non Status.Condtions updates

@coderanger
Copy link
Contributor

Turning on that subresource means that all changes to fields under .status will be blocked from calls to client.Update(). You must separately use client.Status().Update() (which in turn only applies changes under .status). This is the purpose of the status subresource. If you don't want that behavior, don't enable it :)

@dmvolod
Copy link
Contributor Author

dmvolod commented Feb 24, 2021

@coderanger please pay attention that,

  • we are using and talking about controller-runtime library function called controllerutil.CreateOrPatch and it implementing with separate resource Spec and Status Patch
    func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, f MutateFn) (OperationResult, error) {
  • first (empty Status field) are works fine. Both Status and Spec fields are updated
  • This case doesn't work for the next controllerutil.CreateOrPatch calls even if only Status fields are updated

@dmvolod dmvolod changed the title controllerutil.CreateOrPatch doesn't update Status.Conditions event if Spec fields are specified controllerutil.CreateOrPatch doesn't update no-empty Status fields event if Spec fields are specified Feb 28, 2021
@dmvolod dmvolod changed the title controllerutil.CreateOrPatch doesn't update no-empty Status fields event if Spec fields are specified controllerutil.CreateOrPatch doesn't update not empty Status fields event if Spec fields are specified Feb 28, 2021
@dmvolod dmvolod changed the title controllerutil.CreateOrPatch doesn't update not empty Status fields event if Spec fields are specified controllerutil.CreateOrPatch doesn't update not empty Status fields if Spec fields are specified Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants