Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix apply on Ansible 2.9 #135

Merged
merged 6 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
strategy:
matrix:
python_version: ['3.7']
ansible_version: ['==2.9.*', '==2.10.*', '']
steps:
- name: Check out code
uses: actions/checkout@v2
Expand All @@ -92,7 +93,7 @@ jobs:
# The 3.3.0 release of molecule introduced a breaking change. See
# https://github.com/ansible-community/molecule/issues/3083
- name: Install molecule and kubernetes dependencies
run: pip install ansible "molecule<3.3.0" yamllint kubernetes flake8 jsonpatch
run: pip install ansible${{ matrix.ansible_version }} "molecule<3.3.0" yamllint kubernetes flake8 jsonpatch

# The latest release doesn't work with Molecule currently.
# See: https://github.com/ansible-community/molecule/issues/2757
Expand Down
3 changes: 3 additions & 0 deletions changelogs/fragments/135-rename-apply-function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- rename the apply function to fix broken imports in Ansible 2.9 (https://github.com/ansible-collections/kubernetes.core/pull/135).
2 changes: 1 addition & 1 deletion molecule/default/tasks/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@

### https://github.com/ansible-collections/community.kubernetes/issues/111
- set_fact:
api_groups: "{{ lookup('k8s', cluster_info='api_groups') }}"
api_groups: "{{ lookup('kubernetes.core.k8s', cluster_info='api_groups') }}"

- debug:
var: api_groups
Expand Down
4 changes: 2 additions & 2 deletions molecule/default/tasks/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@
assert:
that:
- resource is successful
- resource.result.results | selectattr('changed') | length == 1
- resource.result.results | selectattr('error', 'defined') | length == 1
- resource.result.results | selectattr('changed') | list | length == 1
- resource.result.results | selectattr('error', 'defined') | list | length == 1

- name: Remove Pod (Cleanup)
kubernetes.core.k8s:
Expand Down
1 change: 1 addition & 0 deletions plugins/action/helm.py
1 change: 1 addition & 0 deletions plugins/action/helm_info.py
1 change: 1 addition & 0 deletions plugins/action/helm_plugin.py
1 change: 1 addition & 0 deletions plugins/action/helm_plugin_info.py
1 change: 1 addition & 0 deletions plugins/action/helm_repository.py
1 change: 1 addition & 0 deletions plugins/action/k8s.py
1 change: 1 addition & 0 deletions plugins/action/k8s_cluster_info.py
1 change: 1 addition & 0 deletions plugins/action/k8s_exec.py
1 change: 1 addition & 0 deletions plugins/action/k8s_log.py
1 change: 1 addition & 0 deletions plugins/action/k8s_rollback.py
1 change: 1 addition & 0 deletions plugins/action/k8s_scale.py
1 change: 1 addition & 0 deletions plugins/action/k8s_service.py
1 change: 1 addition & 0 deletions plugins/action/ks8_json_patch.py
2 changes: 1 addition & 1 deletion plugins/module_utils/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def apply_object(resource, definition):
return apply_patch(actual.to_dict(), definition)


def apply(resource, definition):
def k8s_apply(resource, definition):
existing, desired = apply_object(resource, definition)
if not existing:
return resource.create(body=desired, namespace=definition['metadata'].get('namespace'))
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/k8sdynamicclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from kubernetes.dynamic import DynamicClient

from ansible_collections.kubernetes.core.plugins.module_utils.apply import apply
from ansible_collections.kubernetes.core.plugins.module_utils.apply import k8s_apply
gravesm marked this conversation as resolved.
Show resolved Hide resolved
from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import ApplyException


Expand All @@ -33,7 +33,7 @@ def apply(self, resource, body=None, name=None, namespace=None):
if resource.namespaced:
body['metadata']['namespace'] = super().ensure_namespace(resource, namespace, body)
try:
return apply(resource, body)
return k8s_apply(resource, body)
except ApplyException as e:
raise ValueError("Could not apply strategic merge to %s/%s: %s" %
(body['kind'], body['metadata']['name'], e))