Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(toolbox): keep the warpstream client label when claiming a pod (#123681)

Eli Reismanbf8be635bb0a
diff --git a/tools/infra-scripts/clitools/test_toolbox.py b/tools/infra-scripts/clitools/test_toolbox.py
index 74bf11f77028..3824c62fb8b9 100644
--- a/tools/infra-scripts/clitools/test_toolbox.py
+++ b/tools/infra-scripts/clitools/test_toolbox.py
@@ -652,6 +652,26 @@ class TestToolbox(unittest.TestCase):
self.assertIn("--resource-version=42", strip_args)
self.assertNotIn("--resource-version=42", annotate_args)
+ @patch("subprocess.run")
+ def test_claim_pod_keeps_the_warpstream_client_label(self, mock_run):
+ """The claim orphans the pod but keeps the label that lets it produce to WarpStream."""
+ mock_get_response = MagicMock()
+ mock_get_response.stdout = json.dumps(
+ {
+ "app.kubernetes.io/name": "posthog-toolbox-django",
+ "app.kubernetes.io/component": "app",
+ "pod-template-hash": "abc123",
+ "posthog.com/warpstream-client": "true",
+ }
+ )
+ mock_run.side_effect = [mock_get_response, *(MagicMock() for _ in range(4))]
+
+ claim_pod("toolbox-pod-1", {"toolbox-claimed": "u_at_posthog.com"}, 1234567890, namespace="posthog")
+
+ strip_args = mock_run.call_args_list[1][0][0]
+ self.assertEqual(strip_args[-2:], ["app.kubernetes.io/component-", "pod-template-hash-"])
+ self.assertFalse(any(arg.startswith("posthog.com/warpstream-client") for arg in strip_args))
+
@patch("subprocess.run")
def test_claim_pod_raises_claim_race_error_on_conflict(self, mock_run):
"""A 409 Conflict on the first mutation surfaces as ClaimRaceError so the caller can retry."""
diff --git a/tools/infra-scripts/clitools/toolbox/pod.py b/tools/infra-scripts/clitools/toolbox/pod.py
index 15be583ab4f1..ad1f2b1a234e 100644
--- a/tools/infra-scripts/clitools/toolbox/pod.py
+++ b/tools/infra-scripts/clitools/toolbox/pod.py
@@ -10,6 +10,10 @@ from datetime import datetime, timedelta
from toolbox.kubernetes import kubectl_cmd
+# Labels a claim keeps. The WarpStream agents accept Kafka traffic only from pods with
+# posthog.com/warpstream-client, so a claimed pod without it cannot produce to Kafka.
+KEPT_LABELS = frozenset({"app.kubernetes.io/name", "posthog.com/warpstream-client"})
+
class ClaimRaceError(Exception):
"""Raised when a claim attempt loses an optimistic-concurrency race.
@@ -159,7 +163,7 @@ def claim_pod(
successful write; once the first mutation has won, no other writer can
sneak in mid-claim.
- Strips every label except app.kubernetes.io/name (which orphans the pod from
+ Strips every label except those in ``KEPT_LABELS`` (which orphans the pod from
its ReplicaSet by removing pod-template-hash), annotates karpenter to skip
disruption, then applies user_labels + a terminate-after timestamp.
"""
@@ -175,7 +179,7 @@ def claim_pod(
current_labels = json.loads(result.stdout)
- labels_to_remove = [name for name in current_labels.keys() if name != "app.kubernetes.io/name"]
+ labels_to_remove = [name for name in current_labels.keys() if name not in KEPT_LABELS]
# Attach the optimistic-concurrency guard to whichever kubectl invocation is the first
# actual write; once it succeeds, the resourceVersion advances and subsequent calls
# don't need (and can't pass) the same value.