[release-v1.42] fix(apiserver): prevent calico-apiserver deadlock on direct 3.21-to-3.23 upgrade - #5091
Open
xiumozhan wants to merge 1 commit into
Open
[release-v1.42] fix(apiserver): prevent calico-apiserver deadlock on direct 3.21-to-3.23 upgrade#5091xiumozhan wants to merge 1 commit into
xiumozhan wants to merge 1 commit into
Conversation
….23 upgrade On a direct Calico Enterprise 3.21.x to 3.23.x upgrade the operator moves the calico-apiserver from the tigera-system namespace into calico-system and retargets the v3.projectcalico.org APIService before the apiserver's allow policy is effective. The leftover 3.21-era allow-tigera.default-deny (all() selector, calico-system namespace, allow-tigera tier) still selects the moved pod and drops its egress; the aggregated projectcalico.org/v3 API goes down and the operator's write of calico-system.apiserver-access returns 503 forever. Deadlock, with no self-heal. Write a transitional policy bridge through the still-serving old apiserver, before the workload cutover, reproducing the validated 3.22 intermediate state: - rewrite allow-tigera.default-deny to exclude calico-apiserver, - create an order-1 allow-tigera.apiserver-access in the allow-tigera tier, - create calico-system.apiserver-access. The bridge (render.APIServerMigrationBridge) is ordered before the workload component, so the apply loop's fail-fast behaviour requeues before any cutover if a bridge write fails. Detection uses a shared utils.APIServerMigrationInProgress predicate (the deprecated allow-tigera tier still exists and calico-apiserver is not yet Ready in calico-system), gated on the tier watch and a no-op on the native-CRD path. While migrating, the existing APIServerPolicy component and the kube-controllers and tiers deletions of the transitional allow-tigera.* objects are suppressed; they resume once the apiserver is stable in calico-system, and a periodic reconcile on the tiers controller removes the emptied allow-tigera tier promptly. Unit tests cover the predicate, the bridge rendering, the controller wiring (bridge-before-cutover, failed-write requeue, and the APIServerPolicy gate), and the two cross-controller deletion gates. EV-6821
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #5087 to
release-v1.42(ships Calico Enterprise 3.23.1). The commit is a clean copy of the master change; no manual edits.Description
Bug fix.
On a direct Calico Enterprise 3.21.x → 3.23.x upgrade, the operator moves the
calico-apiserverfrom thetigera-systemnamespace intocalico-systemand retargets thev3.projectcalico.orgAPIService before the apiserver's allow policy is effective. The leftover 3.21-eraallow-tigera.default-deny(selectorall(),calico-systemnamespace,allow-tigeratier) still selects the moved pod and drops its egress to the Kubernetes API, so the aggregatedprojectcalico.org/v3API goes down and the operator's write ofcalico-system.apiserver-accessreturns 503 indefinitely. The result is a deadlock that does not self-heal.This change makes the apiserver controller write a transitional policy "bridge" through the still-serving old apiserver, before the workload cutover, reproducing the intermediate state that the safe two-hop upgrade (via 3.22.x) passes through:
allow-tigera.default-denyto excludecalico-apiserver,allow-tigera.apiserver-accessin theallow-tigeratier,calico-system.apiserver-access.The bridge component is ordered before the workload component, so the controller's fail-fast apply loop requeues before any cutover if a bridge write fails. Detection uses a shared predicate — the deprecated
allow-tigeratier still exists andcalico-apiserveris not yet Ready incalico-system— gated on the tier watch and a no-op on the native-CRD (UseV3CRDs) path. While migrating, the existingAPIServerPolicycomponent and the kube-controllers and tiers deletions of the transitionalallow-tigera.*objects are suppressed; they resume once the apiserver is stable incalico-system, and a periodic reconcile on the tiers controller removes the emptiedallow-tigeratier promptly.Components affected: apiserver controller, installation/kube-controllers policy rendering, tiers controller, apiserver policy renderer.
Testing: unit tests (Ginkgo v2 + Gomega + controller-runtime fake client) covering the migration predicate, the bridge rendering, the controller wiring (bridge-before-cutover, failed-write requeue, and the
APIServerPolicygate), and the two cross-controller deletion gates; all affected packages pass andgo vetis clean. Additionally validated end-to-end on a live Calico Enterprise 3.21.4 → 3.23.1 operator upgrade built from thev1.42.4tag plus this change: the API server migrated tocalico-systemwith the aggregated v3 API staying up (only the normal seconds-long cutover blip), and the transitionalallow-tigera.*policies and theallow-tigeratier were cleaned up automatically, leaving a healthy 3.23.1 install.No API/CRD changes.
Fixes EV-6821.
Release Note
For PR author
make gen-files— n/a, no API changes.make gen-versions— n/a, no version changes.For PR reviewers
kind/bug— this is a bug fix.enterprise— the affected path (aggregated API server,allow-tigera→calico-systemmigration) is Calico Enterprise; the change is a no-op on the OSS native-CRD path.docs-not-required(restores expected upgrade behaviour; no user-facing configuration or API change).