def upgrade():
bind = op.get_bind()
session = Session(bind=bind)
### commands auto generated by Alembic - please adjust! ###
op.add_column(
'container_states',
sa.Column('docker_id', sa.String(length=80), server_default='unknown',
nullable=False)
)
op.execute("ALTER TABLE container_states DROP CONSTRAINT container_states_pkey, "\
"ADD CONSTRAINT container_states_pkey PRIMARY KEY "\
"(pod_id, container_name, docker_id, kubes, start_time);")
# op.execute()
try:
# Try to get docker_id for current container states.
# 1. Extract all DB states without end time
# 2. Get pods information for those containers from kubes-api
# 3. Set docker_id for selected DB-states
states = session.query(ContainerState).filter(
ContainerState.end_time == None)
containers = {
(item.pod_id, item.container_name): item for item in states
}
container_ids = _get_container_ids()
for key, state in containers:
if key not in container_ids:
continue
state.docker_id = container_ids[key]
session.commit()
except Exception as err:
# We will not break the migration in case of failed update of
# some docker_id fields. Just warn about it.
logger.warning(
u'Failed to set actual docker_id for currently running containers: %s',
err)
### end Alembic commands ###
30bf03408b5e_add_docker_id_to_container_states.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录