Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/code-check.yml.old

This file was deleted.

12 changes: 11 additions & 1 deletion ocp_resources/project_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

from typing import Any

from kubernetes.dynamic.exceptions import ForbiddenError

from ocp_resources.project_project_openshift_io import Project
from ocp_resources.resource import Resource
from ocp_resources.utils.constants import DEFAULT_CLUSTER_RETRY_EXCEPTIONS, PROTOCOL_ERROR_EXCEPTION_DICT


class ProjectRequest(Resource):
Expand Down Expand Up @@ -54,7 +57,14 @@ def deploy(self, wait: bool = False) -> Project: # type: ignore[override]
teardown=self.teardown,
delete_timeout=self.delete_timeout,
)
project.wait_for_status(status=project.Status.ACTIVE)

# When a ProjectRequest is created, the project is created and the user is added to the project.
# RBAC binding may not have propagated yet, causing transient 403 Forbidden errors, so we need to retry
# on ForbiddenError as well.
project.wait_for_status(
status=project.Status.ACTIVE,
exceptions_dict=PROTOCOL_ERROR_EXCEPTION_DICT | DEFAULT_CLUSTER_RETRY_EXCEPTIONS | {ForbiddenError: []},
)

return project

Expand Down
14 changes: 9 additions & 5 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,13 @@ def _kube_v1_api(self) -> kubernetes.client.CoreV1Api:
return kubernetes.client.CoreV1Api(api_client=self.client.client)

def wait_for_status(
self, status: str, timeout: int = TIMEOUT_4MINUTES, stop_status: str | None = None, sleep: int = 1
self,
status: str,
timeout: int = TIMEOUT_4MINUTES,
stop_status: str | None = None,
sleep: int = 1,
exceptions_dict: dict[type[Exception], list[str]] = PROTOCOL_ERROR_EXCEPTION_DICT
| DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
) -> None:
"""
Wait for resource to be in status
Expand All @@ -966,6 +972,7 @@ def wait_for_status(
status (str): Expected status.
timeout (int): Time to wait for the resource.
stop_status (str): Status which should stop the wait and failed.
exceptions_dict (dict[type[Exception], list[str]]): Dictionary of exceptions to retry on.

Raises:
TimeoutExpiredError: If resource in not in desire status.
Expand All @@ -975,10 +982,7 @@ def wait_for_status(
samples = TimeoutSampler(
wait_timeout=timeout,
sleep=sleep,
exceptions_dict={
**PROTOCOL_ERROR_EXCEPTION_DICT,
**DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
},
exceptions_dict=exceptions_dict,
func=lambda: self.exists,
)
current_status = None
Expand Down