Update to work with k8s 2.0 (#93)

* Update to work with k8s 2.0

This makes the necessary changes to get the collection working with
kubernetes.core 2.0. The biggest changes here will be switching from the
openshift client to the kubernetes client, and dropping Python 2
support.

* Install kubernetes not openshift

* Add changelog fragment
This commit is contained in:
Mike Graves
2021-06-21 14:41:56 -04:00
committed by GitHub
parent 37833d4316
commit f60ded17b0
12 changed files with 82 additions and 55 deletions

View File

@@ -29,8 +29,8 @@ extends_documentation_fragment:
- kubernetes.core.k8s_resource_options
requirements:
- "python >= 2.7"
- "openshift >= 0.11.0"
- "python >= 3.6"
- "kubernetes >= 12.0.0"
- "PyYAML >= 3.11"
options:
@@ -212,8 +212,9 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
try:
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
K8sAnsibleMixin, AUTH_ARG_SPEC, RESOURCE_ARG_SPEC, WAIT_ARG_SPEC
from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
AUTH_ARG_SPEC, RESOURCE_ARG_SPEC, WAIT_ARG_SPEC
)
HAS_KUBERNETES_COLLECTION = True
except ImportError as e:
@@ -224,7 +225,7 @@ except ImportError as e:
AUTH_ARG_SPEC = RESOURCE_ARG_SPEC = WAIT_ARG_SPEC = {}
try:
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError
except ImportError:
pass
@@ -248,7 +249,7 @@ class OpenShiftProcess(K8sAnsibleMixin):
error=to_native(k8s_collection_import_exception)
)
super(OpenShiftProcess, self).__init__()
super(OpenShiftProcess, self).__init__(self.module)
self.params = self.module.params
self.check_mode = self.module.check_mode
@@ -269,7 +270,7 @@ class OpenShiftProcess(K8sAnsibleMixin):
return spec
def execute_module(self):
self.client = self.get_api_client()
self.client = get_api_client(self.module)
v1_templates = self.find_resource('templates', 'template.openshift.io/v1', fail=True)
v1_processed_templates = self.find_resource('processedtemplates', 'template.openshift.io/v1', fail=True)
@@ -294,7 +295,7 @@ class OpenShiftProcess(K8sAnsibleMixin):
template = None
if src or definition:
self.set_resource_definitions()
self.set_resource_definitions(self.module)
if len(self.resource_definitions) < 1:
self.fail_json('Unable to load a Template resource from src or resource_definition')
elif len(self.resource_definitions) > 1: