Skip to content

Conversation

@zachaller
Copy link

Fix race condition and resource leak in kubeconfig provider

Summary

This PR fixes two issues in the kubeconfig provider's cluster engagement flow:

  1. Race condition: Ensures clusters are fully ready before being exposed via the provider
  2. Resource leak: Properly cleans up context when engagement fails

Changes

Call Engage before waiting for cache sync

  • The cluster must be engaged with the manager before waiting for cache sync
  • This allows controllers and watches to be set up, which populate the cache
  • Waiting for sync before engaging would result in an empty cache

Ordering rationale

1. Start cluster (goroutine)
2. Engage with manager → sets up controllers/watches
3. Wait for cache sync → ensures cache is populated
4. Store in map → makes cluster accessible to callers
5. Log success → confirms cluster is fully operational

This ordering prevents external code from accessing an unready cluster and avoids context leaks on failure.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 7, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zachaller
Once this PR has been reviewed and has the lgtm label, please assign mjudeikis for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zachaller zachaller changed the title fix fix: sync ordering Nov 7, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @zachaller!

It looks like this is your first PR to kubernetes-sigs/multicluster-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/multicluster-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 7, 2025
@zachaller zachaller changed the title fix: sync ordering Fix sync ordering for kubeconfig provider Nov 7, 2025
@zachaller zachaller changed the title Fix sync ordering for kubeconfig provider 🐛 Fix sync ordering for kubeconfig provider Nov 7, 2025
@zachaller zachaller marked this pull request as ready for review November 7, 2025 21:09
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 7, 2025
@k8s-ci-robot k8s-ci-robot requested a review from skitt November 7, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants