Fix apply on Ansible 2.9 (#135)

* Fix apply on Ansible 2.9

For some reason the apply function can't be correctly imported in
Ansible 2.9. This just renames it to get it to import. I've also added
molecule testing on multiple Ansible versions.

* Add changelog fragment
This commit is contained in:
Mike Graves
2021-06-16 11:28:46 -04:00
committed by GitHub
parent 46494a18bd
commit c11a255026
19 changed files with 24 additions and 7 deletions

View File

@@ -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
@@ -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

View File

@@ -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).

View File

@@ -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

View File

@@ -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:

1
plugins/action/helm.py Symbolic link
View File

@@ -0,0 +1 @@
k8s_info.py

1
plugins/action/helm_info.py Symbolic link
View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -0,0 +1 @@
k8s_info.py

1
plugins/action/k8s.py Symbolic link
View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -0,0 +1 @@
k8s_info.py

1
plugins/action/k8s_exec.py Symbolic link
View File

@@ -0,0 +1 @@
k8s_info.py

1
plugins/action/k8s_log.py Symbolic link
View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -0,0 +1 @@
k8s_info.py

1
plugins/action/k8s_scale.py Symbolic link
View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -0,0 +1 @@
k8s_info.py

View File

@@ -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'))

View File

@@ -19,7 +19,7 @@ __metaclass__ = type
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
from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import ApplyException
@@ -33,7 +33,7 @@ class K8SDynamicClient(DynamicClient):
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))