Skip to content

Commit 13a10cd

Browse files
committed
wip
Signed-off-by: Attila Mészáros <[email protected]>
1 parent ddb80d1 commit 13a10cd

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

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

+58-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ date: 2025-02-17
44
---
55

66
From version 5 of Java Operator SDK [server side apply](https://kubernetes.io/docs/reference/using-api/server-side-apply/)
7-
is a first-class feature, and used by default to update resources. Since, as we will see,
8-
unfortunately (or fortunately) to use is it requires changes for your reconciler implementation.
7+
is a first-class feature, and used by default to update resources.
8+
As we will see, unfortunately (or fortunately) to use of it requires changes for your reconciler implementation.
99

1010
For this reason, we prepared a feature flag, which you can flip if not prepared to migrate yet:
1111
[`ConfigurationService.useSSAToPatchPrimaryResource`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L493)
1212

1313
Setting this flag to false will make the operations done by `UpdateControl` using the former approach (not SSA).
14-
As well as adding the finalizer with SSA if needed
14+
Similarly, the finalizer handling won't utilize SSA handling.
15+
The plan is to keep this flag and allow to use the former approach (non-SSA) also in future releases.
1516

16-
For dependent resources a separate flag exists (this was true also before v5) to use SSA or not:
17+
For dependent resources, a separate flag exists (this was true also before v5) to use SSA or not:
18+
[`ConfigurationService.ssaBasedCreateUpdateMatchForDependentResources`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L373)
1719

1820

1921
## Resource handling without and with SSA
@@ -34,12 +36,63 @@ So usually the implementation of reconciler looked something like this:
3436

3537
```
3638

37-
In other words, after reconciliation of managed resources the reconcile updated the status on the
39+
In other words, after reconciliation of managed resources, the reconciler updates the status on the
3840
primary resource passed as argument to the reconciler.
3941
Such changes on primary are fine since we don't work directly with the cached object, the argument is
4042
already cloned.
4143

4244
So how does this change with SSA?
45+
For SSA, the updates should contain (only) the "fully specified intent".
46+
In other words, we should fill only the values that we care about.
47+
In practice means creating a **fresh copy** of the resource and setting only what is necessary:
48+
49+
```java
50+
51+
@Override
52+
public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> context) {
53+
54+
reconcileLogicForManagedResources(webPage);
55+
56+
WebPage statusPatch = new WebPage();
57+
statusPatch.setMetadata(new ObjectMetaBuilder()
58+
.withName(webPage.getMetadata().getName())
59+
.withNamespace(webPage.getMetadata().getNamespace())
60+
.build());
61+
statusPatch.setStatus(createStatus(configMapName));
62+
63+
return UpdateControl.patchStatus(statusPatch);
64+
}
65+
```
66+
67+
Note that we just filled the status here, since we patch the status (not the resource spec).
68+
Since the status is a sub-resource in Kubernetes, it will only update the status part.
69+
70+
Every controller you register will have its own default [field manager](https://kubernetes.io/docs/reference/using-api/server-side-apply/#managers).
71+
You can override the field manager name using [`ControllerConfiguration.fieldManager`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java#L89).
72+
That will set the field manager for the updates of the primary resource and dependent resources.
73+
74+
## Migrating to SSA
75+
76+
Using the legacy or the new SSA way of resource management works well.
77+
However, migrating existing resources to SSA might be a challenge.
78+
So we strongly encourage everyone to test the migration, thus write an integration test where
79+
a custom resource is created using legacy approach is getting managed by new approach.
80+
81+
We prepared an integration test to demonstrate how such migration even in a simple case can go wrong,
82+
and how to fix it.
83+
84+
Note that fixing might that you need to [strip managed fields](https://kubernetes.io/docs/reference/using-api/server-side-apply/#clearing-managedfields)
85+
from the custom resource.
86+
87+
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.
88+
89+
Also feel free to report common issues, so we can in case prepare some utilities to handle them.
90+
91+
92+
93+
94+
95+
4396

4497

4598

0 commit comments

Comments
 (0)