Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-130517 / 24.10 / Make checking image updates configurable again #14175

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Add flag to see if image update is requried

Revision ID: 4b0b7ba46e63
Revises: 81b8bae8fb11
Create Date: 2024-08-09 14:35:35.379137+00:00

"""
from alembic import op
import sqlalchemy as sa


revision = '4b0b7ba46e63'
down_revision = '81b8bae8fb11'
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table('services_docker', schema=None) as batch_op:
batch_op.add_column(sa.Column('enable_image_updates', sa.Boolean(), nullable=False, server_default='1'))


def downgrade():
pass
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ async def periodic_check(self):

await (await self.middleware.call('catalog.sync')).wait()

await self.middleware.call('app.image.op.check_update')
# TODO: Add app upgrade alerts and account for update image check
docker_config = await self.middleware.call('docker.config')
if docker_config['enable_image_updates']:
self.middleware.create_task(self.middleware.call('app.image.op.check_update'))
# TODO: Add app upgrade alerts


async def _event_system_ready(middleware, event_type, args):
Expand Down
22 changes: 15 additions & 7 deletions src/middlewared/middlewared/plugins/docker/update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import middlewared.sqlalchemy as sa

from middlewared.schema import accepts, Dict, Int, Patch, Str
from middlewared.schema import accepts, Bool, Dict, Int, Patch, Str
from middlewared.service import CallError, ConfigService, job, private, returns

from .state_utils import Status
Expand All @@ -12,6 +12,7 @@ class DockerModel(sa.Model):

id = sa.Column(sa.Integer(), primary_key=True)
pool = sa.Column(sa.String(255), default=None, nullable=True)
enable_image_updates = sa.Column(sa.Boolean(), default=True)


class DockerService(ConfigService):
Expand All @@ -24,6 +25,7 @@ class Config:

ENTRY = Dict(
'docker_entry',
Bool('enable_image_updates', required=True),
Int('id', required=True),
Str('dataset', required=True),
Str('pool', required=True, null=True),
Expand Down Expand Up @@ -54,16 +56,22 @@ async def do_update(self, job, data):
config.update(data)

if old_config != config:
try:
await self.middleware.call('service.stop', 'docker')
except Exception as e:
raise CallError(f'Failed to stop docker service: {e}')
if config['pool'] != old_config['pool']:
job.set_progress(20, 'Stopping Docker service')
try:
await self.middleware.call('service.stop', 'docker')
except Exception as e:
raise CallError(f'Failed to stop docker service: {e}')

await self.middleware.call('docker.state.set_status', Status.UNCONFIGURED.value)
await self.middleware.call('docker.state.set_status', Status.UNCONFIGURED.value)

await self.middleware.call('datastore.update', self._config.datastore, old_config['id'], config)
await self.middleware.call('docker.setup.status_change')

if config['pool'] != old_config['pool']:
job.set_progress(60, 'Applying requested configuration')
await self.middleware.call('docker.setup.status_change')

job.set_progress(100, 'Requested configuration applied')
return await self.config()

@accepts(roles=['DOCKER_READ'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ async def stop(self):
async def after_start(self):
await self.middleware.call('docker.state.set_status', Status.RUNNING.value)
await self.middleware.call('catalog.sync')
if (await self.middleware.call('docker.config'))['enable_image_updates']:
self.middleware.create_task(self.middleware.call('app.image.op.check_update'))

async def before_stop(self):
await self.middleware.call('docker.state.set_status', Status.STOPPING.value)
Expand Down
Loading