diff --git a/passbook/outposts/controllers/base.py b/passbook/outposts/controllers/base.py index ef47b5c80..65e75d4d1 100644 --- a/passbook/outposts/controllers/base.py +++ b/passbook/outposts/controllers/base.py @@ -33,7 +33,7 @@ class BaseController: """Call .up() but capture all log output and return it.""" with capture_logs() as logs: self.up() - return [f"{x['controller']}: {x['event']}" for x in logs] + return [x["event"] for x in logs] def down(self): """Handler to delete everything we've created""" diff --git a/passbook/outposts/controllers/kubernetes.py b/passbook/outposts/controllers/kubernetes.py index c2717876f..b7412f931 100644 --- a/passbook/outposts/controllers/kubernetes.py +++ b/passbook/outposts/controllers/kubernetes.py @@ -5,6 +5,7 @@ from typing import Dict, List, Type from kubernetes.client import OpenApiException from kubernetes.config import load_incluster_config, load_kube_config from kubernetes.config.config_exception import ConfigException +from structlog.testing import capture_logs from yaml import dump_all from passbook.outposts.controllers.base import BaseController, ControllerException @@ -43,6 +44,18 @@ class KubernetesController(BaseController): except OpenApiException as exc: raise ControllerException from exc + def up_with_logs(self) -> List[str]: + try: + all_logs = [] + for reconcile_key in self.reconcile_order: + with capture_logs() as logs: + reconciler = self.reconcilers[reconcile_key](self) + reconciler.up() + all_logs += [f"{reconcile_key.title()}: {x['event']}" for x in logs] + return all_logs + except OpenApiException as exc: + raise ControllerException from exc + def down(self): try: for reconcile_key in self.reconcile_order: diff --git a/passbook/outposts/tasks.py b/passbook/outposts/tasks.py index e83daf317..7e66be3d5 100644 --- a/passbook/outposts/tasks.py +++ b/passbook/outposts/tasks.py @@ -38,6 +38,7 @@ def outpost_controller(self: MonitoredTask, outpost_pk: str): """Launch controller deployment of Outpost""" logs = [] outpost: Outpost = Outpost.objects.get(pk=outpost_pk) + self.set_uid(slugify(outpost.name)) try: if outpost.type == OutpostType.PROXY: if outpost.deployment_type == OutpostDeploymentType.KUBERNETES: @@ -45,15 +46,9 @@ def outpost_controller(self: MonitoredTask, outpost_pk: str): if outpost.deployment_type == OutpostDeploymentType.DOCKER: logs = ProxyDockerController(outpost).up_with_logs() except ControllerException as exc: - self.set_status( - TaskResult(TaskResultStatus.ERROR, uid=slugify(outpost.name)).with_error( - exc - ) - ) + self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc)) else: - self.set_status( - TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=slugify(outpost.name)) - ) + self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, logs)) @CELERY_APP.task()