Switch to kubernetes upstream python client
For a really long time, we generated and maintained our very own python client generated from kubernetes swagger json files. Now in Kubernetes Community there is a concerted effort to organize an official python client (also generated from swagger) for everyone to use. So let us please switch over from our python-k8sclient and use the community driven python client. I have ported all of our end-to-end tests and got them working in kubernetes client-python project upstream so we should be protected from regressions. Implements: blueprint replace-k8sclient-with-upstream-kubernetes-client Depends-On: I72359f2b811392008eb5267812bf343797b1553a Change-Id: Ib81a69cfdc25198e259e3b3d4081c92c01fd1bc5
This commit is contained in:
parent
26fb77bc0b
commit
e634b55637
|
@ -14,8 +14,9 @@
|
||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from k8sclient.client import api_client
|
from kubernetes import client as k8s_config
|
||||||
from k8sclient.client.apis import apiv_api
|
from kubernetes.client import api_client
|
||||||
|
from kubernetes.client.apis import core_v1_api
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from magnum.conductor.handlers.common.cert_manager import create_client_files
|
from magnum.conductor.handlers.common.cert_manager import create_client_files
|
||||||
|
@ -24,7 +25,7 @@ from magnum.i18n import _LE
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class K8sAPI(apiv_api.ApivApi):
|
class K8sAPI(core_v1_api.CoreV1Api):
|
||||||
|
|
||||||
def _create_temp_file_with_content(self, content):
|
def _create_temp_file_with_content(self, content):
|
||||||
"""Creates temp file and write content to the file.
|
"""Creates temp file and write content to the file.
|
||||||
|
@ -50,11 +51,14 @@ class K8sAPI(apiv_api.ApivApi):
|
||||||
(self.ca_file, self.key_file,
|
(self.ca_file, self.key_file,
|
||||||
self.cert_file) = create_client_files(cluster, context)
|
self.cert_file) = create_client_files(cluster, context)
|
||||||
|
|
||||||
|
config = k8s_config.ConfigurationObject()
|
||||||
|
config.host = cluster.api_address
|
||||||
|
config.ssl_ca_cert = self.ca_file.name
|
||||||
|
config.cert_file = self.cert_file.name
|
||||||
|
config.key_file = self.key_file.name
|
||||||
|
|
||||||
# build a connection with Kubernetes master
|
# build a connection with Kubernetes master
|
||||||
client = api_client.ApiClient(cluster.api_address,
|
client = api_client.ApiClient(config=config)
|
||||||
key_file=self.key_file.name,
|
|
||||||
cert_file=self.cert_file.name,
|
|
||||||
ca_certs=self.ca_file.name)
|
|
||||||
|
|
||||||
super(K8sAPI, self).__init__(client)
|
super(K8sAPI, self).__init__(client)
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class K8sMonitor(monitors.MonitorBase):
|
||||||
|
|
||||||
def pull_data(self):
|
def pull_data(self):
|
||||||
k8s_api = k8s.create_k8s_api(self.context, self.cluster)
|
k8s_api = k8s.create_k8s_api(self.context, self.cluster)
|
||||||
nodes = k8s_api.list_namespaced_node()
|
nodes = k8s_api.list_node()
|
||||||
self.data['nodes'] = self._parse_node_info(nodes)
|
self.data['nodes'] = self._parse_node_info(nodes)
|
||||||
pods = k8s_api.list_namespaced_pod('default')
|
pods = k8s_api.list_namespaced_pod('default')
|
||||||
self.data['pods'] = self._parse_pod_info(pods)
|
self.data['pods'] = self._parse_pod_info(pods)
|
||||||
|
|
|
@ -26,9 +26,10 @@ import fixtures
|
||||||
from six.moves import configparser
|
from six.moves import configparser
|
||||||
|
|
||||||
from heatclient import client as heatclient
|
from heatclient import client as heatclient
|
||||||
from k8sclient.client import api_client
|
|
||||||
from k8sclient.client.apis import apiv_api
|
|
||||||
from keystoneclient.v3 import client as ksclient
|
from keystoneclient.v3 import client as ksclient
|
||||||
|
from kubernetes import client as k8s_config
|
||||||
|
from kubernetes.client import api_client
|
||||||
|
from kubernetes.client.apis import core_v1_api
|
||||||
|
|
||||||
from magnum.common.utils import rmtree_without_raise
|
from magnum.common.utils import rmtree_without_raise
|
||||||
import magnum.conf
|
import magnum.conf
|
||||||
|
@ -386,26 +387,30 @@ class BaseK8sTest(ClusterTest):
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(BaseK8sTest, cls).setUpClass()
|
super(BaseK8sTest, cls).setUpClass()
|
||||||
cls.kube_api_url = cls.cs.clusters.get(cls.cluster.uuid).api_address
|
cls.kube_api_url = cls.cs.clusters.get(cls.cluster.uuid).api_address
|
||||||
k8s_client = api_client.ApiClient(cls.kube_api_url,
|
config = k8s_config.ConfigurationObject()
|
||||||
key_file=cls.key_file,
|
config.host = cls.kube_api_url
|
||||||
cert_file=cls.cert_file,
|
config.ssl_ca_cert = cls.ca_file
|
||||||
ca_certs=cls.ca_file)
|
config.cert_file = cls.cert_file
|
||||||
cls.k8s_api = apiv_api.ApivApi(k8s_client)
|
config.key_file = cls.key_file
|
||||||
|
k8s_client = api_client.ApiClient(config=config)
|
||||||
|
cls.k8s_api = core_v1_api.CoreV1Api(k8s_client)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BaseK8sTest, self).setUp()
|
super(BaseK8sTest, self).setUp()
|
||||||
self.kube_api_url = self.cs.clusters.get(self.cluster.uuid).api_address
|
self.kube_api_url = self.cs.clusters.get(self.cluster.uuid).api_address
|
||||||
k8s_client = api_client.ApiClient(self.kube_api_url,
|
config = k8s_config.ConfigurationObject()
|
||||||
key_file=self.key_file,
|
config.host = self.kube_api_url
|
||||||
cert_file=self.cert_file,
|
config.ssl_ca_cert = self.ca_file
|
||||||
ca_certs=self.ca_file)
|
config.cert_file = self.cert_file
|
||||||
self.k8s_api = apiv_api.ApivApi(k8s_client)
|
config.key_file = self.key_file
|
||||||
|
k8s_client = api_client.ApiClient(config=config)
|
||||||
|
self.k8s_api = core_v1_api.CoreV1Api(k8s_client)
|
||||||
# TODO(coreypobrien) https://bugs.launchpad.net/magnum/+bug/1551824
|
# TODO(coreypobrien) https://bugs.launchpad.net/magnum/+bug/1551824
|
||||||
utils.wait_for_condition(self._is_api_ready, 5, 600)
|
utils.wait_for_condition(self._is_api_ready, 5, 600)
|
||||||
|
|
||||||
def _is_api_ready(self):
|
def _is_api_ready(self):
|
||||||
try:
|
try:
|
||||||
self.k8s_api.list_namespaced_node()
|
self.k8s_api.list_node()
|
||||||
self.LOG.info(_LI("API is ready."))
|
self.LOG.info(_LI("API is ready."))
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -137,7 +137,7 @@ class MonitorsTestCase(base.TestCase):
|
||||||
mock_node.status = mock.MagicMock()
|
mock_node.status = mock.MagicMock()
|
||||||
mock_node.status.capacity = {'memory': '2000Ki', 'cpu': '1'}
|
mock_node.status.capacity = {'memory': '2000Ki', 'cpu': '1'}
|
||||||
mock_nodes.items = [mock_node]
|
mock_nodes.items = [mock_node]
|
||||||
mock_k8s_api.return_value.list_namespaced_node.return_value = (
|
mock_k8s_api.return_value.list_node.return_value = (
|
||||||
mock_nodes)
|
mock_nodes)
|
||||||
mock_pods = mock.MagicMock()
|
mock_pods = mock.MagicMock()
|
||||||
mock_pod = mock.MagicMock()
|
mock_pod = mock.MagicMock()
|
||||||
|
|
|
@ -20,6 +20,7 @@ iso8601>=0.1.11 # MIT
|
||||||
jsonpatch>=1.1 # BSD
|
jsonpatch>=1.1 # BSD
|
||||||
keystoneauth1>=2.18.0 # Apache-2.0
|
keystoneauth1>=2.18.0 # Apache-2.0
|
||||||
keystonemiddleware>=4.12.0 # Apache-2.0
|
keystonemiddleware>=4.12.0 # Apache-2.0
|
||||||
|
kubernetes>=1.0.0b1 # Apache-2.0
|
||||||
marathon>=0.8.6 # MIT
|
marathon>=0.8.6 # MIT
|
||||||
netaddr!=0.7.16,>=0.7.13 # BSD
|
netaddr!=0.7.16,>=0.7.13 # BSD
|
||||||
oslo.concurrency>=3.8.0 # Apache-2.0
|
oslo.concurrency>=3.8.0 # Apache-2.0
|
||||||
|
@ -43,7 +44,6 @@ python-barbicanclient>=4.0.0 # Apache-2.0
|
||||||
python-glanceclient>=2.5.0 # Apache-2.0
|
python-glanceclient>=2.5.0 # Apache-2.0
|
||||||
python-heatclient>=1.6.1 # Apache-2.0
|
python-heatclient>=1.6.1 # Apache-2.0
|
||||||
python-neutronclient>=5.1.0 # Apache-2.0
|
python-neutronclient>=5.1.0 # Apache-2.0
|
||||||
python-k8sclient>=0.2.0 # Apache-2.0
|
|
||||||
python-novaclient>=7.1.0 # Apache-2.0
|
python-novaclient>=7.1.0 # Apache-2.0
|
||||||
python-keystoneclient>=3.8.0 # Apache-2.0
|
python-keystoneclient>=3.8.0 # Apache-2.0
|
||||||
requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0
|
requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0
|
||||||
|
|
Loading…
Reference in New Issue