Skip to content

Commit c3d2e83

Browse files
Fix: Project - allow retry (#2591) (#2594)
Co-authored-by: Ruth Netser <rnetser@redhat.com>
1 parent d51e194 commit c3d2e83

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

.github/workflows/code-check.yml.old

Lines changed: 0 additions & 25 deletions
This file was deleted.

ocp_resources/project_request.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
from typing import Any
44

5+
from kubernetes.dynamic.exceptions import ForbiddenError
6+
57
from ocp_resources.project_project_openshift_io import Project
68
from ocp_resources.resource import Resource
9+
from ocp_resources.utils.constants import DEFAULT_CLUSTER_RETRY_EXCEPTIONS, PROTOCOL_ERROR_EXCEPTION_DICT
710

811

912
class ProjectRequest(Resource):
@@ -54,7 +57,14 @@ def deploy(self, wait: bool = False) -> Project: # type: ignore[override]
5457
teardown=self.teardown,
5558
delete_timeout=self.delete_timeout,
5659
)
57-
project.wait_for_status(status=project.Status.ACTIVE)
60+
61+
# When a ProjectRequest is created, the project is created and the user is added to the project.
62+
# RBAC binding may not have propagated yet, causing transient 403 Forbidden errors, so we need to retry
63+
# on ForbiddenError as well.
64+
project.wait_for_status(
65+
status=project.Status.ACTIVE,
66+
exceptions_dict=PROTOCOL_ERROR_EXCEPTION_DICT | DEFAULT_CLUSTER_RETRY_EXCEPTIONS | {ForbiddenError: []},
67+
)
5868

5969
return project
6070

ocp_resources/resource.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,13 @@ def _kube_v1_api(self) -> kubernetes.client.CoreV1Api:
953953
return kubernetes.client.CoreV1Api(api_client=self.client.client)
954954

955955
def wait_for_status(
956-
self, status: str, timeout: int = TIMEOUT_4MINUTES, stop_status: str | None = None, sleep: int = 1
956+
self,
957+
status: str,
958+
timeout: int = TIMEOUT_4MINUTES,
959+
stop_status: str | None = None,
960+
sleep: int = 1,
961+
exceptions_dict: dict[type[Exception], list[str]] = PROTOCOL_ERROR_EXCEPTION_DICT
962+
| DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
957963
) -> None:
958964
"""
959965
Wait for resource to be in status
@@ -962,6 +968,7 @@ def wait_for_status(
962968
status (str): Expected status.
963969
timeout (int): Time to wait for the resource.
964970
stop_status (str): Status which should stop the wait and failed.
971+
exceptions_dict (dict[type[Exception], list[str]]): Dictionary of exceptions to retry on.
965972
966973
Raises:
967974
TimeoutExpiredError: If resource in not in desire status.
@@ -971,10 +978,7 @@ def wait_for_status(
971978
samples = TimeoutSampler(
972979
wait_timeout=timeout,
973980
sleep=sleep,
974-
exceptions_dict={
975-
**PROTOCOL_ERROR_EXCEPTION_DICT,
976-
**DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
977-
},
981+
exceptions_dict=exceptions_dict,
978982
func=lambda: self.exists,
979983
)
980984
current_status = None

0 commit comments

Comments
 (0)