Skip to content

Using patch when updating status sub-resource (or update without optimistic locking) #525

Closed
@csviri

Description

@csviri

Currently when we update status subresource of a custom resource we do optimistic locking. So if there was an update on custom resource while the controller was reconciliation, the resource version of CR will be changed and consequently the update of the status will fail on conflic.

In case of a successful reconciliation we would like to update the status, even if the custom resource spec is changed meanwhile (note that even a metadata change result in a resourceVersion update). The reason is that we don't want to lost information on the managed (dependent) resource, typically on created ones:

Consider the situation when you create a resource in the controller what can be later only adressed by it's generated ID (from the response of an API call). (Cannot think of better example now (TODO): like a PullRequest in github api). The ID becomes for us a state, this is how we address the resource from now when again reconciling. If we would not store this ID in status, we would have to recreate it on the next run of the controller. So event a spec is changed, this might or might not have effect on the jus created resource. On next run of the controller will reconcile it. But without storing the ID it will be just created and mainly the previouse one not cleaned up.

So there are two ways to go:

  1. Use patch on status - it by definition does not use optimistic locking, it's very generic. Note that under the hood k8s supports both well known json patch standards: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment

  2. Update status without optimistic locking - this will overwrite status event the resource version changed.

Pathching is good because in some cases it might happen that multiple processes want to change the status, so concurrent patches might not result in lost update if implemented correctly. If there are no multiple processes changing the status, simple update is also sufficient.

Probably it's enough to support only Patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurekind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions