mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-26 21:33:02 +00:00
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:
committed by
Mike Graves
parent
b62ea00ebf
commit
58a0fb1605
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user