fix multiple issues with dry_run logic (#561)

fix multiple issues with dry_run logic

SUMMARY

Fix multiple issues with dry_run logic

The parameter value passed to the client set to dry_run=All instead of dry_run=True.
Add conditional check for Kubernetes release for the dry_run to be set
Add integration test that checks to ensure server side dry run is being used during check mode.


ISSUE TYPE


Bugfix Pull Request

Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Jill R <None>
This commit is contained in:
Bikouo Aubin
2023-01-11 08:57:39 +01:00
committed by GitHub
parent 0b4fda7585
commit 26cd550bc0
9 changed files with 89 additions and 22 deletions

View File

@@ -0,0 +1,3 @@
time=30
k8s
k8s_info

View File

@@ -0,0 +1,10 @@
---
test_namespace: "check-mode-ns"
test_config:
- k8s_release: "kubernetes < 18.20.0"
dry_run: false
virtualenv: 'env1'
- k8s_release: "kubernetes >= 18.20.0"
dry_run: true
virtualenv: 'env2'

View File

@@ -0,0 +1,3 @@
---
dependencies:
- remove_namespace

View File

@@ -0,0 +1,32 @@
- name: Create virtualenv with kubernetes release
pip:
name:
- '{{ item.k8s_release }}'
virtualenv_command: "virtualenv --python {{ ansible_python_interpreter }}"
virtualenv: "{{ tmpdir }}/{{ item.virtualenv }}"
- name: Create resource using check mode
k8s:
kind: Namespace
name: '{{ test_namespace }}'
check_mode: true
register: _create
- name: Ensure namespace was not created
k8s_info:
kind: Namespace
name: '{{ test_namespace }}'
register: info
failed_when: info.resources | length > 0
- name: Ensure server side dry_run has being used
assert:
that:
- '"creationTimestamp" in _create.result.metadata'
when: item.dry_run
- name: Ensure server side dry_run was not used
assert:
that:
- '"creationTimestamp" in _create.result.metadata'
when: not item.dry_run

View File

@@ -0,0 +1,19 @@
- name: create temporary directory for tests
tempfile:
suffix: .k8s
state: directory
register: _path
- block:
- include_tasks: tasks/check_mode.yml
with_items: '{{ test_config }}'
vars:
tmpdir: '{{ _path.path }}'
always:
- name: Delete temporaray directory
file:
state: absent
path: '{{ tmpdir }}'
ignore_errors: true