Port changes from main to refactored branch (#472)

Port changes from main to refactored branch

Depends-on: ansible/ansible-zuul-jobs#1563
SUMMARY

This PR contains several commits that complete the rebase of the 2.x-refactor branch onto main. Most of the changes here had to be manually backported after rebasing as the original changes were to code that will be deprecated. In addition, rather than trying to manually sort out conflicts and changes to the sanity ignores, I rewrote the refresh_ignore_files script to fully automate the management of ignore files. Previously, these files were both manually edited and auto-generated. This should no longer be the case, and these files should never be manually edited going forward.
For the purposes of reviewing and history, I kept all changes in separate commits tied to the original commit being backported.

ISSUE TYPE

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Jill R <None>
This commit is contained in:
Mike Graves
2022-06-09 11:20:48 -04:00
committed by GitHub
parent 25644ac192
commit 92785f58da
18 changed files with 827 additions and 1394 deletions

View File

@@ -16,7 +16,6 @@ from ansible_collections.kubernetes.core.plugins.module_utils.k8s.service import
diff_objects,
)
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions import (
CoreException,
ResourceTimeout,
)
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.waiter import exists
@@ -60,11 +59,15 @@ def run_module(module) -> None:
try:
result = perform_action(svc, definition, module.params)
except CoreException as e:
except Exception as e:
try:
error = e.result
except AttributeError:
error = {}
try:
error["reason"] = e.__cause__.reason
except AttributeError:
pass
error["msg"] = to_native(e)
if warnings:
error.setdefault("warnings", []).extend(warnings)
@@ -102,7 +105,13 @@ def perform_action(svc, definition: Dict, params: Dict) -> Dict:
existing = svc.retrieve(resource, definition)
if state == "absent":
instance = svc.delete(resource, definition, existing)
if exists(existing) and existing.kind.endswith("List"):
instance = []
for item in existing.items:
r = svc.delete(resource, item, existing)
instance.append(r)
else:
instance = svc.delete(resource, definition, existing)
result["method"] = "delete"
if exists(existing):
result["changed"] = True
@@ -114,7 +123,9 @@ def perform_action(svc, definition: Dict, params: Dict) -> Dict:
result["msg"] = (
"resource 'kind={kind},name={name},namespace={namespace}' "
"filtered by label_selectors.".format(
kind=kind, name=origin_name, namespace=namespace,
kind=kind,
name=origin_name,
namespace=namespace,
)
)
return result