-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(robot): wait for pvc and volume deleted when cleaning up statefulset #2187
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
from kubernetes import client | ||
from kubernetes.client.rest import ApiException | ||
|
||
from persistentvolumeclaim import PersistentVolumeClaim | ||
from volume import Volume | ||
|
||
from utility.constant import LABEL_TEST | ||
from utility.constant import LABEL_TEST_VALUE | ||
from utility.utility import get_retry_count_and_interval | ||
|
@@ -79,7 +82,9 @@ def delete_statefulset(name, namespace='default'): | |
assert e.status == 404 | ||
|
||
retry_count, retry_interval = get_retry_count_and_interval() | ||
for _ in range(retry_count): | ||
for i in range(retry_count): | ||
time.sleep(retry_interval) | ||
logging(f"Waiting for statefulset {name} deleted ... ({i})") | ||
resp = api.list_namespaced_stateful_set(namespace=namespace) | ||
deleted = True | ||
for item in resp.items: | ||
|
@@ -88,9 +93,34 @@ def delete_statefulset(name, namespace='default'): | |
break | ||
if deleted: | ||
break | ||
assert deleted | ||
|
||
claim = PersistentVolumeClaim() | ||
volume_name = None | ||
for i in range(retry_count): | ||
time.sleep(retry_interval) | ||
logging(f"Waiting for pvc of statefulset {name} deleted ... ({i})") | ||
claims = claim.list(label_selector=f"app={name}") | ||
deleted = False | ||
if len(claims) == 0: | ||
deleted = True | ||
break | ||
else: | ||
volume_name = claims[0].spec.volume_name | ||
assert deleted | ||
|
||
if volume_name: | ||
volume = Volume() | ||
for i in range(retry_count): | ||
time.sleep(retry_interval) | ||
logging(f"Waiting for volume {volume_name} deleted ... ({i})") | ||
volumes = volume.list(label_selector=f"longhornvolume={volume_name}") | ||
deleted = False | ||
if len(volumes) == 0: | ||
deleted = True | ||
break | ||
assert deleted | ||
|
||
Comment on lines
+112
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Handle Multiple Volumes During Deletion Similar to the PVC deletion logic, the code is currently checking for the deletion of a single volume. If there are multiple volumes associated with the stateful set, they should all be checked and waited upon during the deletion process. Consider modifying the code to handle deletion checks for all relevant volumes. Suggested Change: Iterate over all collected -if volume_name:
+if volume_names:
volume = Volume()
for volume_name in volume_names:
for i in range(retry_count):
time.sleep(retry_interval)
logging(f"Waiting for volume {volume_name} to be deleted... ({i})")
volumes = volume.list(label_selector=f"longhornvolume={volume_name}")
if len(volumes) == 0:
deleted = True
break
else:
deleted = False
assert deleted
|
||
|
||
def get_statefulset(name, namespace='default'): | ||
api = client.AppsV1Api() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Handle Multiple PersistentVolumeClaims and Associated Volumes
Currently, the code retrieves the
volume_name
from only the first PersistentVolumeClaim (claims[0].spec.volume_name
). If the stateful set has multiple replicas, there may be multiple PVCs and associated volumes. Consider iterating over all claims to handle multiple PVCs and their volumes properly.Suggested Change:
Modify the loop to handle all PVCs and collect their associated volume names: