Refactor k8s_exec to use new module_utils code (#328)

* Refactor k8s_exec to use new module_utils code

Signed-off-by: Alina Buzachis <abuzachis@redhat.com>

* Fix client

Signed-off-by: Alina Buzachis <abuzachis@redhat.com>
This commit is contained in:
Alina Buzachis
2022-02-04 15:49:43 +01:00
committed by Mike Graves
parent b62ea00ebf
commit 58a0fb1605

View File

@@ -138,6 +138,12 @@ from ansible.module_utils._text import to_native
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
AUTH_ARG_SPEC,
)
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.core import (
AnsibleK8SModule,
)
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
get_api_client,
)
try:
from kubernetes.client.apis import core_v1_api
@@ -157,10 +163,9 @@ def argspec():
return spec
def execute_module(module, k8s_ansible_mixin):
def execute_module(module, client):
# Load kubernetes.client.Configuration
api = core_v1_api.CoreV1Api(k8s_ansible_mixin.client.client)
api = core_v1_api.CoreV1Api(client.client)
# hack because passing the container as None breaks things
optional_kwargs = {}
@@ -228,18 +233,15 @@ def execute_module(module, k8s_ansible_mixin):
def main():
module = AnsibleModule(
module = AnsibleK8SModule(
module_class=AnsibleModule,
check_pyyaml=False,
argument_spec=argspec(),
supports_check_mode=True,
)
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
K8sAnsibleMixin,
get_api_client,
)
k8s_ansible_mixin = K8sAnsibleMixin(module)
k8s_ansible_mixin.client = get_api_client(module=module)
execute_module(module, k8s_ansible_mixin)
client = get_api_client(module)
execute_module(module, client.client)
if __name__ == "__main__":