Skip to content

Commit da4d2c2

Browse files
authored
Fix: Project - allow retry (#2591)
1 parent c78e2d9 commit da4d2c2

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
@@ -957,7 +957,13 @@ def _kube_v1_api(self) -> kubernetes.client.CoreV1Api:
957957
return kubernetes.client.CoreV1Api(api_client=self.client.client)
958958

959959
def wait_for_status(
960-
self, status: str, timeout: int = TIMEOUT_4MINUTES, stop_status: str | None = None, sleep: int = 1
960+
self,
961+
status: str,
962+
timeout: int = TIMEOUT_4MINUTES,
963+
stop_status: str | None = None,
964+
sleep: int = 1,
965+
exceptions_dict: dict[type[Exception], list[str]] = PROTOCOL_ERROR_EXCEPTION_DICT
966+
| DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
961967
) -> None:
962968
"""
963969
Wait for resource to be in status
@@ -966,6 +972,7 @@ def wait_for_status(
966972
status (str): Expected status.
967973
timeout (int): Time to wait for the resource.
968974
stop_status (str): Status which should stop the wait and failed.
975+
exceptions_dict (dict[type[Exception], list[str]]): Dictionary of exceptions to retry on.
969976
970977
Raises:
971978
TimeoutExpiredError: If resource in not in desire status.
@@ -975,10 +982,7 @@ def wait_for_status(
975982
samples = TimeoutSampler(
976983
wait_timeout=timeout,
977984
sleep=sleep,
978-
exceptions_dict={
979-
**PROTOCOL_ERROR_EXCEPTION_DICT,
980-
**DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
981-
},
985+
exceptions_dict=exceptions_dict,
982986
func=lambda: self.exists,
983987
)
984988
current_status = None

0 commit comments

Comments
 (0)