Skip to content

Commit ea030ed

Browse files
committed
When a resource is created, by default if cluster expected exceptions are raised, there will be a retry.
To overwrite and not wait - exceptions_dict={} should be passed
1 parent e65017a commit ea030ed

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ocp_resources/resource.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -978,26 +978,34 @@ def wait_for_status(
978978
self.logger.error(f"Status of {self.kind} {self.name} is {current_status}")
979979
raise
980980

981-
def create(self, wait: bool = False) -> ResourceInstance | None:
981+
def create(
982+
self,
983+
wait: bool = False,
984+
exceptions_dict: dict[type[Exception], list[str]] = DEFAULT_CLUSTER_RETRY_EXCEPTIONS
985+
| PROTOCOL_ERROR_EXCEPTION_DICT,
986+
) -> ResourceInstance | None:
982987
"""
983-
Create resource.
988+
Create resource.
984989
985990
Args:
986991
wait (bool) : True to wait for resource status.
987992
988993
Returns:
989-
bool: True if create succeeded, False otherwise.
994+
ResourceInstance | None: Created resource instance or None if create failed.
990995
"""
991996
self.to_dict()
992997

993998
hashed_res = self.hash_resource_dict(resource_dict=self.res)
994999
self.logger.info(f"Create {self.kind} {self.name}")
9951000
self.logger.info(f"Posting {hashed_res}")
9961001
self.logger.debug(f"\n{yaml.dump(hashed_res)}")
1002+
resource_kwargs: dict[str, Any] = {"body": self.res, "namespace": self.namespace}
9971003
resource_kwargs = {"body": self.res, "namespace": self.namespace}
9981004
if self.dry_run:
9991005
resource_kwargs["dry_run"] = "All"
1000-
resource_ = self.api.create(**resource_kwargs)
1006+
resource_ = Resource.retry_cluster_exceptions(
1007+
func=self.api.create, exceptions_dict=exceptions_dict, **resource_kwargs
1008+
)
10011009
with contextlib.suppress(ForbiddenError, AttributeError, NotFoundError):
10021010
# some resources do not support get() (no instance) or the client do not have permissions
10031011
self.initial_resource_version = self.instance.metadata.resourceVersion

0 commit comments

Comments
 (0)