Skip to content

Commit

Permalink
Remove client_wait_deleted function, use wait_deleted (#1897)
Browse files Browse the repository at this point in the history
* Remove clint_wait_deleted function, use wait_deleted

* Remove clint_wait_deleted function, use wait_deleted
  • Loading branch information
myakove authored Jul 11, 2024
1 parent 60d585c commit 6b80a34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
10 changes: 0 additions & 10 deletions ocp_resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,3 @@ def __init__(

def clean_up(self):
Project(name=self.name).delete(wait=True)

def client_wait_deleted(self, timeout):
"""
client-side Wait until resource is deleted
Args:
timeout (int): Time to wait for the resource.
"""
super().client_wait_deleted(timeout=timeout)
27 changes: 8 additions & 19 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,12 @@ def wait_deleted(self, timeout: int = TIMEOUT_4MINUTES) -> bool:
TimeoutExpiredError: If resource still exists.
"""
self.logger.info(f"Wait until {self.kind} {self.name} is deleted")
return self.client_wait_deleted(timeout=timeout)
samples = TimeoutSampler(wait_timeout=timeout, sleep=1, func=lambda: self.exists)
for sample in samples:
if not sample:
return True

return False

@property
def exists(self) -> Optional[ResourceInstance]:
Expand All @@ -706,22 +711,6 @@ def exists(self) -> Optional[ResourceInstance]:
def _kube_v1_api(self) -> kubernetes.client.CoreV1Api:
return kubernetes.client.CoreV1Api(api_client=self.client.client)

def client_wait_deleted(self, timeout: int) -> bool:
"""
client-side Wait until resource is deleted
Args:
timeout (int): Time to wait for the resource.
Raises:
TimeoutExpiredError: If resource still exists.
"""
samples = TimeoutSampler(wait_timeout=timeout, sleep=1, func=lambda: self.exists)
for sample in samples:
if not sample:
return True
return False

def wait_for_status(
self, status: str, timeout: int = TIMEOUT_4MINUTES, stop_status: str | None = None, sleep: int = 1
) -> None:
Expand Down Expand Up @@ -812,12 +801,12 @@ def delete(self, wait: bool = False, timeout: int = TIMEOUT_4MINUTES, body: Dict
hashed_data = self.hash_resource_dict(resource_dict=self.instance.to_dict())
self.logger.info(f"Deleting {hashed_data}")
self.logger.debug(f"\n{yaml.dump(hashed_data)}")

self.api.delete(name=self.name, namespace=self.namespace, body=body)

if wait:
return self.wait_deleted(timeout=timeout)
return True

return True
except (NotFoundError, TimeoutExpiredError):
return False

Expand Down

0 comments on commit 6b80a34

Please sign in to comment.