Skip to content

Commit bbdadb0

Browse files
rnetserRedHatQE
authored andcommitted
Add retry on resource creation (#2572)
1 parent b85e542 commit bbdadb0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ocp_resources/resource.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,15 +1000,18 @@ def wait_for_status(
10001000
self.logger.error(f"Status of {self.kind} {self.name} is {current_status}")
10011001
raise
10021002

1003-
def create(self, wait: bool = False) -> ResourceInstance | None:
1003+
def create(
1004+
self, wait: bool = False, exceptions_dict: dict[type[Exception], list[str]] = DEFAULT_CLUSTER_RETRY_EXCEPTIONS
1005+
) -> ResourceInstance | None:
10041006
"""
10051007
Create resource.
10061008
10071009
Args:
10081010
wait (bool) : True to wait for resource status.
1011+
exceptions_dict (dict[type[Exception], list[str]]): Dictionary of exceptions to retry on.
10091012
10101013
Returns:
1011-
bool: True if create succeeded, False otherwise.
1014+
ResourceInstance | None: Created resource instance or None if create failed.
10121015
"""
10131016
self.to_dict()
10141017

@@ -1020,10 +1023,13 @@ def create(self, wait: bool = False) -> ResourceInstance | None:
10201023
self.logger.info(f"Create {self.kind} {self.name}")
10211024
self.logger.info(f"Posting {hashed_res}")
10221025
self.logger.debug(f"\n{yaml.dump(hashed_res)}")
1023-
resource_kwargs = {"body": self.res, "namespace": self.namespace}
1026+
resource_kwargs: dict[str, Any] = {"body": self.res, "namespace": self.namespace}
10241027
if self.dry_run:
10251028
resource_kwargs["dry_run"] = "All"
1026-
resource_ = self.api.create(**resource_kwargs)
1029+
1030+
resource_ = Resource.retry_cluster_exceptions(
1031+
func=self.api.create, exceptions_dict=exceptions_dict, **resource_kwargs
1032+
)
10271033
with contextlib.suppress(ForbiddenError, AttributeError, NotFoundError):
10281034
# some resources do not support get() (no instance) or the client do not have permissions
10291035
self.initial_resource_version = self.instance.metadata.resourceVersion

0 commit comments

Comments
 (0)