Skip to content

Commit

Permalink
allow turbo mode, but disabled by default
Browse files Browse the repository at this point in the history
Depends-On: ansible-collections/cloud.common#73

Expose a new parameter called enable_session_cache to enable the
feature.
  • Loading branch information
goneri committed Aug 19, 2021
1 parent 688cff4 commit 7d4e0ee
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 11 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/add_enable_session_cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- add ``enable_session_cache`` parameter to turn on the session cache. The option is disabled by default.
2 changes: 2 additions & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.5'
description: Kubernetes Collection for Ansible.
documentation: ''
homepage: ''
Expand Down
21 changes: 21 additions & 0 deletions plugins/doc_fragments/k8s_turbo_options.py
Original file line number Diff line number Diff line change
@@ -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
'''
8 changes: 7 additions & 1 deletion plugins/module_utils/ansiblemodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions plugins/module_utils/args_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,10 @@ def list_dict_str(value):
}
}
}

TURBO_ARG_SPEC = {
'enable_session_cache': {
'type': 'bool',
'default': False,
},
}
4 changes: 3 additions & 1 deletion plugins/modules/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_wait_options
- kubernetes.core.k8s_delete_options
- kubernetes.core.k8s_turbo_options
options:
state:
Expand Down Expand Up @@ -326,7 +327,7 @@

from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, WAIT_ARG_SPEC, NAME_ARG_SPEC, RESOURCE_ARG_SPEC, DELETE_OPTS_ARG_SPEC)
AUTH_ARG_SPEC, WAIT_ARG_SPEC, NAME_ARG_SPEC, RESOURCE_ARG_SPEC, DELETE_OPTS_ARG_SPEC, TURBO_ARG_SPEC)


def validate_spec():
Expand All @@ -342,6 +343,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)
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_cluster_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
extends_documentation_fragment:
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_turbo_options
requirements:
- "python >= 3.6"
Expand Down Expand Up @@ -155,7 +156,7 @@
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils.parsing.convert_bool import boolean
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC)
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC, TURBO_ARG_SPEC)


def execute_module(module, client):
Expand Down Expand Up @@ -196,6 +197,7 @@ def execute_module(module, client):

def argspec():
spec = copy.deepcopy(AUTH_ARG_SPEC)
spec.update(copy.deepcopy(TURBO_ARG_SPEC))
spec['invalidate_cache'] = dict(type='bool', default=True)
return spec

Expand Down
1 change: 1 addition & 0 deletions plugins/modules/k8s_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
extends_documentation_fragment:
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_turbo_options
requirements:
- "python >= 3.6"
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/k8s_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
extends_documentation_fragment:
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_turbo_options
requirements:
- "python >= 3.6"
Expand Down Expand Up @@ -120,8 +121,8 @@

from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
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.args_common import (
AUTH_ARG_SPEC, TURBO_ARG_SPEC
)

try:
Expand All @@ -134,6 +135,7 @@

def argspec():
spec = copy.deepcopy(AUTH_ARG_SPEC)
spec.update(TURBO_ARG_SPEC)
spec['namespace'] = dict(type='str', required=True)
spec['pod'] = dict(type='str', required=True)
spec['container'] = dict(type='str')
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_name_options
- kubernetes.core.k8s_wait_options
- kubernetes.core.k8s_turbo_options
requirements:
- "python >= 3.6"
Expand Down Expand Up @@ -149,7 +150,7 @@
import copy

from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC, WAIT_ARG_SPEC)
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC, WAIT_ARG_SPEC, TURBO_ARG_SPEC)


def execute_module(module, k8s_ansible_mixin):
Expand All @@ -170,6 +171,7 @@ def execute_module(module, k8s_ansible_mixin):

def argspec():
args = copy.deepcopy(AUTH_ARG_SPEC)
args.update(TURBO_ARG_SPEC)
args.update(WAIT_ARG_SPEC)
args.update(
dict(
Expand Down
6 changes: 5 additions & 1 deletion plugins/modules/k8s_json_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
extends_documentation_fragment:
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_wait_options
- kubernetes.core.k8s_turbo_options
requirements:
- "python >= 3.6"
Expand Down Expand Up @@ -130,7 +131,9 @@
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils._text import to_native
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC, WAIT_ARG_SPEC
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, WAIT_ARG_SPEC, TURBO_ARG_SPEC
)
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
get_api_client, K8sAnsibleMixin)

Expand Down Expand Up @@ -267,6 +270,7 @@ def build_error_msg(kind, name, msg):
def main():
args = copy.deepcopy(AUTH_ARG_SPEC)
args.update(copy.deepcopy(WAIT_ARG_SPEC))
args.update(copy.deepcopy(TURBO_ARG_SPEC))
args.update(JSON_PATCH_ARGS)
module = AnsibleModule(argument_spec=args, supports_check_mode=True)
k8s_module = K8sAnsibleMixin(module)
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
extends_documentation_fragment:
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_name_options
- kubernetes.core.k8s_turbo_options
options:
kind:
description:
Expand Down Expand Up @@ -121,11 +122,12 @@
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible.module_utils.six import PY2

from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC, NAME_ARG_SPEC)
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (AUTH_ARG_SPEC, NAME_ARG_SPEC, TURBO_ARG_SPEC)


def argspec():
args = copy.deepcopy(AUTH_ARG_SPEC)
args.update(TURBO_ARG_SPEC)
args.update(NAME_ARG_SPEC)
args.update(
dict(
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
extends_documentation_fragment:
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_name_options
- kubernetes.core.k8s_turbo_options
requirements:
- "python >= 3.6"
- "kubernetes >= 12.0.0"
Expand Down Expand Up @@ -80,7 +81,7 @@

from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, NAME_ARG_SPEC)
AUTH_ARG_SPEC, NAME_ARG_SPEC, TURBO_ARG_SPEC)


def get_managed_resource(module):
Expand Down Expand Up @@ -181,6 +182,7 @@ def perform_action(module, k8s_ansible_mixin, resource):

def argspec():
args = copy.deepcopy(AUTH_ARG_SPEC)
args.update(TURBO_ARG_SPEC)
args.update(NAME_ARG_SPEC)
args.update(
dict(
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_resource_options
- kubernetes.core.k8s_scale_options
- kubernetes.core.k8s_turbo_options
options:
label_selectors:
Expand Down Expand Up @@ -145,7 +146,7 @@

from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, RESOURCE_ARG_SPEC, NAME_ARG_SPEC)
AUTH_ARG_SPEC, RESOURCE_ARG_SPEC, NAME_ARG_SPEC, TURBO_ARG_SPEC)


SCALE_ARG_SPEC = {
Expand Down Expand Up @@ -274,6 +275,7 @@ def _continue_or_exit(warn):

def argspec():
args = copy.deepcopy(SCALE_ARG_SPEC)
args.update(TURBO_ARG_SPEC)
args.update(RESOURCE_ARG_SPEC)
args.update(NAME_ARG_SPEC)
args.update(AUTH_ARG_SPEC)
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- kubernetes.core.k8s_auth_options
- kubernetes.core.k8s_resource_options
- kubernetes.core.k8s_state_options
- kubernetes.core.k8s_turbo_options
options:
merge_type:
Expand Down Expand Up @@ -148,7 +149,7 @@

from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, COMMON_ARG_SPEC, RESOURCE_ARG_SPEC)
AUTH_ARG_SPEC, COMMON_ARG_SPEC, RESOURCE_ARG_SPEC, TURBO_ARG_SPEC)

SERVICE_ARG_SPEC = {
'apply': {
Expand Down Expand Up @@ -188,6 +189,7 @@ def argspec():
argument_spec.update(COMMON_ARG_SPEC)
argument_spec.update(RESOURCE_ARG_SPEC)
argument_spec.update(SERVICE_ARG_SPEC)
argument_spec.update(TURBO_ARG_SPEC)
return argument_spec


Expand Down

0 comments on commit 7d4e0ee

Please sign in to comment.