Skip to content

Commit

Permalink
Merge pull request #299 from CybercentreCanada/persistent-service-update
Browse files Browse the repository at this point in the history
Persistent service update
  • Loading branch information
cccs-rs committed Sep 20, 2021
2 parents bd00c2f + 6754d66 commit be0c93d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assemblyline_core/updater/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _get_proprietary_registry_tags(self, server, image_name, auth, verify):
resp = requests.get(url, headers=headers, verify=verify)

if resp.ok:
return [tag['name'] for image in resp.json() for tag in image['tags']]
return [tag['name'] for image in resp.json() if image['tags'] for tag in image['tags']]
return []


Expand Down
7 changes: 7 additions & 0 deletions assemblyline_core/updater/run_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
V1ConfigMapVolumeSource, V1Secret, V1LocalObjectReference
from kubernetes import client, config
from kubernetes.client.rest import ApiException
from assemblyline.odm.messages.changes import Operation

from assemblyline.odm.models.service import DockerConfig
from assemblyline.remote.datatypes.events import EventSender
from assemblyline.remote.datatypes.hash import Hash
from assemblyline_core.scaler.controllers.kubernetes_ctl import create_docker_auth_config
from assemblyline_core.server_base import CoreBase
Expand Down Expand Up @@ -370,6 +372,7 @@ def __init__(self, redis_persist=None, redis=None, logger=None, datastore=None):

self.container_update: Hash[dict[str, Any]] = Hash('container-update', self.redis_persist)
self.latest_service_tags: Hash[dict[str, str]] = Hash('service-tags', self.redis_persist)
self.service_events = EventSender('changes.services', host=self.redis)

# Prepare a single threaded scheduler
self.scheduler = sched.scheduler()
Expand Down Expand Up @@ -431,6 +434,10 @@ def container_updates(self):
operations = [(self.datastore.service_delta.UPDATE_SET, 'version', latest_tag)]
if self.datastore.service_delta.update(service_name, operations):
# Update completed, cleanup
self.service_events.send(service_name, {
'operation': Operation.Modified,
'name': service_name
})
self.log.info(f"Service {service_name} update successful!")
else:
self.log.error(f"Service {service_name} has failed to update because it cannot set "
Expand Down

0 comments on commit be0c93d

Please sign in to comment.