Skip to content

Commit

Permalink
Catch url fetch error
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
jkupferer committed Jan 4, 2020
1 parent cd56943 commit f2363d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
del tmp # tmp no longer has any effect

k8s_api = self._task.args.get('api', {})
k8s_module_args = dict((k, v) for k, v in self._task.args.items() if k != 'api')
k8s_module_args.update(self._task.args.get('api', {}))
k8s_module_args.update(k8s_api)

result.update(
self._execute_module(
Expand Down
5 changes: 4 additions & 1 deletion lookup_plugins/k8s_resource_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@

class LookupModule(LookupBase):
def from_definition(self, definition):
if definition['kind'] == 'List' and definition['apiVersion'] == 'v1':
if 'kind' not in definition:
raise AnsibleError('Resource definition has no kind {0}'.format(definition))
elif definition['kind'] == 'List' and definition['apiVersion'] == 'v1':
return definition.get('items', [])
else:
return [definition]
Expand Down Expand Up @@ -88,6 +90,7 @@ def from_template(self, template, searchpath, variables):
def from_url(self, url):
try:
resp = requests.get(url)
resp.raise_for_status()
except Exception as err:
raise AnsibleError('Failed to fetch {}: {}'.format(url, err))
ret = []
Expand Down
2 changes: 1 addition & 1 deletion tasks/k8s-namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: "{{ _k8s_cluster_name }} {{ _k8s_namespace_name }} namespace"
k8s_namespace:
_k8s_namespace:
name: "{{ _k8s_namespace_name }}"
api: "{{ _k8s_cluster_api }}"

Expand Down
2 changes: 1 addition & 1 deletion tests/00-cluster-admin/group_vars/k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ k8s_namespaces:
resources:
- openshift_template:
url: https://raw.githubusercontent.com/sclorg/cakephp-ex/master/openshift/templates/cakephp.json
- url: https://raw.githubusercontent.com/redhat-cop/k8s_config/master/tests/files/configmap.yaml
- url: https://raw.githubusercontent.com/redhat-cop/k8s_config/master/tests/00-cluster-admin/files/configmap.yaml

0 comments on commit f2363d5

Please sign in to comment.