Skip to content

Commit

Permalink
refactor(robot): allow to skip retry for pvc expansion
Browse files Browse the repository at this point in the history
longhorn/longhorn-6633

Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Dec 9, 2024
1 parent e19c13c commit e506d3e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions e2e/libs/keywords/workload_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ def wait_for_workload_volume_detached(self, workload_name):
logging(f'Waiting for {workload_name} volume {volume_name} to be detached')
self.volume.wait_for_volume_detached(volume_name)

def expand_workload_claim_size(self, workload_name, size_in_byte, claim_index=0):
def expand_workload_claim_size(self, workload_name, size_in_byte, claim_index=0, skip_retry=False):
claim_name = get_workload_persistent_volume_claim_name(workload_name, index=claim_index)
current_size = self.persistentvolumeclaim.get(claim_name).spec.resources.requests['storage']
current_size_byte = convert_size_to_bytes(current_size)

logging(f'Expanding {workload_name} persistentvolumeclaim {claim_name} from {current_size_byte} to {size_in_byte}')
self.persistentvolumeclaim.expand(claim_name, size_in_byte)
self.persistentvolumeclaim.expand(claim_name, size_in_byte, skip_retry=skip_retry)

def wait_for_workload_claim_size_expanded(self, workload_name, claim_index=0):
claim_name = get_workload_persistent_volume_claim_name(workload_name, index=claim_index)
Expand Down
5 changes: 3 additions & 2 deletions e2e/libs/persistentvolumeclaim/crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ def get_volume_name(self, claim_name, claim_namespace="default"):
claim = self.get(claim_name, claim_namespace)
return claim.spec.volume_name

def expand(self, claim_name, size, namespace="default"):
for i in range(self.retry_count):
def expand(self, claim_name, size, namespace="default", skip_retry=False):
retry_count = 1 if skip_retry else self.retry_count
for i in range(retry_count):
logging(f"Trying to expand pvc {claim_name} to size {size} ... ({i})")
try:
self.core_v1_api.patch_namespaced_persistent_volume_claim(
Expand Down
4 changes: 2 additions & 2 deletions e2e/libs/persistentvolumeclaim/persistentvolumeclaim.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def get_annotation_value(self, claim_name, annotation_key):
def get_volume_name(self, claim_name):
return self.claim.get_volume_name(claim_name)

def expand(self, claim_name, size_in_byte):
def expand(self, claim_name, size_in_byte, skip_retry=False):
pvc = self.claim.get(claim_name)
current_size = int(pvc.spec.resources.requests['storage'])

target_size = current_size + size_in_byte
logging(f"Expanding PVC {claim_name} from {current_size} to {target_size}")
expanded_size = self.claim.expand(claim_name, target_size)
expanded_size = self.claim.expand(claim_name, target_size, skip_retry=skip_retry)
self.set_annotation(claim_name, ANNOT_EXPANDED_SIZE, str(expanded_size))

0 comments on commit e506d3e

Please sign in to comment.