Skip to content

fix(nodes): merge taints by key and effect so the host copy wins - #4278

Open
TECHANOO wants to merge 2 commits into
loft-sh:mainfrom
TECHANOO:fix/4130-dedupe-node-taints
Open

TECHANOO wants to merge 2 commits into
loft-sh:mainfrom
TECHANOO:fix/4130-dedupe-node-taints

Conversation

@TECHANOO

@TECHANOO TECHANOO commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #4130

The node syncer merged host and virtual taints by comparing each taint's full JSON. When both the host and the virtual node lifecycle controller add node.kubernetes.io/unreachable, the timeAdded values differ, so both copies were kept. The apiserver then rejects the update with "taints must be unique by key and effect pair", and the virtual node stops getting refreshed.

This change merges taints on key and effect and keeps the host copy, including its value and timeAdded. A virtual not-ready or unreachable taint is dropped when the host has no taint with that key, and a taint recorded in original-taints counts as removed once its key and effect are gone from the host, even if timeAdded changed. The annotation format is the same, and toleration filtering still runs after the merge.

I added six cases to TestTranslateBackwards. Five of them fail on main and all pass with the fix. go test ./pkg/controllers/resources/nodes/, gofmt and go vet are clean.


Note

Medium Risk
Changes how node taints are reconciled during sync, which affects scheduling and node readiness, but aligns with Kubernetes uniqueness rules and is covered by expanded unit tests.

Overview
Fixes duplicate lifecycle taints when syncing host nodes into the virtual cluster by replacing JSON string–based taint merging with merge by key + effect, where host taints always win (value and timeAdded included).

Virtual not-ready / unreachable taints are dropped if the host has no taint with that key; virtual taints that matched a previously recorded host taint (from vcluster.loft.sh/original-taints) are dropped once the host removes that key/effect. The annotation format and post-merge toleration filtering are unchanged.

TestTranslateBackwards gains six cases covering mismatched timeAdded, virtual-only lifecycle taints, removed host taints, custom taints, and host-value precedence.

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

The node syncer merged taints by comparing the full JSON of each taint.
When the host and the virtual node lifecycle controller both set
node.kubernetes.io/unreachable, the two timeAdded values made two JSON
strings, so both copies were kept. The apiserver requires taints to be
unique by key and effect and rejected the update. The syncer retried
that patch and stopped refreshing the virtual node.

Merge on key and effect and keep the host copy, including value and
timeAdded. Drop a virtual not-ready or unreachable taint when the host
has none with that key. Treat a taint recorded in original-taints as
removed when its key and effect are gone from the host, even if
timeAdded differs. The annotation is still a JSON array of host taint
JSON strings, and toleration filtering still runs after the merge.

Signed-off-by: Prasad PL <ai@anoo.tech>
@TECHANOO
TECHANOO requested a review from a team as a code owner November 12, 2026 15:30

@blacksoxx blacksoxx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment. The identity change is the right fix for #4130: with key and effect as the key, the second unreachable copy with a different timeAdded can no longer reach the apiserver. Verified at e744030 on current main: merge-tree clean, package tests, vet, gofmt and lint green, and the six new cases fail on main's translate.go except the virtual-only custom taint, which matches the body. Two notes inline, neither blocking.

continue
}
// The host used to have this taint and has since removed it.
if _, ok := old[id]; ok {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P3] With key and effect as the identity, a taint the tenant set on the virtual node with the same key and effect as a host taint is dropped the moment the host removes its copy, since the recorded original matches it too. The old string match only dropped an exact copy. Unavoidable with this identity, and following the host is the safer default; one line in the comment would stop the next reader from treating it as a bug.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, agreed. Added a comment saying so in cc2329c.


// dropVirtualLifecycleTaint reports whether a virtual node lifecycle taint should be
// omitted because the host node does not currently have that key.
func dropVirtualLifecycleTaint(key string, physicalKeys map[string]struct{}) bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P3] The lifecycle check is by key only, so a host not-ready:NoSchedule keeps a virtual not-ready:NoExecute alive as a separate identity. That is what the old hasUnready check did for not-ready as well, so no change in behaviour, just noting it is deliberate.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, that's intentional. Added a comment noting it in cc2329c.

Signed-off-by: Prasad PL <ai@anoo.tech>

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.

Node syncer and virtual scheduler can cause conflict with node.kubernetes.io/unreachable taint

2 participants