Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that k8s_facts always returns resources key #46733

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/k8s/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def kubernetes_facts(self, kind, api_version, name=None, namespace=None, label_s
label_selector=','.join(label_selectors),
field_selector=','.join(field_selectors)).to_dict()
except openshift.dynamic.exceptions.NotFoundError:
return dict(items=[])
return dict(resources=[])

if 'items' in result:
return dict(resources=result['items'])
Expand Down
15 changes: 14 additions & 1 deletion test/integration/targets/k8s/playbooks/roles/k8s/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
debug:
var: output

- name: k8s_facts works with empty resources
k8s_facts:
kind: Deployment
namespace: testing
api_version: extensions/v1beta1
register: k8s_facts

- name: assert that k8s_facts is in correct format
assert:
that:
- "'resources' in k8s_facts"
- not k8s_facts.resources

- name: Create a service
k8s:
state: present
Expand Down Expand Up @@ -85,7 +98,7 @@
k8s:
state: present
inline: &deployment
apiVersion: apps/v1beta1
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: elastic
Expand Down