From 419c6040651b30c4313c0d82009b8613c00cdbf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Tue, 27 Jul 2021 13:39:12 +0200 Subject: [PATCH] allow turbo mode, but disabled by default Depends-On: https://github.com/ansible-collections/cloud.common/pull/73 Expose a new parameter called enable_session_cache to enable the feature. --- .../fragments/add_enable_session_cache.yaml | 3 +++ galaxy.yml | 2 ++ plugins/doc_fragments/k8s_turbo_options.py | 21 +++++++++++++++++++ plugins/module_utils/ansiblemodule.py | 8 ++++++- plugins/module_utils/args_common.py | 7 +++++++ plugins/modules/k8s.py | 1 + 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/add_enable_session_cache.yaml create mode 100644 plugins/doc_fragments/k8s_turbo_options.py diff --git a/changelogs/fragments/add_enable_session_cache.yaml b/changelogs/fragments/add_enable_session_cache.yaml new file mode 100644 index 0000000000..7a931ac8bd --- /dev/null +++ b/changelogs/fragments/add_enable_session_cache.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: +- add ``enable_session_cache`` parameter to turn on the session cache. The option is disabled by default. diff --git a/galaxy.yml b/galaxy.yml index e2d8c6da5a..31ce88e301 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,6 +8,8 @@ authors: - willthames (https://github.com/willthames) - mmazur (https://github.com/mmazur) - jamescassell (https://github.com/jamescassell) +dependencies: + cloud.common: '>=2.0.1' description: Kubernetes Collection for Ansible. documentation: '' homepage: '' diff --git a/plugins/doc_fragments/k8s_turbo_options.py b/plugins/doc_fragments/k8s_turbo_options.py new file mode 100644 index 0000000000..d48594aa13 --- /dev/null +++ b/plugins/doc_fragments/k8s_turbo_options.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +# Copyright: (c) 2018, Red Hat | Ansible +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# Options for selecting or identifying a specific K8s object + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +class ModuleDocFragment(object): + + DOCUMENTATION = r''' +options: + enable_session_cache: + description: + - Enable the caching of the HTTP sessions. + type: bool + default: false +''' diff --git a/plugins/module_utils/ansiblemodule.py b/plugins/module_utils/ansiblemodule.py index a647b163f8..97fc7604d3 100644 --- a/plugins/module_utils/ansiblemodule.py +++ b/plugins/module_utils/ansiblemodule.py @@ -3,4 +3,10 @@ __metaclass__ = type -from ansible.module_utils.basic import AnsibleModule # noqa: F401 +try: + from ansible_collections.cloud.common.plugins.module_utils.turbo.module import ( + AnsibleTurboModule as AnsibleModule, + ) # noqa: F401 + AnsibleModule.collection_name = "kubernetes.core" +except ImportError: + from ansible.module_utils.basic import AnsibleModule # noqa: F401 diff --git a/plugins/module_utils/args_common.py b/plugins/module_utils/args_common.py index 67c183db74..b70a51adbd 100644 --- a/plugins/module_utils/args_common.py +++ b/plugins/module_utils/args_common.py @@ -142,3 +142,10 @@ def list_dict_str(value): } } } + +TURBO_ARG_SPEC = { + 'enable_session_cache': { + 'type': 'bool', + 'default': False, + }, +} diff --git a/plugins/modules/k8s.py b/plugins/modules/k8s.py index 5bcb51cff2..f14d055419 100644 --- a/plugins/modules/k8s.py +++ b/plugins/modules/k8s.py @@ -326,6 +326,7 @@ def argspec(): argument_spec.update(copy.deepcopy(RESOURCE_ARG_SPEC)) argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC)) argument_spec.update(copy.deepcopy(WAIT_ARG_SPEC)) + argument_spec.update(copy.deepcopy(TURBO_ARG_SPEC)) argument_spec['merge_type'] = dict(type='list', elements='str', choices=['json', 'merge', 'strategic-merge']) argument_spec['validate'] = dict(type='dict', default=None, options=validate_spec()) argument_spec['append_hash'] = dict(type='bool', default=False)