-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[v1.17] service-cache: fix incorrect service deletion on remote backends removal #40361
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
Merged
Conversation
This file contains hidden or 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
/test |
marseel
approved these changes
Jul 7, 2025
aanm
approved these changes
Jul 7, 2025
The blamed commit introduced the removal of a service entry from the internal service cache data structure upon reception of a deletion event for remote endpoints from a remote cluster, if the service is no longer associated with either a local endpointslice or remote endpoints from any other cluster. However, this is not correct, and can lead to an unrecoverable situation (until a service update is performed, or Cilium agents are restarted), because subsequent endpoint updates get then discarded due to not finding the corresponding service anymore. Most notably, this bug is triggered if the service in the local cluster has no selector, as in turn it is not associated with any endpointslice, and the service in the remote cluster, initially marked as global, gets deleted (or no longer shared). At that point, even if the remote service gets recreated (or marked global again), the remote endpoints are not merged anymore. Let's get this fixed by not deleting the service entry from the service cache in this case, as it is always removed upon actual deletion of the local service object. Let's also add a unit test to cover this specific scenario, to validate that the fix works as expected (the test does fail without the fix). This bug can be also reproduced with: make kind-clustermesh && make kind-clustermesh-images && make kind-install-cilium-clustermesh kubectl --context kind-clustermesh1 create deploy podinfo --image=stefanprodan/podinfo --replicas=1 kubectl --context kind-clustermesh1 expose deploy podinfo --port 80 --target-port 9898 kubectl --context kind-clustermesh1 annotate svc podinfo service.cilium.io/global=true # Create a service without a selector cat <<EOF | kubectl --context kind-clustermesh2 create -f - apiVersion: v1 kind: Service metadata: annotations: service.cilium.io/global: "true" name: podinfo namespace: default spec: ports: - port: 80 targetPort: 9898 EOF # Marking the remote service as not global triggers the deletion of # the service entry, and marking it as global again does not add back # the remote endpoint entries. kubectl --context kind-clustermesh1 annotate svc podinfo service.cilium.io/global- kubectl --context kind-clustermesh1 annotate svc podinfo service.cilium.io/global=true Fixes: b7d58c1 ("service-cache: cleanup external endpoints and services on delete") Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
f5558a1
to
213d32e
Compare
Rebased to hopefully make CI happier |
/test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
affects/v1.15
This issue affects v1.15 branch
affects/v1.16
This issue affects v1.16 branch
area/clustermesh
Relates to multi-cluster routing functionality in Cilium.
backport/1.17
This PR represents a backport for Cilium 1.17.x of a PR that was merged to main.
kind/backports
This PR provides functionality previously merged into master.
kind/bug
This is a bug in the Cilium logic.
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
release-blocker/1.17
This issue will prevent the release of the next version of Cilium.
release-note/bug
This PR fixes an issue in a previous release of Cilium.
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.
Opening directly against v1.17 as the entire service cache logic has been refactored in main, and is not affected. I'll follow-up adding a test there as well in any case.
The blamed commit introduced the removal of a service entry from the internal service cache data structure upon reception of a deletion event for remote endpoints from a remote cluster, if the service is no longer associated with either a local endpointslice or remote endpoints from any other cluster.
However, this is not correct, and can lead to an unrecoverable situation (until a service update is performed, or Cilium agents are restarted), because subsequent endpoint updates get then discarded due to not finding the corresponding service anymore. Most notably, this bug is triggered if the service in the local cluster has no selector, as in turn it is not associated with any endpointslice, and the service in the remote cluster, initially marked as global, gets deleted (or no longer shared). At that point, even if the remote service gets recreated (or marked global again), the remote endpoints are not merged anymore.
Let's get this fixed by not deleting the service entry from the service cache in this case, as it is always removed upon actual deletion of the local service object. Let's also add a unit test to cover this specific scenario, to validate that the fix works as expected (the test does fail without the fix).
This bug can be also reproduced with:
Fixes: b7d58c1 ("service-cache: cleanup external endpoints and services on delete")