java-operator-sdk: where resources already exist but requests are generated by `CREATE`
Bug Report
io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: PATCH at: https://172.23.0.1:443/apis/policy/v1/namespaces/n3r-platform-opensearch/poddisruptionbudgets/os-osfarm-cluster-manager-pdb?fieldManager=opensearchreconciler&force=true. Message: Operation cannot be fulfilled on poddisruptionbudgets.policy "os-osfarm-cluster-manager-pdb": the object has been modified; please apply your changes to the latest version and try again. Received status: Status(apiVersion=v1, code=409, details=StatusDetails(causes=[], group=policy, kind=poddisruptionbudgets, name=os-osfarm-cluster-manager-pdb, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=Operation cannot be fulfilled on poddisruptionbudgets.policy "os-osfarm-cluster-manager-pdb": the object has been modified; please apply your changes to the latest version and try again, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Conflict, status=Failure, additionalProperties={}).
at io.fabric8.kubernetes.client.KubernetesClientException.copyAsCause(KubernetesClientException.java:238)
at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.waitForResult(OperationSupport.java:507)
at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleResponse(OperationSupport.java:524)
at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handlePatch(OperationSupport.java:419)
at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handlePatch(OperationSupport.java:397)
at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.handlePatch(BaseOperation.java:713)
at io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation.lambda$patch$2(HasMetadataOperation.java:232)
at io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation.patch(HasMetadataOperation.java:237)
at io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation.patch(HasMetadataOperation.java:252)
at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.serverSideApply(BaseOperation.java:1132)
at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.serverSideApply(BaseOperation.java:92)
at io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource.create(KubernetesDependentResource.java:140)
at io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource.create(CRUDKubernetesDependentResource.java:16)
at io.javaoperatorsdk.operator.processing.dependent.AbstractDependentResource.handleCreate(AbstractDependentResource.java:114)
at io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource.handleCreate(KubernetesDependentResource.java:111)
at io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource.handleCreate(KubernetesDependentResource.java:32)
at io.javaoperatorsdk.operator.processing.dependent.AbstractDependentResource.reconcile(AbstractDependentResource.java:62)
at io.javaoperatorsdk.operator.processing.dependent.SingleDependentResourceReconciler.reconcile(SingleDependentResourceReconciler.java:19)
at io.javaoperatorsdk.operator.processing.dependent.AbstractDependentResource.reconcile(AbstractDependentResource.java:52)
at io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowReconcileExecutor$NodeReconcileExecutor.doRun(WorkflowReconcileExecutor.java:115)
at io.javaoperatorsdk.operator.processing.dependent.workflow.NodeExecutor.run(NodeExecutor.java:22)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
at io.javaoperatorsdk.operator.processing.dependent.AbstractDependentResource.handleCreate(AbstractDependentResource.java:114)
What did you do?
Creating PDB with DependentResource
However, even though resources are already created
k get PodDisruptionBudget ✔ 10357 17:43:26
NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE
os-osfarm-cluster-manager-pdb N/A 1 1 88m
When running additional ‘reconcile’ loop
The request was created as Create rather than Update
If there is a secondary resource, shouldn’t the request go to update right?
Why is it created as create?
409 errors continue to occur, which is a problem
What did you expect to see?
What did you see instead? Under which circumstances?
no
Environment
Kubernetes cluster type:
Kubernetes
$ Mention java-operator-sdk version from pom.xml file
v4.4.4
$ java -version
jdk21
$ kubectl version
v1.23.15
Possible Solution
no
Additional context
no
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 43 (23 by maintainers)
Commits related to this issue
- fix: ignore server managed fields for SSA matching closes: #2290 Signed-off-by: Steven Hawkins <shawkins@redhat.com> — committed to shawkins/java-operator-sdk by shawkins 3 years ago
I’m not aware of newer definitive underlying kube issues. There were several later client changes to limit any potential issues with the api server not sending events - we’ll restart the watches at most every 10 minutes.
@10000-ki I should have realized with the previous incarnation of this issue that you were creating the desired state on top of the existing state - are you doing something like new StatefulSetBuilder(existing)… ?
That is why the desired state had the generation set. Here with the state from the other field managers populated you see a similar issue.
The SSA matching logic expects you to only provide your managed desired state when creating the entry - and nothing else.
@csviri is it worth guarding against this more?
@csviri @10000-ki with the full yaml it’s clear that there’s another matching issue in play. The SSA matching logic sees the n3r.navercorp.com annotations as part of the desired state, but does not think that they are owned by the operator, thus it’s trying the operation again.
@10000-ki can you create a simple reproducer pls?
( Ideally with 1 deployment dependent )
This log shows 5 updates of 5 different resources by the operator sdk. The operator then skips propogating the update event for all of them, so this appears to be expected behavior. Can you find a situation in your logs where “Propagating event for …” appears - the surrounding logs should help determine if that resourceVersion of that resource was the result of the operator in which case there would be an event cycle.
@csviri
where can i see this mechanism logic??i couldn’t find that codeShouldn’t we add data to metadata only if the actual and design are different, like above?sorry 😦
i found it
@csviri on a random note thank you for always watching the issue well, I’m a big fan of
Josdkyes i will try
@10000-ki this seems to be a relative complex project, could you pls create a simplistic reproducer - ideally with 1 dependent resource that causes the issue (and in java + maven If possible) that would speed up this very much, thx
@csviri thank you for sharing
in my case It falls into an infinite loop.
https://github.com/10000-ki/test-operator/tree/main/src/main/kotlin/opensearch/operator/api/v1/cr/dependent
can you see this code? i gave you permission
The actual code is on the github enterprise in my company.
I just brought the operator part of the actual project
Pls take a look on these: https://github.com/fabric8io/kubernetes-client/issues/4781 https://github.com/kubernetes/kubernetes/issues/102464
but there might be some newer ones. Maybe @shawkins knows more.
okay i will try
Also what you can you can check if this is a problem on the newer versions of k8s.
First, I’ll increase the
josdkversion to the maximumv4.8.1pls try the newest (4.8.1), if there will be still issues, we will take a look. Note that k8s 1.23 is also a bit old too, there were some issues with event sending in that version (what should be fixed now also on fabric8 client (restarting watches) ). But if the problem persist we can take a look, and try to make a reproducer. Probably the issue will be rather in the fabric8 client, since we are reading the last resource from the informer cache.
Hi @10000-ki there were improvements regarding to this in newer versions, pls upgrade to the newest version