Skip to content

Commit

Permalink
docs: add section on otpimisitic locking to SSA blog (#2710)
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <[email protected]>
  • Loading branch information
csviri authored Feb 27, 2025
1 parent dfaf06f commit b428732
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/content/en/blog/news/nonssa-vs-ssa.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,29 @@ from the custom resource.
See [`StatusPatchSSAMigrationIT`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchSSAMigrationIT.java) for details.

Feel free to report common issues, so we can prepare some utilities to handle them.

## Optimistic concurrency control

When you create a resource for SSA as mentioned above, the framework will apply changes even if the underlying resource
or status subresource is changed while the reconciliation was running.
First, it always forces the conflicts in the background as advised in [Kubernetes docs](https://kubernetes.io/docs/reference/using-api/server-side-apply/#using-server-side-apply-in-a-controller),
in addition to that since the resource version is not set it won't do optimistic locking. If you still
want to have optimistic locking for the patch, use the resource version of the original resource:

```java
@Override
public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> context) {

reconcileLogicForManagedResources(webPage);

WebPage statusPatch = new WebPage();
statusPatch.setMetadata(new ObjectMetaBuilder()
.withName(webPage.getMetadata().getName())
.withNamespace(webPage.getMetadata().getNamespace())
.withResourceVersion(webPage.getMetadata().getResourceVersion())
.build());
statusPatch.setStatus(updatedStatusForWebPage(webPage));

return UpdateControl.patchStatus(statusPatch);
}
```

0 comments on commit b428732

Please sign in to comment.