From bb7ba49c624f4b1b65c9ac413558edc60c70d3a7 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 5 May 2019 16:33:29 +0000 Subject: [PATCH] Support exposing ports in capsule - API In capsule controller, process the 'ports' field and convert it to 'exposed_ports' property of the container. Right now, we process the 'containerPort' and 'protocol' field. Under the hook, Zun will create a security group for opening that port and protocol. The 'hostPort' field is ignored since Zun doesn't expose compute host information. This might be revisited later and implemented by the neutron floating IP port forwarding feature. Change-Id: Ic71d19c5e61573373babb5082331b98847a3cebf --- .zuul.yaml | 2 +- zun/api/controllers/v1/capsules.py | 14 +++++++++----- zun/api/controllers/v1/schemas/parameter_types.py | 2 +- zun/api/controllers/versions.py | 3 ++- zun/api/rest_api_version_history.rst | 14 ++++++++++++++ zun/tests/unit/api/base.py | 2 +- zun/tests/unit/api/controllers/test_root.py | 4 ++-- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index 047b2e63c..89790bbaa 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -26,7 +26,7 @@ test-config: $TEMPEST_CONFIG: container_service: - min_microversion: 1.34 + min_microversion: 1.35 devstack_services: tempest: true devstack_plugins: diff --git a/zun/api/controllers/v1/capsules.py b/zun/api/controllers/v1/capsules.py index fc65dffd9..5e045a0f3 100644 --- a/zun/api/controllers/v1/capsules.py +++ b/zun/api/controllers/v1/capsules.py @@ -287,12 +287,16 @@ class CapsuleController(base.Controller): container_dict['command'] = container_dict['args'] container_dict.pop('args') - # NOTE(kevinz): Don't support port remapping, will find a - # easy way to implement it. - # if container need to open some port, just open it in container, - # user can change the security group and getting access to port. if container_dict.get('ports'): - container_dict.pop('ports') + exposed_ports = {} + ports = container_dict.pop('ports') + for port in ports: + container_port = "%s/%s" % ( + port['containerPort'], + port.get('protocol', 'tcp').lower()) + host_port = {} + exposed_ports[container_port] = host_port + container_dict['exposed_ports'] = exposed_ports if container_dict.get('resources'): resources_list = container_dict.get('resources') diff --git a/zun/api/controllers/v1/schemas/parameter_types.py b/zun/api/controllers/v1/schemas/parameter_types.py index 21bab0b3c..0308cc460 100644 --- a/zun/api/controllers/v1/schemas/parameter_types.py +++ b/zun/api/controllers/v1/schemas/parameter_types.py @@ -421,7 +421,7 @@ capsule_container_ports = { 'protocol': capsule_port_protocol, }, 'additionalProperties': False, - 'required': ['containerPort', 'hostPort'] + 'required': ['containerPort'] } } diff --git a/zun/api/controllers/versions.py b/zun/api/controllers/versions.py index 5624f21e3..82d0940c9 100644 --- a/zun/api/controllers/versions.py +++ b/zun/api/controllers/versions.py @@ -67,10 +67,11 @@ REST_API_VERSION_HISTORY = """REST API Version History: * 1.32 - Make capsule deletion asynchronized * 1.33 - Add 'finish_time' to container actions * 1.34 - Add 'init_containers' to capsule + * 1.35 - Support exposing container ports in capsule """ BASE_VER = '1.1' -CURRENT_MAX_VER = '1.34' +CURRENT_MAX_VER = '1.35' class Version(object): diff --git a/zun/api/rest_api_version_history.rst b/zun/api/rest_api_version_history.rst index 982c5c3ce..1d3192022 100644 --- a/zun/api/rest_api_version_history.rst +++ b/zun/api/rest_api_version_history.rst @@ -261,3 +261,17 @@ user documentation. Add 'init_containers' to capsule. This field contains a list of init_container information. + +1.35 +---- + + Support processing 'ports' field in capsule's container. + Users can leverage this field to open ports of a container. + For example:: + + spec: + containers: + - image: "nginx" + ports: + - containerPort: 80 + protocol: TCP diff --git a/zun/tests/unit/api/base.py b/zun/tests/unit/api/base.py index 0908103fb..f70cf8877 100644 --- a/zun/tests/unit/api/base.py +++ b/zun/tests/unit/api/base.py @@ -26,7 +26,7 @@ from zun.tests.unit.db import base PATH_PREFIX = '/v1' -CURRENT_VERSION = "container 1.34" +CURRENT_VERSION = "container 1.35" class FunctionalTest(base.DbTestCase): diff --git a/zun/tests/unit/api/controllers/test_root.py b/zun/tests/unit/api/controllers/test_root.py index dd59ae39e..5cbbc6ded 100644 --- a/zun/tests/unit/api/controllers/test_root.py +++ b/zun/tests/unit/api/controllers/test_root.py @@ -28,7 +28,7 @@ class TestRootController(api_base.FunctionalTest): 'default_version': {'id': 'v1', 'links': [{'href': 'http://localhost/v1/', 'rel': 'self'}], - 'max_version': '1.34', + 'max_version': '1.35', 'min_version': '1.1', 'status': 'CURRENT'}, 'description': 'Zun is an OpenStack project which ' @@ -37,7 +37,7 @@ class TestRootController(api_base.FunctionalTest): 'versions': [{'id': 'v1', 'links': [{'href': 'http://localhost/v1/', 'rel': 'self'}], - 'max_version': '1.34', + 'max_version': '1.35', 'min_version': '1.1', 'status': 'CURRENT'}]}