Skip to content

Commit

Permalink
remove garbage collector dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad-Hafe committed Dec 23, 2024
1 parent cd0b906 commit 75d87bd
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions ocp_resources/datavolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def __init__(
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
api_name="pvc",
delete_after_completion=None,
**kwargs,
):
"""
Expand Down Expand Up @@ -121,7 +120,6 @@ def __init__(
yaml_file (yaml, default: None): yaml file for the resource.
delete_timeout (int, default: 4 minutes): timeout associated with delete action.
api_name (str, default: "pvc"): api used for DV, pvc/storage
delete_after_completion (str, default: None): annotation for garbage collector - "true"/"false"
"""
super().__init__(
name=name,
Expand All @@ -148,7 +146,6 @@ def __init__(
self.bind_immediate_annotation = bind_immediate_annotation
self.preallocation = preallocation
self.api_name = api_name
self.delete_after_completion = delete_after_completion

def to_dict(self) -> None:
super().to_dict()
Expand Down Expand Up @@ -196,10 +193,6 @@ def to_dict(self) -> None:
}
if self.preallocation is not None:
self.res["spec"]["preallocation"] = self.preallocation
if self.delete_after_completion:
self.res["metadata"].setdefault("annotations", {}).update({
f"{self.api_group}/storage.deleteAfterCompletion": (self.delete_after_completion)
})

def wait_deleted(self, timeout=TIMEOUT_4MINUTES):
"""
Expand Down Expand Up @@ -244,7 +237,6 @@ def scratch_pvc(self):
def _check_none_pending_status(self, failure_timeout=TIMEOUT_2MINUTES):
# Avoid waiting for "Succeeded" status if DV's in Pending/None status
sample = None
# if garbage collector is enabled, DV will be deleted after success
try:
for sample in TimeoutSampler(
wait_timeout=failure_timeout,
Expand All @@ -270,18 +262,16 @@ def wait_for_dv_success(
self,
timeout=TIMEOUT_10MINUTES,
failure_timeout=TIMEOUT_2MINUTES,
dv_garbage_collection_enabled=False,
stop_status_func=None,
*stop_status_func_args,
**stop_status_func_kwargs,
):
"""
Wait until DataVolume succeeded with or without DV Garbage Collection enabled
Wait until DataVolume succeeded
Args:
timeout (int): Time to wait for the DataVolume to succeed.
failure_timeout (int): Time to wait for the DataVolume to have not Pending/None status
dv_garbage_collection_enabled (bool, default: False): if True, expect that DV will disappear after success
stop_status_func (function): function that is called inside the TimeoutSampler
if it returns True - stop the Sampler and raise TimeoutExpiredError
Example:
Expand All @@ -307,11 +297,8 @@ def test_dv():
wait_timeout=timeout,
func=lambda: self.exists,
):
# DV reach success if the status is Succeeded, or if DV garbage collection enabled and the DV does not exist
if sample and sample.get("status", {}).get("phase") == self.Status.SUCCEEDED:
break
elif sample is None and dv_garbage_collection_enabled:
break
elif stop_status_func and stop_status_func(*stop_status_func_args, **stop_status_func_kwargs):
raise TimeoutExpiredError(
value=(
Expand Down Expand Up @@ -339,8 +326,5 @@ def delete(self, wait=False, timeout=TIMEOUT_4MINUTES, body=None):
Returns:
bool: True if delete succeeded, False otherwise.
"""
# if garbage collector is enabled, DV will be deleted after success
if self.exists:
return super().delete(wait=wait, timeout=timeout, body=body)
else:
return self.pvc.delete(wait=wait, timeout=timeout, body=body)
return super().delete(wait=wait, timeout=timeout, body=body)

0 comments on commit 75d87bd

Please sign in to comment.