outpost: fix logs for kubernetes controller
This commit is contained in:
parent
e13d348315
commit
754dbdd0e5
|
@ -33,7 +33,7 @@ class BaseController:
|
||||||
"""Call .up() but capture all log output and return it."""
|
"""Call .up() but capture all log output and return it."""
|
||||||
with capture_logs() as logs:
|
with capture_logs() as logs:
|
||||||
self.up()
|
self.up()
|
||||||
return [f"{x['controller']}: {x['event']}" for x in logs]
|
return [x["event"] for x in logs]
|
||||||
|
|
||||||
def down(self):
|
def down(self):
|
||||||
"""Handler to delete everything we've created"""
|
"""Handler to delete everything we've created"""
|
||||||
|
|
|
@ -5,6 +5,7 @@ from typing import Dict, List, Type
|
||||||
from kubernetes.client import OpenApiException
|
from kubernetes.client import OpenApiException
|
||||||
from kubernetes.config import load_incluster_config, load_kube_config
|
from kubernetes.config import load_incluster_config, load_kube_config
|
||||||
from kubernetes.config.config_exception import ConfigException
|
from kubernetes.config.config_exception import ConfigException
|
||||||
|
from structlog.testing import capture_logs
|
||||||
from yaml import dump_all
|
from yaml import dump_all
|
||||||
|
|
||||||
from passbook.outposts.controllers.base import BaseController, ControllerException
|
from passbook.outposts.controllers.base import BaseController, ControllerException
|
||||||
|
@ -43,6 +44,18 @@ class KubernetesController(BaseController):
|
||||||
except OpenApiException as exc:
|
except OpenApiException as exc:
|
||||||
raise ControllerException from 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):
|
def down(self):
|
||||||
try:
|
try:
|
||||||
for reconcile_key in self.reconcile_order:
|
for reconcile_key in self.reconcile_order:
|
||||||
|
|
|
@ -38,6 +38,7 @@ def outpost_controller(self: MonitoredTask, outpost_pk: str):
|
||||||
"""Launch controller deployment of Outpost"""
|
"""Launch controller deployment of Outpost"""
|
||||||
logs = []
|
logs = []
|
||||||
outpost: Outpost = Outpost.objects.get(pk=outpost_pk)
|
outpost: Outpost = Outpost.objects.get(pk=outpost_pk)
|
||||||
|
self.set_uid(slugify(outpost.name))
|
||||||
try:
|
try:
|
||||||
if outpost.type == OutpostType.PROXY:
|
if outpost.type == OutpostType.PROXY:
|
||||||
if outpost.deployment_type == OutpostDeploymentType.KUBERNETES:
|
if outpost.deployment_type == OutpostDeploymentType.KUBERNETES:
|
||||||
|
@ -45,15 +46,9 @@ def outpost_controller(self: MonitoredTask, outpost_pk: str):
|
||||||
if outpost.deployment_type == OutpostDeploymentType.DOCKER:
|
if outpost.deployment_type == OutpostDeploymentType.DOCKER:
|
||||||
logs = ProxyDockerController(outpost).up_with_logs()
|
logs = ProxyDockerController(outpost).up_with_logs()
|
||||||
except ControllerException as exc:
|
except ControllerException as exc:
|
||||||
self.set_status(
|
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
||||||
TaskResult(TaskResultStatus.ERROR, uid=slugify(outpost.name)).with_error(
|
|
||||||
exc
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.set_status(
|
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, logs))
|
||||||
TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=slugify(outpost.name))
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task()
|
@CELERY_APP.task()
|
||||||
|
|
Reference in New Issue