Make k8sclient use the load balancer address
Currently, our python k8sclient uses the IP address of the master node as the API endpoint. As we are going to have multiple master nodes, we need to use IP address of the load balancer instead. Change-Id: I4da0a80f489f634afc154e8b3626b8c12cc50e86 Partially-Implements: blueprint make-master-ha
This commit is contained in:
parent
86d6996973
commit
bccd681de7
@ -46,20 +46,14 @@ class K8sAPI(ApivbetaApi.ApivbetaApi):
|
||||
|
||||
@staticmethod
|
||||
def _retrieve_k8s_api_endpoint(context, obj):
|
||||
apiserver_port = cfg.CONF.kubernetes.k8s_port
|
||||
if hasattr(obj, 'bay_uuid'):
|
||||
obj = utils.retrieve_bay(context, obj)
|
||||
|
||||
baymodel = utils.retrieve_baymodel(context, obj)
|
||||
if baymodel.apiserver_port is not None:
|
||||
apiserver_port = baymodel.apiserver_port
|
||||
|
||||
params = {
|
||||
'k8s_protocol': cfg.CONF.kubernetes.k8s_protocol,
|
||||
'k8s_port': apiserver_port,
|
||||
'api_address': obj.api_address
|
||||
}
|
||||
return "%(k8s_protocol)s://%(api_address)s:%(k8s_port)s" % params
|
||||
return "%(k8s_protocol)s://%(api_address)s" % params
|
||||
|
||||
|
||||
def create_k8s_api(context, obj):
|
||||
|
@ -353,7 +353,7 @@ class AtomicK8sTemplateDefinition(BaseTemplateDefinition):
|
||||
# self.add_parameter('apiserver_port',
|
||||
# baymodel_attr='apiserver_port')
|
||||
|
||||
self.add_output('kube_master',
|
||||
self.add_output('api_address',
|
||||
bay_attr='api_address')
|
||||
self.add_output('kube_minions',
|
||||
bay_attr=None)
|
||||
|
@ -401,14 +401,14 @@ outputs:
|
||||
params:
|
||||
api_ip_address: {get_attr: [api_pool_floating, floating_ip_address]}
|
||||
description: >
|
||||
This is the IP address and port of the Kubernetes API server.
|
||||
This is the API endpoint of the Kubernetes server. Use this to access
|
||||
the Kubernetes API from outside the cluster.
|
||||
|
||||
kube_master:
|
||||
value: {get_attr: [kube_master_floating, floating_ip_address]}
|
||||
description: >
|
||||
This is the "public" ip address of the Kubernetes master server. Use this address to
|
||||
log in to the Kubernetes master via ssh or to access the Kubernetes API
|
||||
from outside the cluster.
|
||||
log in to the Kubernetes master via ssh.
|
||||
|
||||
kube_minions:
|
||||
value: {get_attr: [kube_minions, kube_minion_ip]}
|
||||
|
@ -208,9 +208,9 @@ class TestKubernetesAPIs(BaseMagnumClient):
|
||||
super(TestKubernetesAPIs, cls).setUpClass()
|
||||
cls.baymodel = cls._create_baymodel('testk8sAPI')
|
||||
cls.bay = cls._create_bay('testk8sAPI', cls.baymodel.uuid)
|
||||
kube_master_ip = cls.cs.bays.get(cls.bay.uuid).api_address
|
||||
kube_master_url = 'http://%s:8080' % kube_master_ip
|
||||
k8s_client = swagger.ApiClient(kube_master_url)
|
||||
kube_api_address = cls.cs.bays.get(cls.bay.uuid).api_address
|
||||
kube_api_url = 'http://%s' % kube_api_address
|
||||
k8s_client = swagger.ApiClient(kube_api_url)
|
||||
cls.k8s_api = ApivbetaApi.ApivbetaApi(k8s_client)
|
||||
|
||||
@classmethod
|
||||
|
@ -284,7 +284,7 @@ class TestBayConductorWithK8s(base.TestCase):
|
||||
"output_key": "kube_minions_external"},
|
||||
{"output_value": expected_api_address,
|
||||
"description": "No description given",
|
||||
"output_key": "kube_master"},
|
||||
"output_key": "api_address"},
|
||||
{"output_value": ['any', 'output'],
|
||||
"description": "No description given",
|
||||
"output_key": "kube_minions"}
|
||||
|
@ -22,55 +22,25 @@ from magnum.tests import base
|
||||
|
||||
class TestK8sAPI(base.TestCase):
|
||||
|
||||
def _test_retrieve_k8s_api_endpoint(self, mock_baymodel_get_by_uuid,
|
||||
mock_bay_get_by_uuid,
|
||||
apiserver_port=None):
|
||||
@patch('magnum.objects.Bay.get_by_uuid')
|
||||
def test_retrieve_k8s_api_endpoint(self, mock_bay_get_by_uuid):
|
||||
expected_context = 'context'
|
||||
expected_api_address = 'api_address'
|
||||
expected_baymodel_id = 'e74c40e0-d825-11e2-a28f-0800200c9a61'
|
||||
expected_protocol = cfg.CONF.kubernetes.k8s_protocol
|
||||
if apiserver_port is None:
|
||||
expected_apiserver_port = cfg.CONF.kubernetes.k8s_port
|
||||
else:
|
||||
expected_apiserver_port = apiserver_port
|
||||
|
||||
resource = objects.Pod({})
|
||||
resource.bay_uuid = 'bay_uuid'
|
||||
bay = objects.Bay({})
|
||||
bay.api_address = expected_api_address
|
||||
bay.baymodel_id = expected_baymodel_id
|
||||
baymodel = objects.BayModel({})
|
||||
baymodel.apiserver_port = apiserver_port
|
||||
|
||||
mock_bay_get_by_uuid.return_value = bay
|
||||
mock_baymodel_get_by_uuid.return_value = baymodel
|
||||
|
||||
actual_api_endpoint = k8s_api.K8sAPI._retrieve_k8s_api_endpoint(
|
||||
expected_context, resource)
|
||||
self.assertEqual("%s://%s:%d" % (expected_protocol,
|
||||
expected_api_address,
|
||||
expected_apiserver_port),
|
||||
self.assertEqual("%s://%s" % (expected_protocol,
|
||||
expected_api_address),
|
||||
actual_api_endpoint)
|
||||
|
||||
@patch('magnum.objects.Bay.get_by_uuid')
|
||||
@patch('magnum.objects.BayModel.get_by_uuid')
|
||||
def test_retrieve_k8s_api_endpoint(
|
||||
self,
|
||||
mock_baymodel_get_by_uuid,
|
||||
mock_bay_get_by_uuid):
|
||||
self._test_retrieve_k8s_api_endpoint(mock_baymodel_get_by_uuid,
|
||||
mock_bay_get_by_uuid,
|
||||
apiserver_port=9999)
|
||||
|
||||
@patch('magnum.objects.Bay.get_by_uuid')
|
||||
@patch('magnum.objects.BayModel.get_by_uuid')
|
||||
def test_retrieve_k8s_api_endpoint_without_baymodel_apiserver_port(
|
||||
self,
|
||||
mock_baymodel_get_by_uuid,
|
||||
mock_bay_get_by_uuid):
|
||||
self._test_retrieve_k8s_api_endpoint(mock_baymodel_get_by_uuid,
|
||||
mock_bay_get_by_uuid)
|
||||
|
||||
@patch('magnum.conductor.k8s_api.K8sAPI')
|
||||
def test_create_k8s_api(self, mock_k8s_api_cls):
|
||||
context = 'context'
|
||||
|
Loading…
x
Reference in New Issue
Block a user