From 0492c35723925be603b6d218aca4114d0c4ef46f Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sat, 21 Dec 2019 20:43:56 +0000 Subject: [PATCH] Add 'annotations' to capsule API Implements: blueprint add-annotations-to-capsule Change-Id: Ibf3f801596c3a768b05fca9ccbef555ddba319af --- .zuul.yaml | 2 +- api-ref/source/capsules.inc | 4 ++++ api-ref/source/parameters.yaml | 21 +++++++++++++++++-- .../source/samples/capsule-create-req.json | 5 ++++- .../source/samples/capsule-create-resp.json | 3 +++ .../source/samples/capsule-get-all-resp.json | 3 +++ api-ref/source/samples/capsule-show-resp.json | 3 +++ zun/api/controllers/v1/capsules.py | 1 + .../controllers/v1/schemas/parameter_types.py | 5 +++++ zun/api/controllers/v1/views/capsules_view.py | 1 + zun/api/controllers/versions.py | 3 ++- zun/api/rest_api_version_history.rst | 6 ++++++ zun/tests/unit/api/base.py | 2 +- zun/tests/unit/api/controllers/test_root.py | 4 ++-- 14 files changed, 55 insertions(+), 8 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index f837f9a6e..2afdcb547 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -28,7 +28,7 @@ test-config: $TEMPEST_CONFIG: container_service: - min_microversion: 1.37 + min_microversion: 1.38 post-config: $ZUN_CONF: docker: diff --git a/api-ref/source/capsules.inc b/api-ref/source/capsules.inc index 99ca2733b..cbd0bc532 100644 --- a/api-ref/source/capsules.inc +++ b/api-ref/source/capsules.inc @@ -43,6 +43,7 @@ Capsule Template - metadata: capsule-metadata-request - metadata.labels: capsule-labels-request - metadata.name: capsule-name-request + - metadata.annotations: capsule-annotations-request - spec: capsule-spec-request .. _create-capsule-spec: @@ -114,6 +115,7 @@ Capsule - uuid: capsule-uuid - name: capsule-name - labels: capsule-labels + - annotations: capsule-annotations - restart_policy: capsule-restart_policy - created_at: created_at - updated_at: updated_at @@ -206,6 +208,7 @@ Capsule - uuid: capsule-uuid - name: capsule-name - labels: capsule-labels + - annotations: capsule-annotations - restart_policy: capsule-restart_policy - created_at: created_at - updated_at: updated_at @@ -301,6 +304,7 @@ Capsule - uuid: capsule-uuid - name: capsule-name - labels: capsule-labels + - annotations: capsule-annotations - restart_policy: capsule-restart_policy - created_at: created_at - updated_at: updated_at diff --git a/api-ref/source/parameters.yaml b/api-ref/source/parameters.yaml index eb9400736..eebcf3456 100644 --- a/api-ref/source/parameters.yaml +++ b/api-ref/source/parameters.yaml @@ -327,6 +327,22 @@ capsule-addresses: IP address of the capsule. This includes both ipv4 and/or ipv6 addresses. in: body required: true +capsule-annotations: + description: | + The annotations of the capsule. + Annotations is an unstructured key value map stored with a resource + that may be set by external tools to store and retrieve arbitrary metadata. + in: body + required: true + type: object +capsule-annotations-request: + description: | + The annotations added to the capsule. + Annotations is an unstructured key value map stored with a resource + that may be set by external tools to store and retrieve arbitrary metadata. + in: body + required: false + type: object capsule-args-request: description: | The arguments to the command. @@ -466,14 +482,15 @@ capsule-memory: capsule-metadata-request: description: | Capsule metadata in key-value format. - Keys can be ``name`` or ``labels``. + Keys can be ``name``, ``labels`` and ``annotations``. An example format would look as follows: .. code-block:: javascript "metadata": { "labels": {"app": "web"}, - "name": "demo" + "name": "demo", + "annotations": {"key1": "value1"} } in: body diff --git a/api-ref/source/samples/capsule-create-req.json b/api-ref/source/samples/capsule-create-req.json index 71c8148d4..b8e7bdcc1 100644 --- a/api-ref/source/samples/capsule-create-req.json +++ b/api-ref/source/samples/capsule-create-req.json @@ -70,7 +70,10 @@ "labels": { "app": "web" }, - "name": "demo" + "name": "demo", + "annotations": { + "key1": "value1" + }, } } } \ No newline at end of file diff --git a/api-ref/source/samples/capsule-create-resp.json b/api-ref/source/samples/capsule-create-resp.json index f1d9c901b..753660003 100644 --- a/api-ref/source/samples/capsule-create-resp.json +++ b/api-ref/source/samples/capsule-create-resp.json @@ -16,6 +16,9 @@ "labels": { "app": "web" }, + "annotations": { + "key1": "value1" + }, "restart_policy": { "MaximumRetryCount": "0", "Name": "always" diff --git a/api-ref/source/samples/capsule-get-all-resp.json b/api-ref/source/samples/capsule-get-all-resp.json index 092232d8f..acda6e1b0 100644 --- a/api-ref/source/samples/capsule-get-all-resp.json +++ b/api-ref/source/samples/capsule-get-all-resp.json @@ -18,6 +18,9 @@ "labels": { "app": "web" }, + "annotations": { + "key1": "value1" + }, "restart_policy": { "MaximumRetryCount": "0", "Name": "always" diff --git a/api-ref/source/samples/capsule-show-resp.json b/api-ref/source/samples/capsule-show-resp.json index d6cb4ab64..4a9b82ca5 100644 --- a/api-ref/source/samples/capsule-show-resp.json +++ b/api-ref/source/samples/capsule-show-resp.json @@ -16,6 +16,9 @@ "labels": { "app": "web" }, + "annotations": { + "key1": "value1" + }, "restart_policy": { "MaximumRetryCount": "0", "Name": "always" diff --git a/zun/api/controllers/v1/capsules.py b/zun/api/controllers/v1/capsules.py index 13e307803..72b7ed0ca 100644 --- a/zun/api/controllers/v1/capsules.py +++ b/zun/api/controllers/v1/capsules.py @@ -235,6 +235,7 @@ class CapsuleController(base.Controller): if metadata_info: new_capsule.name = metadata_info.get('name', None) new_capsule.labels = metadata_info.get('labels', None) + new_capsule.annotations = metadata_info.get('annotations', None) # create the capsule in DB so that it generates a 'id' new_capsule.save() diff --git a/zun/api/controllers/v1/schemas/parameter_types.py b/zun/api/controllers/v1/schemas/parameter_types.py index 2133f8b45..04db0f805 100644 --- a/zun/api/controllers/v1/schemas/parameter_types.py +++ b/zun/api/controllers/v1/schemas/parameter_types.py @@ -132,6 +132,10 @@ labels = { 'type': ['object', 'null'] } +annotations = { + 'type': ['object', 'null'] +} + hints = { 'type': ['object', 'null'] } @@ -373,6 +377,7 @@ capsule_metadata = { "type": ["object"], "properties": { "labels": labels, + "annotations": annotations, # use the same format as container name "name": container_name, } diff --git a/zun/api/controllers/v1/views/capsules_view.py b/zun/api/controllers/v1/views/capsules_view.py index 053c07c10..9a6f151ad 100644 --- a/zun/api/controllers/v1/views/capsules_view.py +++ b/zun/api/controllers/v1/views/capsules_view.py @@ -31,6 +31,7 @@ _basic_keys = ( 'restart_policy', 'name', 'labels', + 'annotations', 'memory', 'cpu', 'init_containers', diff --git a/zun/api/controllers/versions.py b/zun/api/controllers/versions.py index 9646fbf56..7f43f3e4e 100644 --- a/zun/api/controllers/versions.py +++ b/zun/api/controllers/versions.py @@ -70,10 +70,11 @@ REST_API_VERSION_HISTORY = """REST API Version History: * 1.35 - Support exposing container ports in capsule * 1.36 - Add 'tty' to container * 1.37 - Add 'tty' and 'stdin' to capsule + * 1.38 - Add 'annotations' to capsule """ BASE_VER = '1.1' -CURRENT_MAX_VER = '1.37' +CURRENT_MAX_VER = '1.38' class Version(object): diff --git a/zun/api/rest_api_version_history.rst b/zun/api/rest_api_version_history.rst index 8f7707e53..5f3660291 100644 --- a/zun/api/rest_api_version_history.rst +++ b/zun/api/rest_api_version_history.rst @@ -287,3 +287,9 @@ user documentation. Add 'tty' and 'stdin' to capsule. Containers in capsule can specify these two fields. + +1.38 +---- + + Add 'annotations' to capsule. + This field stores metadata of the capsule in key-value format. diff --git a/zun/tests/unit/api/base.py b/zun/tests/unit/api/base.py index 54aa879c2..154cf8cf2 100644 --- a/zun/tests/unit/api/base.py +++ b/zun/tests/unit/api/base.py @@ -28,7 +28,7 @@ from zun.tests.unit.db import base PATH_PREFIX = '/v1' -CURRENT_VERSION = "container 1.36" +CURRENT_VERSION = "container 1.38" 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 205c1161f..73c92bb2d 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.37', + 'max_version': '1.38', '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.37', + 'max_version': '1.38', 'min_version': '1.1', 'status': 'CURRENT'}]}