mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-28 10:24:45 +00:00
[backport/2.2] Don't wait on *List resources for info module (#331)
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- k8s_info - don't wait on empty List resources (https://github.com/ansible-collections/kubernetes.core/pull/253).
|
||||||
@@ -199,6 +199,38 @@
|
|||||||
that:
|
that:
|
||||||
- "{{ lookup('pipe', 'date +%s') }} - {{ start }} > 30"
|
- "{{ lookup('pipe', 'date +%s') }} - {{ start }} > 30"
|
||||||
|
|
||||||
|
- name: Create simple pod
|
||||||
|
k8s:
|
||||||
|
definition:
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: wait-pod-1
|
||||||
|
namespace: "{{ wait_namespace }}"
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: busybox
|
||||||
|
name: busybox
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- while true; do sleep 5; done
|
||||||
|
|
||||||
|
- name: Wait for multiple non-existent pods to be created
|
||||||
|
k8s_info:
|
||||||
|
kind: Pod
|
||||||
|
namespace: "{{ wait_namespace }}"
|
||||||
|
label_selectors:
|
||||||
|
- thislabel=doesnotexist
|
||||||
|
wait: yes
|
||||||
|
wait_timeout: 10
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Assert no pods were found
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not result.resources
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
k8s_pod_name: pod-info-1
|
k8s_pod_name: pod-info-1
|
||||||
|
|
||||||
|
|||||||
@@ -279,18 +279,28 @@ class K8sAnsibleMixin(object):
|
|||||||
def _elapsed():
|
def _elapsed():
|
||||||
return (datetime.now() - start).seconds
|
return (datetime.now() - start).seconds
|
||||||
|
|
||||||
if result is None:
|
def result_empty(result):
|
||||||
while _elapsed() < wait_timeout:
|
return (
|
||||||
try:
|
result is None
|
||||||
result = resource.get(name=name, namespace=namespace,
|
or result.kind.endswith("List")
|
||||||
label_selector=','.join(label_selectors),
|
and not result.get("items")
|
||||||
field_selector=','.join(field_selectors))
|
)
|
||||||
break
|
|
||||||
except NotFoundError:
|
while result_empty(result) and _elapsed() < wait_timeout:
|
||||||
pass
|
try:
|
||||||
time.sleep(wait_sleep)
|
result = resource.get(
|
||||||
if result is None:
|
name=name,
|
||||||
return dict(resources=[], api_found=True)
|
namespace=namespace,
|
||||||
|
label_selector=",".join(label_selectors),
|
||||||
|
field_selector=",".join(field_selectors),
|
||||||
|
)
|
||||||
|
except NotFoundError:
|
||||||
|
pass
|
||||||
|
if not result_empty(result):
|
||||||
|
break
|
||||||
|
time.sleep(wait_sleep)
|
||||||
|
if result_empty(result):
|
||||||
|
return dict(resources=[], api_found=True)
|
||||||
|
|
||||||
if isinstance(result, ResourceInstance):
|
if isinstance(result, ResourceInstance):
|
||||||
satisfied_by = []
|
satisfied_by = []
|
||||||
|
|||||||
@@ -191,6 +191,10 @@ def main():
|
|||||||
|
|
||||||
k8s_ansible_mixin = K8sAnsibleMixin(module)
|
k8s_ansible_mixin = K8sAnsibleMixin(module)
|
||||||
k8s_ansible_mixin.client = get_api_client(module=module)
|
k8s_ansible_mixin.client = get_api_client(module=module)
|
||||||
|
k8s_ansible_mixin.fail_json = module.fail_json
|
||||||
|
k8s_ansible_mixin.fail = module.fail_json
|
||||||
|
k8s_ansible_mixin.exit_json = module.exit_json
|
||||||
|
k8s_ansible_mixin.warn = module.warn
|
||||||
execute_module(module, k8s_ansible_mixin)
|
execute_module(module, k8s_ansible_mixin)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user