From ce037ce3ba1ec0e8e54d1336aa69597a661cd733 Mon Sep 17 00:00:00 2001 From: abikouo Date: Tue, 18 May 2021 09:35:49 +0200 Subject: [PATCH] not tested --- plugins/doc_fragments/k8s_wait_options.py | 4 +--- plugins/module_utils/common.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/doc_fragments/k8s_wait_options.py b/plugins/doc_fragments/k8s_wait_options.py index d556f36d..263986ec 100644 --- a/plugins/doc_fragments/k8s_wait_options.py +++ b/plugins/doc_fragments/k8s_wait_options.py @@ -67,7 +67,5 @@ options: wait_for: description: - Specifies a property on the resource to wait for. - - Ignored if C(wait) is not set or is set to False. - default: 120 - type: int + - Ignored if C(wait) is not set or is set to I(False). ''' diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index bea2a39b..b64f475d 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -373,7 +373,7 @@ class K8sAnsibleMixin(object): def _wait_for_elapsed(): return (datetime.now() - start).seconds - + response = None while _wait_for_elapsed() < timeout: try: @@ -438,7 +438,7 @@ class K8sAnsibleMixin(object): return False def _wait_for_property(resource): - return all([ jsonpath.match("$.{}".format(item),json_data) for item in wait_for ]) + return all([ jsonpath.match("$.{}".format(item),resource) for item in wait_for ]) def _resource_absent(resource): return not resource @@ -457,13 +457,15 @@ class K8sAnsibleMixin(object): kind = definition['kind'] predicates = [] if state == 'present': - if condition: - predicates.append(_custom_condition) - if wait_for: - # json path predicate - predicates.append(_wait_for_property) if condition is None and wait_for is None: predicates.append(waiter.get(kind, lambda x: x)) + else: + if condition: + # add waiter on custom condition + predicates.append(_custom_condition) + if wait_for: + # json path predicate + predicates.append(_wait_for_property) else: predicates.append(_resource_absent) return self._wait_for(resource, definition['metadata']['name'], definition['metadata'].get('namespace'), predicates, sleep, timeout, state)