Skip to content

Add Calico route-reflector label drift problem - #828

Merged
Saadmrp1038 merged 9 commits into
SREGym:mainfrom
thromel:romel/calico-route-reflector-label-drift
Jun 25, 2026
Merged

Saadmrp1038 merged 9 commits into
SREGym:mainfrom
thromel:romel/calico-route-reflector-label-drift

Conversation

@thromel

@thromel thromel commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds calico_route_reflector_label_drift_hotel_reservation, a Hotel Reservation benchmark problem based on Reddit's Pi-Day Kubernetes outage.

The failure is a CNI routing-policy bug. Calico is running in route-reflector mode with node-to-node mesh disabled, but its BGPPeer still selects route reflectors through the old node-role.kubernetes.io/master label. When that label disappears during a Kubernetes label migration, cross-node pod and service traffic breaks even though many pods still look healthy.

This follows RFC #827. The route-reflector setup is done at runtime, so this PR does not change kind/setup_kind_cluster.sh or scripts/ansible/setup_cluster.yml.

Real-world failure story

Reddit's incident writeup describes a Kubernetes 1.23 to 1.24 upgrade where Calico route reflectors still depended on the legacy node-role.kubernetes.io/master label. After the control-plane label migration, Calico BGP peer selection no longer matched the intended route-reflector nodes. The outage looked like broad service instability, but the root cause was stale CNI/BGP peer selection.

Related links:

Fault model

The problem starts from a normal Hotel Reservation deployment on a multi-node kind cluster with Calico BGP available. Fault injection then makes the network topology explicit:

  1. Calico BGPConfiguration/default is set to nodeToNodeMeshEnabled: false.
  2. The control-plane node is annotated with projectcalico.org/RouteReflectorClusterID.
  3. BGPPeer/stale-master-route-reflectors selects has(node-role.kubernetes.io/master).
  4. The old node-role.kubernetes.io/master label is added first so the topology starts healthy.
  5. Hotel Reservation frontend and reservation pods are pinned to different worker nodes.
  6. A platform-health probe is created with one client, one same-node server, and one cross-node server.
  7. The actual fault removes the old master label, so the BGPPeer selector no longer matches a route-reflector node.

The injector waits for direct network evidence: same-node pod traffic still works, while cross-node Pod IP and Service/DNS probes fail.

What reviewers should see at runtime

When the fault is active:

  • BGPConfiguration/default has node-to-node mesh disabled.
  • BGPPeer/stale-master-route-reflectors still exists but no longer selects the route-reflector node.
  • platform-health/east-west-client can reach the same-node server.
  • the same client cannot reach the cross-node server by Pod IP or Service DNS.
  • Hotel Reservation pods may still be Running, so pod phase alone is not enough to diagnose this.

Useful checks:

kubectl get bgpconfiguration default -o yaml
kubectl get bgppeer stale-master-route-reflectors -o yaml

kubectl get node --show-labels | grep -E "control-plane|master|RouteReflector"

kubectl get pod -n platform-health -o wide
kubectl get svc -n platform-health

kubectl -n platform-health exec deploy/east-west-client -- \
  sh -c "wget -T2 -qO- http://east-west-server.platform-health.svc.cluster.local/health"

A good diagnosis should avoid app-level explanations like bad image, broken service selector, DNS-only failure, or Hotel Reservation code. The useful evidence is in Calico BGP configuration, node labels, route-reflector annotations, and cross-node probe behavior.

Expected mitigation

The intended fix is to restore a valid route-reflector peer selection while keeping route-reflector mode enabled:

  • keep nodeToNodeMeshEnabled: false;
  • keep at least one BGPPeer;
  • make the BGPPeer select an actual route-reflector node, either through node-role.kubernetes.io/control-plane, a deliberately restored legacy label, or a stable custom label such as route-reflector=true;
  • ensure every selected peer node has projectcalico.org/RouteReflectorClusterID;
  • let cross-node Pod IP, Service/DNS, and Hotel Reservation probes recover.

The mitigation oracle rejects shortcuts that would hide the fault:

  • enabling node-to-node mesh instead of fixing route-reflector peer selection;
  • deleting the synthetic probe;
  • deleting Calico or BGPPeer resources without restoring cross-node routing;
  • scaling Hotel Reservation deployments down;
  • forcing app or probe pods onto one node;
  • leaving stale unmatched legacy selectors behind;
  • using a broad peer selector that also matches nodes without projectcalico.org/RouteReflectorClusterID.

Code changes

  • sregym/conductor/problems/calico_route_reflector_label_drift.py: problem definition, runtime BGP setup, probe topology, cross-node fault evidence, recovery, and cleanup.
  • sregym/conductor/oracles/calico_route_reflector_mitigation.py: mitigation oracle for route-reflector recovery and shortcut rejection.
  • sregym/conductor/conductor.py: global cleanup for interrupted same-cluster runs.
  • mcp_server/k8s/clusterrole.yaml: node patch/update permissions and Calico BGP resource permissions for MCP use.
  • sregym/conductor/problems/registry.py: registers calico_route_reflector_label_drift_hotel_reservation.
  • Problem List.md: adds the new problem entry.
  • docs/problem-rfcs/calico_route_reflector_label_drift_hotel_reservation.md: RFC and operator-facing notes.
  • tests/problems/test_calico_route_reflector_label_drift.py, tests/oracles/test_calico_route_reflector_mitigation.py, tests/conductor/test_calico_route_reflector_cleanup.py, and tests/mcp/test_mcp_rbac.py: focused coverage for injection, cleanup, oracle checks, and RBAC.

No Python dependencies are added.

Validation

Requested CI validation:

/validate-problem calico_route_reflector_label_drift_hotel_reservation

Local checks run on the clean PR branch:

python3 -m py_compile \
  sregym/conductor/problems/calico_route_reflector_label_drift.py \
  sregym/conductor/oracles/calico_route_reflector_mitigation.py \
  sregym/conductor/conductor.py

uv run pytest -q \
  tests/oracles/test_calico_route_reflector_mitigation.py \
  tests/problems/test_calico_route_reflector_label_drift.py \
  tests/conductor/test_calico_route_reflector_cleanup.py \
  tests/mcp/test_mcp_rbac.py

uv run --with ruff ruff check \
  sregym/conductor/conductor.py \
  sregym/conductor/problems/registry.py \
  sregym/conductor/problems/calico_route_reflector_label_drift.py \
  sregym/conductor/oracles/calico_route_reflector_mitigation.py \
  tests/problems/test_calico_route_reflector_label_drift.py \
  tests/oracles/test_calico_route_reflector_mitigation.py \
  tests/conductor/test_calico_route_reflector_cleanup.py \
  tests/mcp/test_mcp_rbac.py

uv run --with black black --check \
  sregym/conductor/conductor.py \
  sregym/conductor/problems/registry.py \
  sregym/conductor/problems/calico_route_reflector_label_drift.py \
  sregym/conductor/oracles/calico_route_reflector_mitigation.py \
  tests/problems/test_calico_route_reflector_label_drift.py \
  tests/oracles/test_calico_route_reflector_mitigation.py \
  tests/conductor/test_calico_route_reflector_cleanup.py \
  tests/mcp/test_mcp_rbac.py

The focused unit suite passed with 31 tests.

A targeted local lifecycle on kind-sregym-calico-spike also passed: app deploy, fault injection, oracle failure while the fault was active, recovery, oracle success after mitigation, and cleanup. Command used:

uv run python tests/integration/validate_problem.py \
  --problem calico_route_reflector_label_drift_hotel_reservation \
  --summary /tmp/calico-route-reflector-validation-final.md \
  --inject-timeout 300 \
  --recover-timeout 600 \
  --poll-interval 15

That run passed in 1210s.

Local environment note: the lifecycle run needed /run/udev materialized inside the kind nodes for OpenEBS NDM. That was a local cluster setup issue, not a problem-code change.

No agent-run result is claimed here. The evidence for this PR is the lifecycle validation and the Calico state described above.

@Saadmrp1038

Saadmrp1038 commented May 31, 2026 •

Copy link
Copy Markdown
Collaborator

@thromel

the lifecycle run needed /run/udev materialized inside the kind nodes for OpenEBS NDM.

Are you using mac?

@thromel

thromel commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

@thromel

the lifecycle run needed /run/udev materialized inside the kind nodes for OpenEBS NDM.

Are you using mac?

Yes, I am running this locally on mac.

@Saadmrp1038

Copy link
Copy Markdown
Collaborator

@thromel I see. Thanks for the info.
Another person also faced this /run/udev issue on mac. Looking into this.

@Saadmrp1038

Copy link
Copy Markdown
Collaborator

@thromel just a heads-up since you already have a previous PR and there are already so many pending PRs, it will probably take 1 week+ for me to get to this one. I am treating the first PR as the eval task.

@tianyin

tianyin commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

@munimthahmid will help review it.

@tianyin tianyin added benchmark Benchmark platform-related issues and removed low-priority labels Jun 21, 2026
Comment thread sregym/conductor/conductor.py Resolved
Comment thread Problem List.md Resolved
Comment thread Problem List.md Resolved
Comment thread mcp_server/k8s/clusterrole.yaml Resolved

@munimthahmid munimthahmid left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@thromel The failure implementation and mitigation logic look mostly correct. I left a few inline comments on minor issues. Could you please address them?

After addressing them, could you also run the problem end to end with an agent and share how the agent performs, including the diagnosis and mitigation results and any timeouts or difficulties encountered? That would be greatly appreciated.

@thromel

thromel commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

I pushed the review fixes and resolved the threads.

What changed:

  • Agent-visible names are generic now, so the problem text does not give away the Calico route-reflector failure.
  • The problem snapshots the original BGPConfiguration/default, node labels/annotations, and existing BGPPeers before mutation. Cleanup can now restore the cluster state that was already there.
  • Reinjection cleanup removes problem-owned residue before baseline capture.
  • platform-checks is treated as unsafe if it already exists without this problem's ownership label. Cleanup only deletes that namespace when this problem created it.
  • Cleanup also removes BGPPeers created during the run, including valid differently named replacement peers accepted by the mitigation oracle.
  • Added read-only discovery.k8s.io/endpointslices RBAC for the Kubernetes MCP role.
  • Fixed the Codex container install issue found during the e2e run. The install script now checks codex exec and installs the missing Linux ARM64 optional package when npm skips it.

Checks:

  • Local focused tests: 42 passed for the Calico problem, conductor cleanup, mitigation oracle, and MCP RBAC tests.
  • ruff check, ruff format --check, and git diff --check passed.
  • Rebuilt sregym-agent-base:latest; Codex install smoke test passed with codex-cli 0.141.0.
  • GitHub checks are green on 4ee73a3f: lint, resolve, validate, smoke-test, and codeql-custom.
  • There are no failing PR checks right now. The only non-success entry is a skipped Claude Code run from comment activity.

Codex run:

  • Ran codex with gpt-5.5 on calico_route_reflector_label_drift_hotel_reservation with --agent-timeout 3600.
  • Result file: results/0622_0426/codex_ALL_results.csv.
  • The run finished end to end. Codex diagnosed the BGPPeer/cluster-peer-policy selector drift: the peer selector still targeted deprecated node-role.kubernetes.io/master, while the actual route-reflector node only had node-role.kubernetes.io/control-plane.
  • Mitigation succeeded. CSV timing: TTL=1620.64s, TTM=1731.90s, Mitigation.success=True.
  • The first Codex attempt exposed the missing Linux ARM64 Codex package in the agent image; that fix is included here. During local setup, Loki chunks-cache also needed the same cluster-only memory reduction used in earlier local e2e runs.
  • I regraded the saved diagnosis with openai/gpt-5.5 using the clipboard credentials: verdict=True, composite_score=0.89, D1=1.00, D2=1.00, D3=0.67.

@tianyin
tianyin requested a review from munimthahmid June 22, 2026 02:31

@munimthahmid munimthahmid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@thromel Everything looks good except for one minor issue. Could you take a look when you have a chance?

I ran three agent evaluations on this scenario, and the overall takeaway is that it is not easy for the agents, which is good:

  1. Claude Sonnet 4.6 spent more than 40 minutes diagnosing the issue, chasing symptoms, and never converged on a root cause before I stopped it(it was burning tokens :) ).
  2. One Codex GPT-5.5 run only "succeeded" by reading the leaked harness problem ID from mounted /logs artifacts and jumping straight to the fix, so its mitigation success is contaminated (#905 ).
  3. Another Codex GPT-5.5 run got the diagnosis mostly right, correctly identifying the stale master vs control-plane label mismatch in the Calico BGPPeer selector, but its mitigation was rejected because it enabled full node-to-node mesh instead of preserving the intended route-reflector topology.

@munimthahmid munimthahmid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot, @thromel, for being patient and fixing all the issues. I ran one more end-to-end run, and it's working properly. Looks good to me. @Saadmrp1038 can have a look and merge it if everything is fine

@Saadmrp1038

Copy link
Copy Markdown
Collaborator

Works Great!

@Saadmrp1038
Saadmrp1038 merged commit bcec38f into SREGym:main Jun 25, 2026
5 checks passed
vsmart-06 pushed a commit to vsmart-06/SREGym that referenced this pull request Jul 12, 2026
* Add Calico route-reflector label drift problem

* Address Calico route-reflector review comments

* Harden Calico cleanup ownership tracking

* Fix Codex agent install verification

* Tighten Codex platform package detection

* Restore kubelet eviction reset cleanup

* Neutralize Calico ownership metadata

---------

Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Saadmrp1038 added a commit that referenced this pull request Jul 22, 2026
* Updated default mitigation oracle

* Stop timeout for 0 replicas

* TBC in CloudLab

* Pushing all attempts at the problem

* Enable idempotence

* Add mutating_webhook_resource_limits problem (#847)

* Add mutating_webhook_resource_limits problem

* Add mutating_webhook_resource_limits to Problem List

* mutating_webhook_resource_limits problem docstring fix

Removed incorrect information about mitigation options.

* Additions to mutating_webhook_limits_resource_limits problem

 - Memory limit/request patching before activating the webhook
 - Decoy pods for increased complexity

* More additions to mutating_webhook problem

 - Make decoys realisticly named
 - Similar minor changes

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Derive the default problem namespace from the application (#876)

* add the the probem redundency

* base.

* the fixed and dynamic app name are fixed. hte namespace are also fixed.

* unessessry formating is reverted.

* unessessry formating is reverted.

* formating correction.

* formating correction.

* formating correction.

* add fault injection decorator markers to test_problem_bsae.py

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Confluent kafka attempt

* Custom image attempt

* Threaded producer and added consumer

* Syntax error

* Added some imports

* fix edge cases

* run ruff check adn format

* New OOM attempt

* Force crash on OOM

* Add file_descriptor_exhaustion problem (#832)

* add file_descriptor_exhaustion problem

* Modify fault injection and recovery methods

* Fix fault recovery

* Change fault injection method
Add fault injection by flooding connections

* Update fault injection method and add custom oracle

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Finalizer deadlock controller clean (#873)

* finalizzer code is reaoslve dadlock benchmark.

* yaml file corrected.

* reverting hte comments back to their place.

* read only rbac

* controller log is generalized and avoiding any sregym related name exposing.

* applied ruff linter formatter accordingly.

* replace metadata naming and includding all the oprations on mitigation side.

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add: secret_rotation_stale_env_credentials_astronomy_shop problem (#851)

* Add secret rotation stale env credentials problem

* Simplify secret rotation mitigation oracle checks

* Require rotated PostgreSQL in oracle

* Fix stale DB credential rotation shortcuts

  - Remove old password from postgresql-init ConfigMap
  - Keep PostgreSQL password rotation durable after pod restart
  - Reject mitigations that revert otelu to the old password
  - Remove old password leaks from unrelated pods

* Fix fault recovery to satisfy the oracle

* Fix problem registry import ordering

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add cumulative_admission_webhook_timeout_hotel_reservation problem (#886)

* Add cumulative_admission_webhook_timeout_hotel_reservation problem

* Pin webhook backends to worker nodes via nodeAffinity

* Make webhook backends realistic admission services

Replace the dummy webhook backends with HTTPS admission servers that terminate TLS using Secret-mounted certificates, validate AdmissionReview

requests, and return proper admission responses. Certificates are signed by the same CA referenced in each webhook's `caBundle`, with SANs

covering the backend Service DNS names.

The admission logic enforces a trusted image registry allowlist and a

per-container CPU limit. All Hotel Reservation workloads satisfy these

policies, so the webhooks remain transparent during normal operation and

recovery.

Also:
* Vary webhook `timeoutSeconds` (12, 8, 11, 9) to make the cumulative
  timeout less obvious.

* Rename the CA CN from `sregym-webhook-ca` to
  `compliance-webhook-ca`.

* Remove a duplicate `rule.from_` check in the oracle.

* Fix create-or-replace handling for webhooks, NetworkPolicies,
  Deployments, and Services so re-injection updates existing resources
  instead of failing or silently skipping changes.

* Model the fault as a missing apiserver NetworkPolicy allow

* Model the fault as a missing apiserver allow with a near-miss policy

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add psa_restricted_blocks_recreation problem (#891)

Labelling a namespace pod-security.kubernetes.io/enforce=restricted leaves
running pods untouched but makes the apiserver reject recreated pods that run
as root / set no seccomp profile, so a deployment silently goes
under-replicated. Unlike the existing webhook problems, the policy is enforced
by the apiserver via a namespace label, not a webhook config.

* Add copilot cli agent (#893)

* add copilot cli agent

* remove -s flag

* Fix MCP retry error handling and CRLF parsing in CI (#896)

* fix(mcp): broaden MCP retry exceptions and return error instead of raising

* fix(ci): strip CRLF from PR description before parsing problem ID

* Fix kind cluster detection (#897)

* Fix custom kind cluster detection

* Handle failed kind detection output

* fix edge cases

* run ruff check adn format

* Shell state persistence (#903)

* Include shell persistence

* Include shell persistence

* Isolate problem IDs from agent runtime artifacts

* update SREGym-applications (18620ed) (#910)

* Add Calico route-reflector label drift problem (#828)

* Add Calico route-reflector label drift problem

* Address Calico route-reflector review comments

* Harden Calico cleanup ownership tracking

* Fix Codex agent install verification

* Tighten Codex platform package detection

* Restore kubelet eviction reset cleanup

* Neutralize Calico ownership metadata

---------

Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Fail alert oracle on Prometheus query errors (#912)

* Decouple failure configmaps from mongo pods in `hotel-reservation` (#899)

* decouple failure configmaps from mongo pods

* remove empty failure configmaps creation

* Support local LLM endpoints for Stratus and OpenCode (#917)

* Support local LLM endpoints for Stratus

* Prefer env vars for local LLM endpoints

* Support local LLM endpoints for OpenCode

* Route local endpoints into agent containers

* Normalize OpenCode local judge models

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Preflight check the judge model (#924)

* Add support for uniform agent trajectory (ATIF format) (#918)

* add support for ATIF trajectory conversion and normalization, add claudecode adapter

* fix: make _finish_problem idempotent

* isolate .codex mount in container runner

* better temp dir cleanup

* add codex adapter

* add opencode adapter

* add copilot adapter

* add stratus adapter

* fix antropic caching for stratus

* add gemini adapter

* store normalized ATIF trajectories in SQLite indexed by problem type

* edge tests

* bump litellm, tikoken

* update docker lib versions

* Add node_clock_drift Problem  (#894)

* adding clock drift problem

* fixing race condition causing sidecar log delay

* fixing recover_fault to reverse time sync removal applied, improve cleanup

* global cleanup added + fixed restoration for node_clock_drift problem

* fixing mitigation oracle to ensure correct node checked

* adding problem to non emulated cluster problems list

* extending wait

* indentation error fix

* fixing time restoration in global cleanup

* adding in check to make sure it picks worker node

* adding another control plane filter, fixing clock step-back in global recovery

* increase sidecar rollout timeout, make podnames/labels generic, idempotancy check

* formatting fixes

* format fix

* fix

* fix ruff check/format issues

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Minimum viable python version

* Changed diagnosis oracle

* Cleaned up fault recovery

* Edit tasklist.yml

* Removed old Java artifacts

* Updated mitigation oracle to be more robust

* Added polling

* Fail Kafka producer leak injection on timeout

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Co-authored-by: Kerem Akcalioglu <[email protected]>
Co-authored-by: ermias mulugeta <[email protected]>
Co-authored-by: Tejas Shukla <[email protected]>
Co-authored-by: Petr Myagkov <[email protected]>
Co-authored-by: Omar Faruqe Riyad <[email protected]>
Co-authored-by: Mohammad Tamimul Ehsan <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Om Kumar <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Tanzim Hossain Romel <[email protected]>
Co-authored-by: haani-maybe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark Benchmark platform-related issues problem Adding a new problem to the benchmark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants