Skip to content

Commit 0897b96

Browse files
committed
Removes unnecessary sandboxclaim watch
1 parent 6c5f151 commit 0897b96

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

clients/python/agentic-sandbox-client/agentic_sandbox/sandbox_client.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
SANDBOX_PLURAL_NAME = "sandboxes"
4040

4141
logging.basicConfig(level=logging.INFO,
42-
format='%(asctime)s - %(levelname)s - %(message)s', stream=sys.stdout)
42+
format='%(asctime)s - %(levelname)s - %(message)s',
43+
stream=sys.stdout)
4344

4445

4546
@dataclass
@@ -129,39 +130,13 @@ def _create_claim(self):
129130

130131
def _wait_for_sandbox_ready(self):
131132
"""
132-
Waits for the SandboxClaim to be populated with the Sandbox name, and then
133-
waits for the Sandbox custom resource to have a 'Ready' status condition.
133+
Waits for the Sandbox custom resource to have a 'Ready' status condition.
134134
This indicates that the underlying pod is running and has passed its checks.
135135
"""
136136
if not self.claim_name:
137137
raise RuntimeError(
138138
"Cannot wait for sandbox, claim has not been created.")
139139

140-
# Watch for the SandboxClaim to be updated with the sandbox name
141-
w_claim = watch.Watch()
142-
for event in w_claim.stream(
143-
self.custom_objects_api.list_namespaced_custom_object,
144-
namespace=self.namespace,
145-
group=CLAIM_API_GROUP,
146-
version=CLAIM_API_VERSION,
147-
plural=CLAIM_PLURAL_NAME,
148-
field_selector=f"metadata.name={self.claim_name}",
149-
timeout_seconds=self.sandbox_ready_timeout
150-
):
151-
if event["type"] in ["ADDED", "MODIFIED"]:
152-
claim_obj = event["object"]
153-
status = claim_obj.get("status", {})
154-
sandbox_status = status.get("sandbox", {})
155-
if sandbox_status and sandbox_status.get("Name"):
156-
self.sandbox_name = sandbox_status.get("Name")
157-
w_claim.stop()
158-
break
159-
else:
160-
self.__exit__(None, None, None) # Attempt cleanup
161-
raise TimeoutError(
162-
f"SandboxClaim did not become ready within {self.sandbox_ready_timeout} seconds.")
163-
164-
# Watch for the Sandbox to become ready
165140
w = watch.Watch()
166141
logging.info("Watching for Sandbox to become ready...")
167142
for event in w.stream(
@@ -170,7 +145,7 @@ def _wait_for_sandbox_ready(self):
170145
group=SANDBOX_API_GROUP,
171146
version=SANDBOX_API_VERSION,
172147
plural=SANDBOX_PLURAL_NAME,
173-
field_selector=f"metadata.name={self.sandbox_name}",
148+
field_selector=f"metadata.name={self.claim_name}",
174149
timeout_seconds=self.sandbox_ready_timeout
175150
):
176151
if event["type"] in ["ADDED", "MODIFIED"]:
@@ -184,6 +159,7 @@ def _wait_for_sandbox_ready(self):
184159
break
185160

186161
if is_ready:
162+
self.sandbox_name = sandbox_object['metadata']['name']
187163
annotations = sandbox_object.get(
188164
'metadata', {}).get('annotations', {})
189165
pod_name_annotation = "agents.x-k8s.io/pod-name"
@@ -197,7 +173,7 @@ def _wait_for_sandbox_ready(self):
197173
logging.info(f"Sandbox {self.sandbox_name} is ready.")
198174
break
199175

200-
if not self.pod_name:
176+
if not self.sandbox_name:
201177
self.__exit__(None, None, None)
202178
raise TimeoutError(
203179
f"Sandbox did not become ready or pod name could not be determined within {self.sandbox_ready_timeout} seconds.")

0 commit comments

Comments
 (0)