-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: blog post on SSA #2689
Merged
docs: blog post on SSA #2689
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
faed9f9
docs: blog on ssa vs non-SSA
csviri c5db32a
rename file
csviri 0a7c7ae
wip
csviri 546e24a
wip
csviri 4ef1411
wip
csviri 5450eab
wip
csviri 6ba45ea
Update nonssa-vs-ssa.md
csviri 538ebc5
Update nonssa-vs-ssa.md
csviri fcbd2f0
wip
csviri 4297bbd
link
csviri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
title: News | ||
title: Posts | ||
weight: 20 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: From legacy approach to server-side apply | ||
date: 2025-02-25 | ||
--- | ||
|
||
From version 5 of Java Operator SDK [server side apply](https://kubernetes.io/docs/reference/using-api/server-side-apply/) | ||
is a first-class feature and is used by default to update resources. | ||
As we will see, unfortunately (or fortunately), using it requires changes for your reconciler implementation. | ||
|
||
For this reason, we prepared a feature flag, which you can flip if you are not prepared to migrate yet: | ||
[`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) | ||
|
||
Setting this flag to false will make the operations done by `UpdateControl` using the former approach (not SSA). | ||
Similarly, the finalizer handling won't utilize SSA handling. | ||
The plan is to keep this flag and allow the use of the former approach (non-SSA) also in future releases. | ||
|
||
For dependent resources, a separate flag exists (this was true also before v5) to use SSA or not: | ||
[`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) | ||
|
||
|
||
## Resource handling without and with SSA | ||
|
||
Until version 5, changing primary resources through `UpdateControl` did not use server-side apply. | ||
So usually, the implementation of the reconciler looked something like this: | ||
|
||
```java | ||
|
||
@Override | ||
public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> context) { | ||
|
||
reconcileLogicForManagedResources(webPage); | ||
webPage.setStatus(updatedStatusForWebPage(webPage)); | ||
|
||
return UpdateControl.patchStatus(webPage); | ||
} | ||
|
||
``` | ||
|
||
In other words, after the reconciliation of managed resources, the reconciler updates the status of the | ||
primary resource passed as an argument to the reconciler. | ||
Such changes on the primary are fine since we don't work directly with the cached object, the argument is | ||
already cloned. | ||
|
||
So, how does this change with SSA? | ||
For SSA, the updates should contain (only) the "fully specified intent". | ||
In other words, we should only fill in the values we care about. | ||
In practice, it means creating a **fresh copy** of the resource and setting only what is necessary: | ||
|
||
```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()) | ||
.build()); | ||
statusPatch.setStatus(updatedStatusForWebPage(webPage)); | ||
|
||
return UpdateControl.patchStatus(statusPatch); | ||
} | ||
``` | ||
|
||
Note that we just filled out the status here since we patched the status (not the resource spec). | ||
Since the status is a sub-resource in Kubernetes, it will only update the status part. | ||
|
||
Every controller you register will have its default [field manager](https://kubernetes.io/docs/reference/using-api/server-side-apply/#managers). | ||
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). | ||
That will set the field manager for the primary resource and dependent resources as well. | ||
|
||
## Migrating to SSA | ||
|
||
Using the legacy or the new SSA way of resource management works well. | ||
However, migrating existing resources to SSA might be a challenge. | ||
We strongly recommend testing the migration, thus implementing an integration test where | ||
a custom resource is created using the legacy approach and is managed by the new approach. | ||
|
||
We prepared an integration test to demonstrate how such migration, even in a simple case, can go wrong, | ||
and how to fix it. | ||
|
||
To fix some cases, you might need to [strip managed fields](https://kubernetes.io/docs/reference/using-api/server-side-apply/#clearing-managedfields) | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add that it will be properly deprecated at least one major or minor in advance so people can prepare?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I don't want to deprecate it, unless there is of course a major architectural change.