mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-11-21 14:48:37 +00:00
Emit an explicit deprecation warning when users enable Ansible Turbo mode via `ENABLE_TURBO_MODE`, and stop turbo mode from being used on ansible-core versions where `cloud.common` is not supported.
Turbo mode depends on `cloud.common`, which is being retired. PR #1120 already deprecated the `cloud.common` dependency; without this change, removing that dependency later would cause `ENABLE_TURBO_MODE` to stop working silently. This PR warns users at runtime so they can migrate before support is removed in `kubernetes.core` 8.0.0.
Changes:
* Modules: emit the deprecation at import time via the module-level `deprecate()` in `plugins/module_utils/ansiblemodule.py`. `AnsibleTurboModule.__init__()` ends in `run_on_daemon()`, which calls `exit_json()` and exits the process, so a `deprecate()` call tied to instance construction is never reached.
* Modules: skip turbo mode on ansible-core >= 2.19.0 and fall back to the standard `AnsibleModule`, emitting a warning. `cloud.common` declares `requires_ansible '>=2.15.0,<2.19'`, but that is only enforced at collection load time and the turbo import itself still succeeds on newer cores, so turbo mode would otherwise fail later with `byte indices must be integers or slices, not str`.
* Modules and lookup: warn instead of silently falling back when `ENABLE_TURBO_MODE` is set but `cloud.common` is not installed.
* Lookup: call `Display.deprecated()` in the `k8s` lookup when turbo mode is enabled. The lookup path still works on >= 2.19, so it keeps using turbo and is not version-gated.
* Docs: add deprecation notices to `README.md` and `docs/ansible_turbo_mode.rst`.
* Changelog: add `deprecated_features`, `bugfixes`, and `minor_changes` fragment entries.
On ansible-core < 2.19 with `cloud.common` installed, turbo mode continues to work exactly as before and only gains a deprecation warning. On ansible-core >= 2.19 turbo mode is now deliberately bypassed, which replaces a confusing traceback with a clear warning.
* Bugfix Pull Request
* Docs Pull Request
`ENABLE_TURBO_MODE` / Ansible Turbo mode
On a supported ansible-core (< 2.19) with `cloud.common` installed, turbo mode stays active and users see:
```
[DEPRECATION WARNING]: ENABLE_TURBO_MODE is deprecated, as it relies on the cloud.common collection which is being retired. Setting this environment variable will have no effect once support is removed. This feature will be removed from kubernetes.core in version 8.0.0.
```
On ansible-core >= 2.19.0, turbo mode is bypassed and an additional warning is emitted:
```
[WARNING]: ENABLE_TURBO_MODE is ignored on ansible-core 2.21.4: Ansible Turbo mode requires the cloud.common collection, which supports ansible-core < 2.19.0 only. Continuing without Turbo mode.
```
Warnings are emitted from:
* `plugins/module_utils/ansiblemodule.py` for collection modules
* `plugins/lookup/k8s.py` for the `k8s` lookup plugin
To verify locally:
```shell
export ENABLE_TURBO_MODE=1
ansible localhost -m kubernetes.core.k8s_info -a "kind=Namespace" 2>&1 | grep -iE "deprecat|warning"
```
Integration tests that run with `ENABLE_TURBO_MODE=true` use ansible-core 2.18, where turbo mode remains enabled, so turbo behaviour there is unchanged.
Thanks to @yurnov for diagnosing the unreachable deprecation and for the suggested fix in [mandar242#1](https://github.com/mandar242/kubernetes.core/pull/1).
(cherry picked from commit 031bc475fa)
Co-authored-by: Mandar Kulkarni <mandkulk@redhat.com>
56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
import os
|
|
|
|
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
|
from ansible.module_utils.common.validation import check_type_bool
|
|
from ansible.module_utils.common.warnings import deprecate, warn
|
|
from ansible_collections.kubernetes.core.plugins.module_utils.version import (
|
|
LooseVersion,
|
|
)
|
|
|
|
# cloud.common declares requires_ansible '>=2.15.0,<2.19'. On newer ansible-core the
|
|
# import still succeeds, so the version has to be checked explicitly: relying on
|
|
# ImportError alone lets turbo mode fail later with an unrelated traceback.
|
|
TURBO_UNSUPPORTED_CORE = "2.19.0"
|
|
|
|
try:
|
|
enable_turbo_mode = check_type_bool(os.environ.get("ENABLE_TURBO_MODE"))
|
|
except TypeError:
|
|
enable_turbo_mode = False
|
|
|
|
if enable_turbo_mode:
|
|
deprecate(
|
|
"ENABLE_TURBO_MODE is deprecated, as it relies on the cloud.common collection "
|
|
"which is being retired. Setting this environment variable will have no effect "
|
|
"once support is removed.",
|
|
version="8.0.0",
|
|
collection_name="kubernetes.core",
|
|
)
|
|
if LooseVersion(ansible_version) >= LooseVersion(TURBO_UNSUPPORTED_CORE):
|
|
warn(
|
|
"ENABLE_TURBO_MODE is ignored on ansible-core %s: Ansible Turbo mode requires "
|
|
"the cloud.common collection, which supports ansible-core < %s only. "
|
|
"Continuing without Turbo mode." % (ansible_version, TURBO_UNSUPPORTED_CORE)
|
|
)
|
|
enable_turbo_mode = False
|
|
|
|
if enable_turbo_mode:
|
|
try:
|
|
from ansible_collections.cloud.common.plugins.module_utils.turbo.module import ( # noqa: F401
|
|
AnsibleTurboModule as AnsibleModule,
|
|
)
|
|
|
|
AnsibleModule.collection_name = "kubernetes.core"
|
|
except ImportError:
|
|
warn(
|
|
"ENABLE_TURBO_MODE is set but the cloud.common collection is not installed. "
|
|
"Continuing without Turbo mode."
|
|
)
|
|
from ansible.module_utils.basic import AnsibleModule # noqa: F401
|
|
else:
|
|
from ansible.module_utils.basic import AnsibleModule # noqa: F401
|