Skip to content

Commit fd87423

Browse files
authored
Merge pull request #293 from CybercentreCanada/persistent-service-update
Persistent service update
2 parents ec0a520 + 59dfacc commit fd87423

File tree

3 files changed

+13
-26
lines changed

3 files changed

+13
-26
lines changed

assemblyline_core/scaler/controllers/kubernetes_ctl.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121

2222
from assemblyline_core.scaler.controllers.interface import ControllerInterface
2323

24-
25-
# How to identify the update volume as a whole, in a way that the underlying container system recognizes.
26-
CONTAINER_UPDATE_DIRECTORY = '/mount/updates/'
27-
2824
# RESERVE_MEMORY_PER_NODE = os.environ.get('RESERVE_MEMORY_PER_NODE')
2925

3026
API_TIMEOUT = 90
@@ -243,8 +239,7 @@ def core_config_mount(self, name, config_map, key, target_path):
243239
def add_profile(self, profile, scale=0):
244240
"""Tell the controller about a service profile it needs to manage."""
245241
self._create_deployment(profile.name, self._deployment_name(profile.name),
246-
profile.container_config, profile.shutdown_seconds, scale,
247-
mount_updates=profile.mount_updates)
242+
profile.container_config, profile.shutdown_seconds, scale)
248243
self._external_profiles[profile.name] = profile
249244

250245
def _loop_forever(self, function):
@@ -442,7 +437,7 @@ def memory_info(self):
442437
def _create_metadata(deployment_name: str, labels: Dict[str, str]):
443438
return V1ObjectMeta(name=deployment_name, labels=labels)
444439

445-
def _create_volumes(self, service_name, mount_updates=False, core_mounts=False):
440+
def _create_volumes(self, core_mounts=False):
446441
volumes, mounts = [], []
447442

448443
# Attach the mount that provides the config file
@@ -461,15 +456,14 @@ def _create_containers(self, service_name: str, deployment_name: str, container_
461456
memory = container_config.ram_mb
462457
min_memory = min(container_config.ram_mb_min, container_config.ram_mb)
463458
environment_variables: list[V1EnvVar] = []
464-
# If we are launching a core container, include the scalers environment
459+
# If we are launching a core container, include environment variables related to authentication for DBs
465460
if core_container:
466-
environment_variables += [V1EnvVar(name=_n, value=_v) for _n, _v in os.environ.items()]
461+
environment_variables += [V1EnvVar(name=_n, value=_v) for _n, _v in os.environ.items()
462+
if any(term in _n for term in ['ELASTIC', 'FILESTORE', 'UI_SERVER'])]
467463
# Overwrite them with configured special environment variables
468464
environment_variables += [V1EnvVar(name=_e.name, value=_e.value) for _e in container_config.environment]
469465
# Overwrite those with special hard coded variables
470466
environment_variables += [
471-
V1EnvVar(name='UPDATE_PATH', value=CONTAINER_UPDATE_DIRECTORY),
472-
V1EnvVar(name='FILE_UPDATE_DIRECTORY', value=CONTAINER_UPDATE_DIRECTORY),
473467
V1EnvVar(name='AL_SERVICE_NAME', value=service_name),
474468
V1EnvVar(name='LOG_LEVEL', value=self.log_level)
475469
]
@@ -491,7 +485,7 @@ def _create_containers(self, service_name: str, deployment_name: str, container_
491485

492486
def _create_deployment(self, service_name: str, deployment_name: str, docker_config,
493487
shutdown_seconds, scale: int, labels=None, volumes=None, mounts=None,
494-
mount_updates=True, core_mounts=False):
488+
core_mounts=False):
495489

496490
replace = False
497491
resources = self.apps_api.list_namespaced_deployment(namespace=self.namespace, _request_timeout=API_TIMEOUT)
@@ -544,7 +538,7 @@ def _create_deployment(self, service_name: str, deployment_name: str, docker_con
544538
all_labels['section'] = 'core'
545539
all_labels.update(labels or {})
546540

547-
all_volumes, all_mounts = self._create_volumes(service_name, mount_updates, core_mounts)
541+
all_volumes, all_mounts = self._create_volumes(core_mounts)
548542
all_volumes.extend(volumes or [])
549543
all_mounts.extend(mounts or [])
550544
metadata = self._create_metadata(deployment_name=deployment_name, labels=all_labels)
@@ -636,8 +630,7 @@ def stop_container(self, service_name, container_id):
636630

637631
def restart(self, service):
638632
self._create_deployment(service.name, self._deployment_name(service.name), service.container_config,
639-
service.shutdown_seconds, self.get_target(service.name),
640-
mount_updates=service.mount_updates)
633+
service.shutdown_seconds, self.get_target(service.name))
641634

642635
def get_running_container_names(self):
643636
pods = self.api.list_pod_for_all_namespaces(field_selector='status.phase==Running',
@@ -664,7 +657,7 @@ def new_events(self):
664657
return new
665658

666659
def start_stateful_container(self, service_name: str, container_name: str,
667-
spec, labels: dict[str, str], mount_updates: bool = False):
660+
spec, labels: dict[str, str]):
668661
# Setup PVC
669662
deployment_name = self._dependency_name(service_name, container_name)
670663
mounts, volumes = [], []
@@ -687,7 +680,7 @@ def start_stateful_container(self, service_name: str, container_name: str,
687680
spec.container.environment.append({'name': 'AL_INSTANCE_KEY', 'value': instance_key})
688681
self._create_deployment(service_name, deployment_name, spec.container,
689682
30, 1, labels, volumes=volumes, mounts=mounts,
690-
mount_updates=mount_updates, core_mounts=spec.run_as_core)
683+
core_mounts=spec.run_as_core)
691684

692685
# Setup a service to direct to the deployment
693686
try:

assemblyline_core/scaler/scaler_server.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ class ServiceProfile:
107107
"""
108108

109109
def __init__(self, name, container_config: DockerConfig, config_hash=0, min_instances=0, max_instances=None,
110-
growth: float = 600, shrink: Optional[float] = None, backlog=500, queue=None, shutdown_seconds=30,
111-
mount_updates=True):
110+
growth: float = 600, shrink: Optional[float] = None, backlog=500, queue=None, shutdown_seconds=30):
112111
"""
113112
:param name: Name of the service to manage
114113
:param container_config: Instructions on how to start this service
@@ -126,7 +125,6 @@ def __init__(self, name, container_config: DockerConfig, config_hash=0, min_inst
126125
self.low_duty_cycle = 0.5
127126
self.shutdown_seconds = shutdown_seconds
128127
self.config_hash = config_hash
129-
self.mount_updates = mount_updates
130128

131129
# How many instances we want, and can have
132130
self.min_instances = self._min_instances = max(0, int(min_instances))
@@ -216,7 +214,6 @@ def __deepcopy__(self, memodict=None):
216214
shrink=self.shrink_threshold,
217215
backlog=self.backlog,
218216
shutdown_seconds=self.shutdown_seconds,
219-
mount_updates=self.mount_updates
220217
)
221218
prof.desired_instances = self.desired_instances
222219
prof.running_instances = self.running_instances
@@ -343,7 +340,6 @@ def sync_services(self):
343340
name = service.name
344341
stage = self.get_service_stage(service.name)
345342
discovered_services.append(name)
346-
mount_updates = bool(service.update_config)
347343

348344
# noinspection PyBroadException
349345
try:
@@ -358,7 +354,6 @@ def sync_services(self):
358354
container_name=_n,
359355
spec=dependency,
360356
labels={'dependency_for': service.name},
361-
mount_updates=mount_updates
362357
)
363358

364359
# Move to the next service stage
@@ -403,7 +398,6 @@ def sync_services(self):
403398
queue=get_service_queue(name, self.redis),
404399
# Give service an extra 30 seconds to upload results
405400
shutdown_seconds=service.timeout + 30,
406-
mount_updates=mount_updates
407401
))
408402

409403
# Update RAM, CPU, licence requirements for running services

assemblyline_core/updater/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _get_proprietary_registry_tags(self, server, image_name, auth, verify):
4848
# Determine project/repo IDs from image name
4949
project_id, repo_id = image_name.split('/', 1)
5050
repo_id = repo_id.replace('/', "%2F")
51-
url = f"https://{server}/api/v2.0/projects/{project_id}/repositories/{repo_id}/artifacts"
51+
url = f"https://{server}/api/v2.0/projects/{project_id}/repositories/{repo_id}/artifacts?page_size=0"
5252

5353
headers = {}
5454
if auth:
@@ -129,7 +129,7 @@ def process_image(image):
129129

130130
tag_name = None
131131
if not tags:
132-
logger.warning(f"Cannot fetch latest tag for service {service_name} - {image}"
132+
logger.warning(f"Cannot fetch latest tag for service {service_name} - {image_name}"
133133
f" => [server: {server}, repo_name: {image_name}, channel: {update_channel}]")
134134
else:
135135
tag_name = f"{FRAMEWORK_VERSION}.{SYSTEM_VERSION}.0.{update_channel}0"

0 commit comments

Comments
 (0)