From b4287321008eb8f817850a3fc519374b07840e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 27 Feb 2025 13:43:24 +0100 Subject: [PATCH] docs: add section on otpimisitic locking to SSA blog (#2710) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docs/content/en/blog/news/nonssa-vs-ssa.md | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/content/en/blog/news/nonssa-vs-ssa.md b/docs/content/en/blog/news/nonssa-vs-ssa.md index 241828d3e3..e95fb0a295 100644 --- a/docs/content/en/blog/news/nonssa-vs-ssa.md +++ b/docs/content/en/blog/news/nonssa-vs-ssa.md @@ -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 reconcile(WebPage webPage, Context 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); +} +```