From fb39299578a412cd1f40e1f6e3dd2fb434691124 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Mon, 26 Nov 2018 14:04:22 -0500 Subject: [PATCH] Fix error where pod has error and no containers (cherry picked from commit 865430e3e0efa946e2a2a1b4c6eb35d8a74d460d) --- ...enshift-inventory-plugin-empty-pods-and-serialization.yaml | 4 ++++ lib/ansible/module_utils/k8s/inventory.py | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 changelogs/fragments/49299-openshift-inventory-plugin-empty-pods-and-serialization.yaml diff --git a/changelogs/fragments/49299-openshift-inventory-plugin-empty-pods-and-serialization.yaml b/changelogs/fragments/49299-openshift-inventory-plugin-empty-pods-and-serialization.yaml new file mode 100644 index 00000000000..68a2b49cc6a --- /dev/null +++ b/changelogs/fragments/49299-openshift-inventory-plugin-empty-pods-and-serialization.yaml @@ -0,0 +1,4 @@ +--- +bugfixes: +- Convert hostvars data in OpenShift inventory plugin to be serializable by ansible-inventory +- Fix error in OpenShift inventory plugin when a pod has errored and is empty diff --git a/lib/ansible/module_utils/k8s/inventory.py b/lib/ansible/module_utils/k8s/inventory.py index 5a33349db36..4e68722e2f1 100644 --- a/lib/ansible/module_utils/k8s/inventory.py +++ b/lib/ansible/module_utils/k8s/inventory.py @@ -127,6 +127,9 @@ class K8sInventoryHelper(K8sAnsibleMixin): else: pod_labels = {} + if not pod.status.containerStatuses: + continue + for container in pod.status.containerStatuses: # add each pod_container to the namespace group, and to each label_value group container_name = '{0}_{1}'.format(pod.metadata.name, container.name)