diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index 85264bc015..1169e00fa5 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -978,7 +978,12 @@ def wait_for_status( self.logger.error(f"Status of {self.kind} {self.name} is {current_status}") raise - def create(self, wait: bool = False) -> ResourceInstance | None: + def create( + self, + wait: bool = False, + exceptions_dict: dict[type[Exception], list[str]] = DEFAULT_CLUSTER_RETRY_EXCEPTIONS + | PROTOCOL_ERROR_EXCEPTION_DICT, + ) -> ResourceInstance | None: """ Create resource. @@ -986,7 +991,7 @@ def create(self, wait: bool = False) -> ResourceInstance | None: wait (bool) : True to wait for resource status. Returns: - bool: True if create succeeded, False otherwise. + ResourceInstance | None: Created resource instance or None if create failed. """ self.to_dict() @@ -994,10 +999,13 @@ def create(self, wait: bool = False) -> ResourceInstance | None: self.logger.info(f"Create {self.kind} {self.name}") self.logger.info(f"Posting {hashed_res}") self.logger.debug(f"\n{yaml.dump(hashed_res)}") + resource_kwargs: dict[str, Any] = {"body": self.res, "namespace": self.namespace} resource_kwargs = {"body": self.res, "namespace": self.namespace} if self.dry_run: resource_kwargs["dry_run"] = "All" - resource_ = self.api.create(**resource_kwargs) + resource_ = Resource.retry_cluster_exceptions( + func=self.api.create, exceptions_dict=exceptions_dict, **resource_kwargs + ) with contextlib.suppress(ForbiddenError, AttributeError, NotFoundError): # some resources do not support get() (no instance) or the client do not have permissions self.initial_resource_version = self.instance.metadata.resourceVersion