diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6682b3188d..c316c36b40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/changelogs/fragments/135-rename-apply-function.yml b/changelogs/fragments/135-rename-apply-function.yml new file mode 100644 index 0000000000..965cd6f917 --- /dev/null +++ b/changelogs/fragments/135-rename-apply-function.yml @@ -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). diff --git a/molecule/default/tasks/full.yml b/molecule/default/tasks/full.yml index 2e3268ed40..65dfba013f 100644 --- a/molecule/default/tasks/full.yml +++ b/molecule/default/tasks/full.yml @@ -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 diff --git a/molecule/default/tasks/template.yml b/molecule/default/tasks/template.yml index cb5b91ac81..d7cba2dc41 100644 --- a/molecule/default/tasks/template.yml +++ b/molecule/default/tasks/template.yml @@ -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: diff --git a/plugins/action/helm.py b/plugins/action/helm.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/helm.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/helm_info.py b/plugins/action/helm_info.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/helm_info.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/helm_plugin.py b/plugins/action/helm_plugin.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/helm_plugin.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/helm_plugin_info.py b/plugins/action/helm_plugin_info.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/helm_plugin_info.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/helm_repository.py b/plugins/action/helm_repository.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/helm_repository.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/k8s.py b/plugins/action/k8s.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/k8s.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/k8s_cluster_info.py b/plugins/action/k8s_cluster_info.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/k8s_cluster_info.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/k8s_exec.py b/plugins/action/k8s_exec.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/k8s_exec.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/k8s_log.py b/plugins/action/k8s_log.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/k8s_log.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/k8s_rollback.py b/plugins/action/k8s_rollback.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/k8s_rollback.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/k8s_scale.py b/plugins/action/k8s_scale.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/k8s_scale.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/k8s_service.py b/plugins/action/k8s_service.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/k8s_service.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/action/ks8_json_patch.py b/plugins/action/ks8_json_patch.py new file mode 120000 index 0000000000..667980ed38 --- /dev/null +++ b/plugins/action/ks8_json_patch.py @@ -0,0 +1 @@ +k8s_info.py \ No newline at end of file diff --git a/plugins/module_utils/apply.py b/plugins/module_utils/apply.py index 87c3e2d6ec..486d9a5a2c 100644 --- a/plugins/module_utils/apply.py +++ b/plugins/module_utils/apply.py @@ -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')) diff --git a/plugins/module_utils/k8sdynamicclient.py b/plugins/module_utils/k8sdynamicclient.py index 7a7b6cddc7..0827009ce0 100644 --- a/plugins/module_utils/k8sdynamicclient.py +++ b/plugins/module_utils/k8sdynamicclient.py @@ -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 from ansible_collections.kubernetes.core.plugins.module_utils.exceptions import ApplyException @@ -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))