You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm reconciling a standalone dependent resource of type Secret that needs to be updated (it exists in k8s but I need to update it with new data).
I believe this also affects managed dependent resources, and any type of resource.
What did you expect to see?
During the reconcile() method, the desired() method should have been called only once.
What did you see instead? Under which circumstances?
During the reconcile() method, the desired() method is called twice.
Environment
Kubernetes cluster type:
OpenShift
$ Mention java-operator-sdk version from pom.xml file
4.2.2
$ java -version
openjdk version "11.0.16.1" 2022-08-12
OpenJDK Runtime Environment Temurin-11.0.16.1+1 (build 11.0.16.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.16.1+1 (build 11.0.16.1+1, mixed mode)
67 final Matcher.Result<R> match = match(actualResource, primary, context);
68 if (!match.matched()) {
69 final var desired = match.computedDesired().orElse(desired(primary, context));
throwIfNull(desired, primary, "Desired");
logForOperation("Updating", primary, desired);
var updatedResource = handleUpdate(actualResource, desired, primary, context);
return ReconcileResult.resourceUpdated(updatedResource);
}
Additional context
In my case, we're generating some random data, including passwords, that are stored in the secret. I've implemented a custom check to determine if the reconciliation of the secret is required (basically, if it does not exist or it is empty), and only in such a case generate the passwords and create/update the secret with the random passwords. I observed that when the secret exists but is empty, passwords were actually generated twice before being applied to the secret. The first set of passwords were actually used, and the second was generated for nothing (since it's in the orElse part that is not used since the desired state was already computed).
The text was updated successfully, but these errors were encountered:
Bug Report
What did you do?
I'm reconciling a standalone dependent resource of type Secret that needs to be updated (it exists in k8s but I need to update it with new data).
I believe this also affects managed dependent resources, and any type of resource.
What did you expect to see?
During the
reconcile()
method, thedesired()
method should have been called only once.What did you see instead? Under which circumstances?
During the
reconcile()
method, thedesired()
method is called twice.Environment
Kubernetes cluster type:
OpenShift
$ Mention java-operator-sdk version from pom.xml file
4.2.2
$ java -version
$ kubectl version
Possible Solution
In the
reconcile()
method ofAbstractDependentResource
, at line 67, thematch()
method callsdesired()
and stores the computed actual resources in theMatcher.Result
object (which is good).https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java#L67
But then, in line 69,
desired()
is called AGAIN (even though it's inorElse
part):https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java#L69
Line 69 should change and only invoke
desired()
if the Optionalmatch.computedDesired()
is empty.Simple change :)
Here's the current code:
Additional context
In my case, we're generating some random data, including passwords, that are stored in the secret. I've implemented a custom check to determine if the reconciliation of the secret is required (basically, if it does not exist or it is empty), and only in such a case generate the passwords and create/update the secret with the random passwords. I observed that when the secret exists but is empty, passwords were actually generated twice before being applied to the secret. The first set of passwords were actually used, and the second was generated for nothing (since it's in the
orElse
part that is not used since the desired state was already computed).The text was updated successfully, but these errors were encountered: