mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-29 02:44:41 +00:00
Enable turbo mode for k8s lookup plugin (#335)
Enable turbo mode for k8s lookup plugin SUMMARY Enable Turbo mode for k8s lookup plugin This resolves partially #291 ISSUE TYPE Feature Pull Request COMPONENT NAME k8s lookup Reviewed-by: Abhijeet Kasurde <None> Reviewed-by: None <None> Reviewed-by: None <None>
This commit is contained in:
@@ -169,7 +169,7 @@ For documentation on how to use individual modules and other content included in
|
|||||||
## Ansible Turbo mode Tech Preview
|
## Ansible Turbo mode Tech Preview
|
||||||
|
|
||||||
|
|
||||||
The ``kubernetes.core`` collection supports Ansible Turbo mode as a tech preview via the ``cloud.common`` collection. By default, this feature is disabled. To enable Turbo mode, set the environment variable `ENABLE_TURBO_MODE=1` on the managed node. For example:
|
The ``kubernetes.core`` collection supports Ansible Turbo mode as a tech preview via the ``cloud.common`` collection. By default, this feature is disabled. To enable Turbo mode for modules, set the environment variable `ENABLE_TURBO_MODE=1` on the managed node. For example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
---
|
---
|
||||||
@@ -180,6 +180,9 @@ The ``kubernetes.core`` collection supports Ansible Turbo mode as a tech preview
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To enable Turbo mode for k8s lookup plugin, set the environment variable `ENABLE_TURBO_MODE=1` on the managed node. This is not working when
|
||||||
|
defined in the playbook using `environment` keyword as above, you must set it using `export ENABLE_TURBO_MODE=1`.
|
||||||
|
|
||||||
Please read more about Ansible Turbo mode - [here](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/ansible_turbo_mode.rst).
|
Please read more about Ansible Turbo mode - [here](https://github.com/ansible-collections/kubernetes.core/blob/main/docs/ansible_turbo_mode.rst).
|
||||||
|
|
||||||
## Testing and Development
|
## Testing and Development
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- k8s lookup plugin - Enable turbo mode via environment variable (https://github.com/ansible-collections/kubernetes.core/issues/291).
|
||||||
@@ -183,15 +183,31 @@ RETURN = """
|
|||||||
type: complex
|
type: complex
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.common._collections_compat import KeysView
|
from ansible.module_utils.common._collections_compat import KeysView
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.module_utils.common.validation import check_type_bool
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
||||||
K8sAnsibleMixin,
|
K8sAnsibleMixin,
|
||||||
get_api_client,
|
get_api_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
enable_turbo_mode = check_type_bool(os.environ.get("ENABLE_TURBO_MODE"))
|
||||||
|
except TypeError:
|
||||||
|
enable_turbo_mode = False
|
||||||
|
|
||||||
|
if enable_turbo_mode:
|
||||||
|
try:
|
||||||
|
from ansible_collections.cloud.common.plugins.plugin_utils.turbo.lookup import (
|
||||||
|
TurboLookupBase as LookupBase,
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
from ansible.plugins.lookup import LookupBase # noqa: F401
|
||||||
|
else:
|
||||||
|
from ansible.plugins.lookup import LookupBase # noqa: F401
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.dynamic.exceptions import NotFoundError
|
from kubernetes.dynamic.exceptions import NotFoundError
|
||||||
@@ -283,5 +299,7 @@ class KubernetesLookup(K8sAnsibleMixin):
|
|||||||
|
|
||||||
|
|
||||||
class LookupModule(LookupBase):
|
class LookupModule(LookupBase):
|
||||||
def run(self, terms, variables=None, **kwargs):
|
def _run(self, terms, variables=None, **kwargs):
|
||||||
return KubernetesLookup().run(terms, variables=variables, **kwargs)
|
return KubernetesLookup().run(terms, variables=variables, **kwargs)
|
||||||
|
|
||||||
|
run = _run if not hasattr(LookupBase, "run_on_daemon") else LookupBase.run_on_daemon
|
||||||
|
|||||||
Reference in New Issue
Block a user