Add 'cni_metadata' to db layer

This field will be used by Zun to pass information to CNI plugin.

Change-Id: Id1beeae646cf41fa217424adf2df46fe588a25a0
Implements: blueprint support-cni
This commit is contained in:
Hongbin Lu 2019-12-30 17:54:41 +00:00
parent 2f8ad94bd5
commit be5d95ac7c
5 changed files with 60 additions and 8 deletions

View File

@ -0,0 +1,37 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""add cni_metadata to container
Revision ID: 47d79ffdc582
Revises: c2052ead4f95
Create Date: 2019-12-30 17:40:10.199545
"""
# revision identifiers, used by Alembic.
revision = '47d79ffdc582'
down_revision = 'c2052ead4f95'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def MediumText():
return sa.Text().with_variant(sa.dialects.mysql.MEDIUMTEXT(), 'mysql')
def upgrade():
op.add_column('container',
sa.Column('cni_metadata', MediumText(), nullable=True))

View File

@ -183,6 +183,7 @@ class Container(Base):
default=consts.TYPE_CONTAINER,
server_default=str(consts.TYPE_CONTAINER))
annotations = Column(MediumText())
cni_metadata = Column(MediumText())
class VolumeMapping(Base):

View File

@ -106,6 +106,7 @@ class ContainerBase(base.ZunPersistentObject, base.ZunObject):
'registry_id': fields.IntegerField(nullable=True),
'registry': fields.ObjectField("Registry", nullable=True),
'annotations': z_fields.JsonField(nullable=True),
'cni_metadata': z_fields.JsonField(nullable=True),
}
# should be redefined in subclasses
@ -239,6 +240,10 @@ class ContainerBase(base.ZunPersistentObject, base.ZunObject):
if annotations is not None:
values['annotations'] = self.fields['annotations'].to_primitive(
self, 'annotations', self.annotations)
cni_metadata = values.pop('cni_metadata', None)
if cni_metadata is not None:
values['cni_metadata'] = self.fields['cni_metadata'].to_primitive(
self, 'cni_metadata', self.cni_metadata)
values['container_type'] = self.container_type
db_container = dbapi.create_container(context, values)
self._from_db_object(self, db_container)
@ -279,6 +284,10 @@ class ContainerBase(base.ZunPersistentObject, base.ZunObject):
if annotations is not None:
updates['annotations'] = self.fields['annotations'].to_primitive(
self, 'annotations', self.annotations)
cni_metadata = updates.pop('cni_metadata', None)
if cni_metadata is not None:
updates['cni_metadata'] = self.fields['cni_metadata'].to_primitive(
self, 'cni_metadata', self.cni_metadata)
dbapi.update_container(context, self.container_type, self.uuid,
updates)
@ -411,7 +420,8 @@ class Container(ContainerBase):
# Version 1.40: Add 'tty' attributes
# Version 1.41: Add 'annotations' attributes
# Version 1.42: Remove 'meta' attribute
VERSION = '1.42'
# Version 1.43: Add 'cni_metadata' attribute
VERSION = '1.43'
container_type = consts.TYPE_CONTAINER
@ -422,7 +432,8 @@ class Capsule(ContainerBase):
# Version 1.1: Add 'tty' attributes
# Version 1.2: Add 'annotations' attributes
# Version 1.3: Remove 'meta' attribute
VERSION = '1.3'
# Version 1.4: Add 'cni_metadata' attribute
VERSION = '1.4'
container_type = consts.TYPE_CAPSULE
@ -465,7 +476,8 @@ class CapsuleContainer(ContainerBase):
# Version 1.1: Add 'tty' attributes
# Version 1.2: Add 'annotations' attributes
# Version 1.3: Remove 'meta' attribute
VERSION = '1.3'
# Version 1.4: Add 'cni_metadata' attribute
VERSION = '1.4'
container_type = consts.TYPE_CAPSULE_CONTAINER
@ -493,7 +505,8 @@ class CapsuleInitContainer(ContainerBase):
# Version 1.1: Add 'tty' attributes
# Version 1.2: Add 'annotations' attributes
# Version 1.3: Remove 'meta' attribute
VERSION = '1.3'
# Version 1.4: Add 'cni_metadata' attribute
VERSION = '1.4'
container_type = consts.TYPE_CAPSULE_INIT_CONTAINER

View File

@ -102,6 +102,7 @@ def get_test_container(**kwargs):
'container_type': kwargs.get('container_type', consts.TYPE_CONTAINER),
'capsule_id': kwargs.get('capsule_id', 33),
'annotations': kwargs.get('annotations', '{"key": "val"}'),
'cni_metadata': kwargs.get('cni_metadata', '{"key": "val"}'),
}

View File

@ -344,10 +344,10 @@ class TestObject(test_base.TestCase, _TestObject):
# For more information on object version testing, read
# https://docs.openstack.org/zun/latest/
object_data = {
'Capsule': '1.3-3ef24a2b99fa141caffa564dd3880fc5',
'CapsuleContainer': '1.3-2de3af3092ecb918e4d270c7bb2d93cb',
'CapsuleInitContainer': '1.3-2de3af3092ecb918e4d270c7bb2d93cb',
'Container': '1.42-cc5b84f4d846f2c0cf6231e808f1a4d1',
'Capsule': '1.4-66281771e65f95e6e79c604b59b7e3a3',
'CapsuleContainer': '1.4-ab82355ff19b201307c59a5b17ecc32d',
'CapsuleInitContainer': '1.4-ab82355ff19b201307c59a5b17ecc32d',
'Container': '1.43-bdd6b22fc8d6d1bb8518ed807e8e7b90',
'Cpuset': '1.0-06c4e6335683c18b87e2e54080f8c341',
'Volume': '1.0-034768f2f5c5e89acb5ee45c6d3f3403',
'VolumeMapping': '1.5-57febc66526185a75a744637e7a387c7',