Skip to content

Do not fail cluster engagement because of a stopping sync controller - #215

Merged
kcp-ci-bot merged 3 commits into
kcp-dev:mainfrom
Wompipomp:fix/engage-stopping-controller
Dec 3, 2026
Merged

kcp-ci-bot merged 3 commits into
kcp-dev:mainfrom
Wompipomp:fix/engage-stopping-controller

Conversation

@Wompipomp

@Wompipomp Wompipomp commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A sync controller whose context is cancelled (it was stopped, or it exited and #201 is about to
restart it) is still registered with the DynamicMultiClusterManager until it is removed under the
runnables lock. Forwarding an Engage() call to it can fail,
because its per-cluster watch may not sync with a cancelled context. The cluster tracker returned that
error, and multicluster-runtime then removed the whole cluster, so no sync controller served it
until it was engaged again or the agent restarted.

Engagement errors of a controller that is stopping (its context is done) are now ignored. This also
covers pre-seeding, so a controller that is stopped while it starts no longer fails
StartController (it is then restarted through #201's backoff). Errors of running controllers
still abort the engagement as before (TestEngageFailsForRunningController).

This uses the controller's context that #212 stores next to each controller in the DMCM.

Tested with go test -race ./... and make lint (no new findings) after the rebase; e2e runs in CI. TestEngageWhileControllerIsStopping keeps a
stopped controller inside a reconcile, engages a new cluster in the meantime, and fails without the
fix with failed to watch for cluster "second": context canceled.

Rebased onto main after #212 was merged.

What Type of PR Is This?

/kind bug

Related Issue(s)

Fixes #214

Release Notes

Fix workspaces being dropped for all sync controllers when they are engaged while a sync controller is shutting down.

@kcp-ci-bot kcp-ci-bot added kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has signed the DCO. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 28, 2026
@kcp-ci-bot

Copy link
Copy Markdown
Contributor

Hi @Wompipomp. Thanks for your PR.

I'm waiting for a kcp-dev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kcp-ci-bot kcp-ci-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 28, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

/ok-to-test

@kcp-ci-bot kcp-ci-bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 2, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

/ok-to-test

@kcp-ci-bot kcp-ci-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2026
@Wompipomp
Wompipomp force-pushed the fix/engage-stopping-controller branch from 29cd467 to 5bcb6f3 Compare December 2, 2026 10:39
@kcp-ci-bot kcp-ci-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

@mjudeikis-bot review this. Do local extensive testing of this

@mjudeikis-bot mjudeikis-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: I built ./internal/... and ran go vet on the changed packages; both were clean. I ran go test -race on internal/kcp, internal/controllerutil and internal/controller/syncmanager, and all passed. A second run with -count=5 and no race detector also passed, so I saw no flakiness. Running the new TestEngageWhileControllerIsStopping on the parent commit b014641 fails with failed to watch for cluster "second": context canceled, and it passes at HEAD, so the test reproduces the bug this PR fixes. I also changed TestStoppedControllersDoNotLeak to use the plain cache instead of HandlerRemovingCache; it then fails (goroutines go from 17 to 57), so it really guards against the handler leak.

Behaviour: I checked the dependency code and found no problems. controller-runtime v0.24.1 starts Kind sources with the controller's own context, not the timed sync context (internal/controller/controller.go:371), and it passes that same context to GetInformer. So HandlerRemovingCache removes local handlers exactly when the controller stops. multicluster-runtime's Engage deduplicates by whether the old engagement context is still live, so giving each call its own engagement context does not cause duplicate watches. The engagement error is now swallowed only when the controller's own context is done; errors from running controllers still fail engagement, and TestEngageFailsForRunningController covers that. I ran everything without a real kcp or kube-apiserver because the sandbox has neither. Behaviour against live clusters (real informer RemoveEventHandler and an end-to-end PublishedResource change) is unverified; the e2e suite would cover it.

@mjudeikis

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2026
@kcp-ci-bot

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: aedef84df12963de0605c5526cb54f29f7e411cd

@kcp-ci-bot kcp-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 2, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

/retest

@Wompipomp
Wompipomp force-pushed the fix/engage-stopping-controller branch from 5bcb6f3 to 012baed Compare December 2, 2026 14:31
@kcp-ci-bot kcp-ci-bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2026
@kcp-ci-bot
kcp-ci-bot requested a review from mjudeikis December 2, 2026 14:31
@mjudeikis

Copy link
Copy Markdown
Contributor

@Wompipomp one more rebase please :D

@kcp-ci-bot kcp-ci-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2026
@Wompipomp

Copy link
Copy Markdown
Contributor Author

@Wompipomp one more rebase please :D

rebasing all day 😄

A sync controller whose context is cancelled (because it was stopped, or
because it exited and is about to be restarted) stays registered with
the DynamicMultiClusterManager until it is removed under the runnables
lock. Forwarding an Engage() call to it fails, because its per-cluster
watch cannot sync with a cancelled context. The cluster tracker then
returns that error, and the cluster provider drops the whole cluster, so
no sync controller serves it until the cluster is engaged again or the
agent restarts.

Ignore engagement errors of a controller that is stopping. This also
applies to pre-seeding, so a controller that is stopped while it is
being started no longer fails StartController. Errors of running
controllers still abort the engagement.

on-behalf-of: @eon-se opensource@eon.com
Signed-off-by: Mark Altmann <mark.altmann.external@eon.com>
@Wompipomp
Wompipomp force-pushed the fix/engage-stopping-controller branch from 012baed to 0a6e446 Compare December 2, 2026 18:41
@kcp-ci-bot kcp-ci-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 2, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

@Wompipomp one more rebase please :D

rebasing all day 😄

Sorry :D I want to cut a release and make sure all your changes are in there :D

@mjudeikis

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2026
@kcp-ci-bot

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: a8299268ed98f896cc5811d1b78867b57cfdface

@kcp-ci-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mjudeikis

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

The pull request process is described here

Details 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

@kcp-ci-bot kcp-ci-bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

/lgtm

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2026
@kcp-ci-bot

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: ba3a42aa6299604c41bc15df5f958790e4725045

@mjudeikis mjudeikis added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Dec 3, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

Sorry I pushed ontop. Want to get this merged so we can tag a release :)
p.s. can you ping me on kuberentes slack so I can match who are you so next time I can ping you? :)

@kcp-ci-bot
kcp-ci-bot merged commit 08402f4 into kcp-dev:main Dec 3, 2026
14 checks passed
@Wompipomp

Copy link
Copy Markdown
Contributor Author

Sorry I pushed ontop. Want to get this merged so we can tag a release :) p.s. can you ping me on kuberentes slack so I can match who are you so next time I can ping you? :)

no worries 😄 Thanks for merging. Yes of course will do 👍

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: engaging a workspace can fail while a sync controller is stopping, and the workspace is dropped for all controllers

4 participants