Add started_at attribute to container

In Virtual-kubelet, we need to implement a kubelet
driver for Zun, just the same with ACI. Since Pod
will use the sandbox container start time as the
Pod start time, for align with Pod, we need to record
container started_at time field to record this.

Ref: https://github.com/virtual-kubelet/virtual-kubelet/blob/master/providers/azure/aci.go#L744

Part of blueprint golang-client

Change-Id: Iefedcd828b1b2935892bbe46729cdac8963c1d9a
Signed-off-by: Kevin Zhao <kevin.zhao@arm.com>
This commit is contained in:
Kevin Zhao 2018-05-03 11:27:40 +08:00
parent 9d982ae1bd
commit c637a441d3
5 changed files with 40 additions and 2 deletions

View File

@ -0,0 +1,34 @@
# 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 started_at to containers
Revision ID: 271c7f45982d
Revises: cff60402dd86
Create Date: 2018-05-03 11:27:00.722445
"""
# revision identifiers, used by Alembic.
revision = '271c7f45982d'
down_revision = 'cff60402dd86'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('container',
sa.Column('started_at', sa.DateTime(),
nullable=True))

View File

@ -169,6 +169,7 @@ class Container(Base):
auto_heal = Column(Boolean, default=False)
capsule_id = Column(Integer,
ForeignKey('capsule.id', ondelete='CASCADE'))
started_at = Column(DateTime, default=timeutils.utcnow)
class VolumeMapping(Base):

View File

@ -59,7 +59,8 @@ class Container(base.ZunPersistentObject, base.ZunObject):
# Version 1.28: Add 'Dead' to ContainerStatus
# Version 1.29: Add 'Restarting' to ContainerStatus
# Version 1.30: Add capsule_id attribute
VERSION = '1.30'
# Version 1.31: Add 'started_at' attribute
VERSION = '1.31'
fields = {
'id': fields.IntegerField(),
@ -98,6 +99,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
'disk': fields.IntegerField(nullable=True),
'auto_heal': fields.BooleanField(nullable=True),
'capsule_id': fields.IntegerField(nullable=True),
'started_at': fields.DateTimeField(nullable=True),
}
@staticmethod

View File

@ -101,6 +101,7 @@ def get_test_container(**kwargs):
'disk': kwargs.get('disk', 20),
'auto_heal': kwargs.get('auto_heal', False),
'capsule_id': kwargs.get('capsule_id', 42),
'started_at': kwargs.get('started_at'),
}

View File

@ -344,7 +344,7 @@ class TestObject(test_base.TestCase, _TestObject):
# For more information on object version testing, read
# https://docs.openstack.org/zun/latest/
object_data = {
'Container': '1.30-fc17da52173f258245d424c9a5cf99c7',
'Container': '1.31-4e1f27e1326bc42c7fa7ca0681bbe883',
'VolumeMapping': '1.1-50df6202f7846a136a91444c38eba841',
'Image': '1.1-330e6205c80b99b59717e1cfc6a79935',
'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',