Skip to content

Commit

Permalink
Merge pull request ansible-collections#481 from ansible-collections/2…
Browse files Browse the repository at this point in the history
….x-refactor

Refactor common.py
  • Loading branch information
gravesm committed Jun 23, 2022
2 parents 193a0cb + 14fe6f1 commit 9f51fc0
Show file tree
Hide file tree
Showing 46 changed files with 3,824 additions and 1,640 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/481-refactor-common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
major_changes:
- refactor K8sAnsibleMixin into module_utils/k8s/ (https://github.com/ansible-collections/kubernetes.core/pull/481).
9 changes: 9 additions & 0 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@


def configuration_digest(configuration, **kwargs):
"""This function has been deprecated and will be removed in version 4.0.0."""
m = hashlib.sha256()
for k in AUTH_ARG_MAP:
if not hasattr(configuration, k):
Expand All @@ -150,6 +151,8 @@ def configuration_digest(configuration, **kwargs):


class unique_string(str):
"""This function has been deprecated and will be removed in version 4.0.0."""

_low = None

def __hash__(self):
Expand All @@ -169,6 +172,7 @@ def lower(self):


def get_api_client(module=None, **kwargs):
"""This function has been deprecated and will be removed in version 4.0.0. Please use module_utils.k8s.client.get_api_client() instead."""
auth = {}

def _raise_or_fail(exc, msg):
Expand Down Expand Up @@ -340,6 +344,11 @@ def _load_config():

class K8sAnsibleMixin(object):
def __init__(self, module, pyyaml_required=True, *args, **kwargs):
module.deprecate(
msg="The K8sAnsibleMixin class has been deprecated and refactored into the module_utils/k8s/ directory.",
version="4.0.0",
collection_name="kubernetes.core",
)
if not HAS_K8S_MODULE_HELPER:
module.fail_json(
msg=missing_required_lib("kubernetes"),
Expand Down
14 changes: 11 additions & 3 deletions plugins/module_utils/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import tarfile

# from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions import (
CoreException,
)
from ansible.module_utils._text import to_native

try:
Expand Down Expand Up @@ -376,12 +379,17 @@ def run(self):
)


def check_pod(k8s_ansible_mixin, module):
resource = k8s_ansible_mixin.find_resource("Pod", None, True)
def check_pod(svc):
module = svc.module
namespace = module.params.get("namespace")
name = module.params.get("pod")
container = module.params.get("container")

try:
resource = svc.find_resource("Pod", None, True)
except CoreException as e:
module.fail_json(msg=to_native(e))

def _fail(exc):
arg = {}
if hasattr(exc, "body"):
Expand All @@ -398,7 +406,7 @@ def _fail(exc):
module.fail_json(msg=msg, **arg)

try:
result = resource.get(name=name, namespace=namespace)
result = svc.client.get(resource, name=name, namespace=namespace)
containers = [
c["name"] for c in result.to_dict()["status"]["containerStatuses"]
]
Expand Down

0 comments on commit 9f51fc0

Please sign in to comment.