|
10 | 10 | from kubernetes import client as kubeclient |
11 | 11 | from kubernetes.client.rest import ApiException |
12 | 12 | from miq_version import TemplateName, Version |
13 | | -from openshift import client as ociclient |
14 | 13 | from wait_for import TimedOutError, wait_for |
15 | 14 |
|
| 15 | +# Try to import openshift client module |
| 16 | +# In openshift>=0.13, the static client module was removed in favor of the dynamic client |
| 17 | +# For backward compatibility, we attempt the import but allow it to fail gracefully |
| 18 | +try: |
| 19 | + from openshift import client as ociclient |
| 20 | + |
| 21 | + _OPENSHIFT_CLIENT_AVAILABLE = True |
| 22 | +except (ImportError, AttributeError): |
| 23 | + # openshift.client module doesn't exist in openshift>=0.13 |
| 24 | + # The OpenShift functionality will not work until code is migrated to dynamic client |
| 25 | + ociclient = None |
| 26 | + _OPENSHIFT_CLIENT_AVAILABLE = False |
| 27 | + |
16 | 28 | from wrapanapi.systems.base import System |
17 | 29 |
|
18 | 30 | # this service allows to access db outside of openshift |
@@ -196,6 +208,14 @@ def _identifying_attrs(self): |
196 | 208 | return {"hostname": self.hostname, "port": self.port} |
197 | 209 |
|
198 | 210 | def _connect(self): |
| 211 | + if not _OPENSHIFT_CLIENT_AVAILABLE or ociclient is None: |
| 212 | + raise ImportError( |
| 213 | + "The openshift.client module is not available. " |
| 214 | + "OpenShift requires openshift<=0.13 which is incompatible with Python 3.9+, " |
| 215 | + "or the code needs to be migrated to use the openshift.dynamic client API. " |
| 216 | + "See https://github.com/openshift/openshift-restclient-python for guidance." |
| 217 | + ) |
| 218 | + |
199 | 219 | url = "{proto}://{host}:{port}".format( |
200 | 220 | proto=self.protocol, host=self.hostname, port=self.port |
201 | 221 | ) |
|
0 commit comments