Skip to content

fix(syncer): retry recreating the kubernetes service when the apiserver wins the race - #4280

Open
blacksoxx wants to merge 1 commit into
loft-sh:mainfrom
blacksoxx:kubernetes-service-recreate-retry
Open

blacksoxx wants to merge 1 commit into
loft-sh:mainfrom
blacksoxx:kubernetes-service-recreate-retry

Conversation

@blacksoxx

@blacksoxx blacksoxx commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What issue type does this pull request address?
/kind bugfix

What does this pull request do? Which issues does it resolve?
resolves #4279

To change the ClusterIP of default/kubernetes the syncer deletes the service and creates it again. The kube-apiserver recreates that service on its own as soon as it is gone, so the create can lose the race and fail with AlreadyExists. The startup wrapper only retried on Conflict, so the syncer exited.

The delete and create now repeat inside the sync, up to five times, until the service that exists carries the cluster ips of the host service. A service recreated by the apiserver with the wanted ips already is accepted as is.

Please provide a short message that should be published in the vcluster release notes
Fixed an issue where the syncer exited at startup when the kube-apiserver recreated the default/kubernetes service while the syncer was replacing its ClusterIP.

What else do we need to know?
Unit test with a client that plays the apiserver recreating the service between delete and create: winning at once, losing once, losing twice, and never winning.


Note

Medium Risk
Changes startup-critical sync of the default/kubernetes Service; bounded retries reduce failure modes but still delete/recreate a core cluster object.

Overview
When the virtual default/kubernetes service needs a new ClusterIP, the syncer no longer does a single delete-then-create. It delegates to recreateService, which can repeat that cycle up to five times to cope with the kube-apiserver immediately recreating the service and causing AlreadyExists on create.

If another actor recreates the service first, the syncer GETs the current object: it succeeds when the live service already has the host’s cluster IPs, or it deletes again and retries with the updated object. ResourceVersion and UID are cleared on each create attempt.

Unit tests add an apiserverRecreatesClient that simulates the apiserver winning the race zero, one, two, or every time, asserting the virtual service ends up with the host IP or returns an error after max attempts.

Reviewed by Cursor Bugbot for commit 0050c38. Bugbot is set up for automated code reviews on this repo. Configure here.

…er wins the race

To change the ClusterIP of default/kubernetes the syncer deletes the service and creates it again. The kube-apiserver recreates that service on its own as soon as it is gone, so the create can lose the race and fail with AlreadyExists; the startup wrapper only retried on Conflict and the syncer exited. The delete and create now repeat inside the sync, bounded, until the service that exists carries the cluster ips of the host service.

Signed-off-by: Youssef Omar Bouden <youssef.bouden2002@gmail.com>
@blacksoxx
blacksoxx requested a review from a team as a code owner November 13, 2026 12:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syncer exits when kube-apiserver recreates default/kubernetes during ClusterIP synchronization

1 participant