Skip to content

fix(pods): sanitize topology spread matchLabelKeys before host sync#3807

Open
officialasishkumar wants to merge 2 commits intoloft-sh:mainfrom
officialasishkumar:fix/topologyspread-matchlabelkeys
Open

fix(pods): sanitize topology spread matchLabelKeys before host sync#3807
officialasishkumar wants to merge 2 commits intoloft-sh:mainfrom
officialasishkumar:fix/topologyspread-matchlabelkeys

Conversation

@officialasishkumar
Copy link
Copy Markdown

What issue type does this pull request address? (keep at least one, remove the others)
/kind bugfix

What does this pull request do? Which issues does it resolve? (use resolves #<issue_number> if possible)
Sanitizes API-server-merged topologySpreadConstraints.matchLabelKeys expressions before syncing pods to the host cluster, so the host API server can apply its own mutation step without rejecting the pod as invalid.

resolves #3668

Please provide a short message that should be published in the vcluster release notes
Fixed an issue where pods using topologySpreadConstraints.matchLabelKeys could fail to sync to host clusters running Kubernetes 1.34+.

What else do we need to know?
Validation:

  • go test ./pkg/controllers/resources/pods/translate -run TestTranslateTopologySpreadConstraints -count=1 -v
  • go test ./pkg/controllers/resources/pods/...

E2E Tests

Default Test Execution

The mandatory PR suite runs automatically. Only specify additional test suites below if needed.

Adding New Test Suites

When adding a new ginkgo test suite:

  • Add labels to the test suite
  • Update label-filter section below to execute the new test suite
  • Verify test suite runs in CI/CD pipeline

Additional test suites

Additional test suite(s) that will be executed before the mandatory PR suite:

none

@officialasishkumar officialasishkumar requested a review from a team as a code owner April 8, 2026 09:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57e52c6646

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +961 to +962
value, ok := podLabels[requirement.Key]
return ok && requirement.Values[0] == value
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Strip matchLabelKeys expression even when pod label changed

This sanitization only removes a matchLabelKeys-derived expression when the selector value still equals the pod's current label value. If that label was later changed or removed (pod labels are mutable), the API-server-injected expression becomes stale but is still invalid to keep alongside MatchLabelKeys, so the host API server can still reject the synced pod on 1.34+. The filter should strip requirements keyed by MatchLabelKeys regardless of current label equality.

Useful? React with 👍 / 👎.

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.

Updated in c605e3d: requirements keyed by MatchLabelKeys are now stripped regardless of the pod's current label value, and the test covers the stale-label case.

Kubernetes 1.34+ mutates topology spread selectors during pod creation by merging matchLabelKeys into matchExpressions. When vCluster forwards that already-mutated pod to the host API server, the host rejects the create because the same key exists in both matchLabelKeys and labelSelector.

Strip only the API-server-generated key-in-value requirements before translating the selector so the host API server can apply its own mutation step again. Add a translator unit test that covers the pod-template-hash case from the reported sync failure.
@officialasishkumar officialasishkumar force-pushed the fix/topologyspread-matchlabelkeys branch from 57e52c6 to c605e3d Compare April 9, 2026 18:05
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 fails to create pods on host when topologySpreadConstraints uses matchLabelKeys (k8s 1.34+ API server mutation conflict)

1 participant