Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/1033-warnings-deprecations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Replace passing ``warnings`` to ``exit_json`` with ``AnsibleModule.warn`` in the ``k8s_drain``, ``k8s_rollback.py`` and ``k8s_scale.py`` modules as it deprecated in ``ansible-core>=2.19.0`` and will be removed in ``ansible-core>=2.23.0`` (https://github.com/ansible-collections/kubernetes.core/pull/1033).
10 changes: 7 additions & 3 deletions plugins/module_utils/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,15 @@ def copy(self):
def run(self):
self.files_to_copy = self.list_remote_files()
if self.files_to_copy == []:
# Using warn method instead of passing warnings to exit_json as it is
# deprecated in ansible-core>=2.19.0
self._module.warn(
"No file found from directory '{0}' into remote Pod.".format(
self.remote_path
)
)
self.module.exit_json(
changed=False,
warning="No file found from directory '{0}' into remote Pod.".format(
self.remote_path
),
)
self.copy()

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/k8s_drain.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def _revert_node_patch():
warnings.append(warn)
result.append("{0} Pod(s) deleted from node.".format(number_pod))
if warnings:
return dict(result=" ".join(result), warnings=warnings)
self._module.warn(warnings)
return dict(result=" ".join(result))

def patch_node(self, unschedulable):
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def perform_action(svc, resource):
module.params["kind"],
resource["metadata"]["name"],
)
result = {"changed": False, "warnings": [warn]}
if warn:
module.warn(warn)
result = {"changed": False}
return result

if module.params["kind"] == "Deployment":
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/k8s_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,12 @@ def _continue_or_fail(error):
module.fail_json(msg=error, **return_attributes)

def _continue_or_exit(warn):
if warn:
module.warn(warn)
if multiple_scale:
return_attributes["results"].append({"warning": warn, "changed": False})
return_attributes["results"].append({"changed": False})
else:
module.exit_json(warning=warn, **return_attributes)
module.exit_json(**return_attributes)

for existing in existing_items:
if kind.lower() == "job":
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/targets/k8s_rollback/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,16 @@
namespace: "{{ namespace }}"
register: result

- name: Debug result
debug:
var: result

- name: Assert warning is returned for no rollout history
assert:
that:
- not result.changed
- result.rollback_info[0].warnings is defined
- "'No rollout history found' in result.rollback_info[0].warnings[0]"
- "'No rollout history found' in result.warnings.warnings[0]"

- name: Create a service for unsupported resource test
k8s:
Expand Down
Loading