Skip to content
Merged
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
14 changes: 10 additions & 4 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,15 +1000,18 @@ 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
) -> ResourceInstance | None:
"""
Create resource.

Args:
wait (bool) : True to wait for resource status.
exceptions_dict (dict[type[Exception], list[str]]): Dictionary of exceptions to retry on.

Returns:
bool: True if create succeeded, False otherwise.
ResourceInstance | None: Created resource instance or None if create failed.
"""
self.to_dict()

Expand All @@ -1020,10 +1023,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 = {"body": self.res, "namespace": self.namespace}
resource_kwargs: dict[str, Any] = {"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
Expand Down