diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index ca8b47bca6..58048ea5fd 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -15,6 +15,7 @@ ConflictError, MethodNotAllowedError, NotFoundError, + ForbiddenError, ) from kubernetes.dynamic.resource import ResourceField from packaging.version import Version @@ -26,6 +27,7 @@ PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_1MINUTE, TIMEOUT_4MINUTES, + TIMEOUT_10SEC, ) from ocp_resources.event import Event from timeout_sampler import ( @@ -612,7 +614,7 @@ def exists(self): """ try: return self.instance - except TimeoutExpiredError: + except NotFoundError: return None def client_wait_deleted(self, timeout): @@ -699,7 +701,7 @@ def create(self, wait=False): self.logger.info(f"Posting {hashed_res}") self.logger.debug(f"\n{yaml.dump(hashed_res)}") resource_ = self.api.create(body=self.res, namespace=self.namespace, dry_run=self.dry_run) - with contextlib.suppress(TimeoutExpiredError): + with contextlib.suppress(ForbiddenError, AttributeError): # some resources do not support get() (no instance) or the client do not have permissions self.initial_resource_version = self.instance.metadata.resourceVersion @@ -765,16 +767,23 @@ def update_replace(self, resource_dict): @staticmethod def retry_cluster_exceptions(func, exceptions_dict=DEFAULT_CLUSTER_RETRY_EXCEPTIONS, **kwargs): - sampler = TimeoutSampler( - wait_timeout=10, - sleep=1, - func=func, - print_log=False, - exceptions_dict=exceptions_dict, - **kwargs, - ) - for sample in sampler: - return sample + try: + sampler = TimeoutSampler( + wait_timeout=TIMEOUT_10SEC, + sleep=1, + func=func, + print_log=False, + exceptions_dict=exceptions_dict, + **kwargs, + ) + for sample in sampler: + return sample + + except TimeoutExpiredError as exp: + if exp.last_exp: + raise exp.last_exp + + raise @classmethod def get( diff --git a/poetry.lock b/poetry.lock index 08d816a9cd..2388b7a04d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -894,12 +894,12 @@ files = [ [[package]] name = "timeout-sampler" -version = "0.0.16" +version = "0.0.17" description = "Timeout utility class to wait for any function output and interact with it in given time" optional = false -python-versions = ">=3.8,<4.0" +python-versions = "<4.0,>=3.8" files = [ - {file = "timeout_sampler-0.0.16.tar.gz", hash = "sha256:0587e5aae74a46bf24dca4c43e17675cad9754110f8d69dc00103dbcb8066d95"}, + {file = "timeout_sampler-0.0.17.tar.gz", hash = "sha256:c4685f343ead7542df03293aa40efdf455bab8c45f89e51a21ac4a3f4c8855d9"}, ] [package.dependencies]