Skip to content

Commit b428732

Browse files
authored
docs: add section on otpimisitic locking to SSA blog (#2710)
Signed-off-by: Attila Mészáros <[email protected]>
1 parent dfaf06f commit b428732

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/content/en/blog/news/nonssa-vs-ssa.md

+26
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,29 @@ from the custom resource.
8787
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.
8888

8989
Feel free to report common issues, so we can prepare some utilities to handle them.
90+
91+
## Optimistic concurrency control
92+
93+
When you create a resource for SSA as mentioned above, the framework will apply changes even if the underlying resource
94+
or status subresource is changed while the reconciliation was running.
95+
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),
96+
in addition to that since the resource version is not set it won't do optimistic locking. If you still
97+
want to have optimistic locking for the patch, use the resource version of the original resource:
98+
99+
```java
100+
@Override
101+
public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> context) {
102+
103+
reconcileLogicForManagedResources(webPage);
104+
105+
WebPage statusPatch = new WebPage();
106+
statusPatch.setMetadata(new ObjectMetaBuilder()
107+
.withName(webPage.getMetadata().getName())
108+
.withNamespace(webPage.getMetadata().getNamespace())
109+
.withResourceVersion(webPage.getMetadata().getResourceVersion())
110+
.build());
111+
statusPatch.setStatus(updatedStatusForWebPage(webPage));
112+
113+
return UpdateControl.patchStatus(statusPatch);
114+
}
115+
```

0 commit comments

Comments
 (0)