Skip to content

Commit

Permalink
k8s: turn off wait in check_mode (ansible#51310)
Browse files Browse the repository at this point in the history
  • Loading branch information
willthames authored and resmo committed Jan 25, 2019
1 parent 9cb7cbb commit 195de8b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/ansible/module_utils/k8s/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,19 @@ def perform_action(self, resource, definition):
return result
else:
# Delete the object
result['changed'] = True
if not self.check_mode:
try:
k8s_obj = resource.delete(**params)
result['result'] = k8s_obj.to_dict()
except DynamicApiError as exc:
self.fail_json(msg="Failed to delete object: {0}".format(exc.body),
error=exc.status, status=exc.status, reason=exc.reason)
result['changed'] = True
if wait:
success, resource, duration = self.wait(resource, definition, wait_timeout, 'absent')
result['duration'] = duration
if not success:
self.fail_json(msg="Resource deletion timed out", **result)
if wait:
success, resource, duration = self.wait(resource, definition, wait_timeout, 'absent')
result['duration'] = duration
if not success:
self.fail_json(msg="Resource deletion timed out", **result)
return result
else:
if not existing:
Expand All @@ -259,7 +259,7 @@ def perform_action(self, resource, definition):
self.fail_json(msg=msg, error=exc.status, status=exc.status, reason=exc.reason)
success = True
result['result'] = k8s_obj
if wait:
if wait and not self.check_mode:
success, result['result'], result['duration'] = self.wait(resource, definition, wait_timeout)
result['changed'] = True
result['method'] = 'create'
Expand Down
27 changes: 27 additions & 0 deletions test/integration/targets/k8s/playbooks/roles/k8s/tasks/waiter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@
that:
- ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled

- name: update a daemonset in check_mode
k8s:
definition:
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: wait-daemonset
namespace: "{{ wait_namespace }}"
spec:
selector:
matchLabels:
app: "{{ wait_pod_name }}"
updateStrategy:
type: RollingUpdate
template: "{{ wait_pod_template }}"
wait: yes
wait_timeout: 180
vars:
wait_pod_name: wait-ds
wait_pod_image: gcr.io/kuar-demo/kuard-amd64:2
register: update_ds_check_mode

- name: check that check_mode returned changed
assert:
that:
- update_ds_check_mode is changed

- name: update a daemonset
k8s:
definition:
Expand Down

0 comments on commit 195de8b

Please sign in to comment.