Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Sep 24, 2020
1 parent 289e601 commit 6ca507e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
4 changes: 2 additions & 2 deletions molecule/default/tasks/info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
assert:
that:
- wait_info is successful
- wait_info.changed is false
- not wait_info.changed

- name: Remove Pod
k8s:
Expand Down Expand Up @@ -120,7 +120,7 @@
assert:
that:
- wait_info is successful
- wait_info.changed is false
- not wait_info.changed

- name: "Remove Pod {{ multi_pod_one }}"
k8s:
Expand Down
70 changes: 42 additions & 28 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@
except ImportError:
from ansible.module_utils.common.dict_transformations import recursive_diff

try:
try:
# >=0.10
from openshift.dynamic.resource import ResourceInstance
except ImportError:
# <0.10
from openshift.dynamic.client import ResourceInstance
HAS_K8S_INSTANCE_HELPER = True
k8s_import_exception = None
except ImportError as e:
HAS_K8S_INSTANCE_HELPER = False
k8s_import_exception = e
K8S_IMP_ERR = traceback.format_exc()


def list_dict_str(value):
if isinstance(value, (list, dict, string_types)):
Expand Down Expand Up @@ -280,24 +294,26 @@ def kubernetes_facts(self, kind, api_version, name=None, namespace=None, label_s
namespace=namespace,
label_selector=','.join(label_selectors),
field_selector=','.join(field_selectors))
satisfied_by = []
if wait and result['kind'].endswith('List') and hasattr(result, 'items'):
# We have a list of ResourceInstance
for resource_instance in result.get('items'):
success, res, duration = self.wait(resource, resource_instance, sleep=wait_sleep, timeout=wait_timeout)
if not success:
self.fail(msg="Failed to gather information about %s(s)" % result.get('kind')[:-4])
satisfied_by.append(res)
return dict(resources=satisfied_by)
else:
result = result.to_dict()
if wait:
satisfied_by = []
if isinstance(result, ResourceInstance):
# We have a list of ResourceInstance
for resource_instance in result.get('items', []):
success, res, duration = self.wait(resource, resource_instance,
sleep=wait_sleep, timeout=wait_timeout,
state=state, condition=condition)
if not success:
self.fail(msg="Failed to gather information about %s(s) even"
" after waiting for %s seconds" % (res.get('kind'), duration))
satisfied_by.append(res)
return dict(resources=satisfied_by)
result = result.to_dict()
except (openshift.dynamic.exceptions.BadRequestError, openshift.dynamic.exceptions.NotFoundError):
return dict(resources=[])

if 'items' in result:
return dict(resources=result['items'])
else:
return dict(resources=[result])
return dict(resources=[result])

def remove_aliases(self):
"""
Expand Down Expand Up @@ -363,8 +379,7 @@ def _wait_for_elapsed():
if predicate(response):
if response:
return True, response.to_dict(), _wait_for_elapsed()
else:
return True, {}, _wait_for_elapsed()
return True, {}, _wait_for_elapsed()
time.sleep(sleep)
except NotFoundError:
if state == 'absent':
Expand Down Expand Up @@ -473,21 +488,20 @@ def set_resource_definitions(self):

def check_library_version(self):
validate = self.params.get('validate')
if validate:
if LooseVersion(self.openshift_version) < LooseVersion("0.8.0"):
self.fail_json(msg="openshift >= 0.8.0 is required for validate")
if validate and LooseVersion(self.openshift_version) < LooseVersion("0.8.0"):
self.fail_json(msg="openshift >= 0.8.0 is required for validate")
self.append_hash = self.params.get('append_hash')
if self.append_hash:
if not HAS_K8S_CONFIG_HASH:
self.fail_json(msg=missing_required_lib("openshift >= 0.7.2", reason="for append_hash"),
exception=K8S_CONFIG_HASH_IMP_ERR)
if self.params['merge_type']:
if LooseVersion(self.openshift_version) < LooseVersion("0.6.2"):
self.fail_json(msg=missing_required_lib("openshift >= 0.6.2", reason="for merge_type"))
if self.append_hash and not HAS_K8S_CONFIG_HASH:
self.fail_json(msg=missing_required_lib("openshift >= 0.7.2", reason="for append_hash"),
exception=K8S_CONFIG_HASH_IMP_ERR)
if self.params['merge_type'] and LooseVersion(self.openshift_version) < LooseVersion("0.6.2"):
self.fail_json(msg=missing_required_lib("openshift >= 0.6.2", reason="for merge_type"))
self.apply = self.params.get('apply', False)
if self.apply:
if not HAS_K8S_APPLY:
self.fail_json(msg=missing_required_lib("openshift >= 0.9.2", reason="for apply"))
if self.apply and not HAS_K8S_APPLY:
self.fail_json(msg=missing_required_lib("openshift >= 0.9.2", reason="for apply"))
wait = self.params.get('wait', False)
if wait and not HAS_K8S_INSTANCE_HELPER:
self.fail_json(msg=missing_required_lib("openshift >= 0.4.0", reason="for wait"))

def flatten_list_kind(self, list_resource, definitions):
flattened = []
Expand Down

0 comments on commit 6ca507e

Please sign in to comment.