outposts: pass outpost reference instead of PK, implement TaskResult.uid
This commit is contained in:
parent
86cfb10b9b
commit
fa504e4bf9
|
@ -19,8 +19,8 @@ class BaseController:
|
||||||
|
|
||||||
outpost: Outpost
|
outpost: Outpost
|
||||||
|
|
||||||
def __init__(self, outpost_pk: str):
|
def __init__(self, outpost: Outpost):
|
||||||
self.outpost = Outpost.objects.get(pk=outpost_pk)
|
self.outpost = outpost
|
||||||
self.logger = get_logger(
|
self.logger = get_logger(
|
||||||
controller=self.__class__.__name__, outpost=self.outpost
|
controller=self.__class__.__name__, outpost=self.outpost
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,6 +8,7 @@ from yaml import safe_dump
|
||||||
|
|
||||||
from passbook import __version__
|
from passbook import __version__
|
||||||
from passbook.outposts.controllers.base import BaseController, ControllerException
|
from passbook.outposts.controllers.base import BaseController, ControllerException
|
||||||
|
from passbook.outposts.models import Outpost
|
||||||
|
|
||||||
|
|
||||||
class DockerController(BaseController):
|
class DockerController(BaseController):
|
||||||
|
@ -19,8 +20,8 @@ class DockerController(BaseController):
|
||||||
|
|
||||||
image_base = "beryju/passbook"
|
image_base = "beryju/passbook"
|
||||||
|
|
||||||
def __init__(self, outpost_pk: str) -> None:
|
def __init__(self, outpost: Outpost) -> None:
|
||||||
super().__init__(outpost_pk)
|
super().__init__(outpost)
|
||||||
self.client = from_env()
|
self.client = from_env()
|
||||||
|
|
||||||
def _get_env(self) -> Dict[str, str]:
|
def _get_env(self) -> Dict[str, str]:
|
||||||
|
|
|
@ -10,13 +10,14 @@ from passbook.outposts.controllers.base import BaseController, ControllerExcepti
|
||||||
from passbook.outposts.controllers.k8s.deployment import DeploymentReconciler
|
from passbook.outposts.controllers.k8s.deployment import DeploymentReconciler
|
||||||
from passbook.outposts.controllers.k8s.secret import SecretReconciler
|
from passbook.outposts.controllers.k8s.secret import SecretReconciler
|
||||||
from passbook.outposts.controllers.k8s.service import ServiceReconciler
|
from passbook.outposts.controllers.k8s.service import ServiceReconciler
|
||||||
|
from passbook.outposts.models import Outpost
|
||||||
|
|
||||||
|
|
||||||
class KubernetesController(BaseController):
|
class KubernetesController(BaseController):
|
||||||
"""Manage deployment of outpost in kubernetes"""
|
"""Manage deployment of outpost in kubernetes"""
|
||||||
|
|
||||||
def __init__(self, outpost_pk: str) -> None:
|
def __init__(self, outpost: Outpost) -> None:
|
||||||
super().__init__(outpost_pk)
|
super().__init__(outpost)
|
||||||
try:
|
try:
|
||||||
load_incluster_config()
|
load_incluster_config()
|
||||||
except ConfigException:
|
except ConfigException:
|
||||||
|
|
|
@ -29,25 +29,26 @@ def outpost_controller_all():
|
||||||
for outpost in Outpost.objects.exclude(
|
for outpost in Outpost.objects.exclude(
|
||||||
deployment_type=OutpostDeploymentType.CUSTOM
|
deployment_type=OutpostDeploymentType.CUSTOM
|
||||||
):
|
):
|
||||||
outpost_controller.delay(outpost.pk.hex, outpost.deployment_type, outpost.type)
|
outpost_controller.delay(outpost.pk.hex)
|
||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
||||||
def outpost_controller(
|
def outpost_controller(self: MonitoredTask, outpost_pk: str):
|
||||||
self: MonitoredTask, outpost_pk: str, deployment_type: str, outpost_type: str
|
|
||||||
):
|
|
||||||
"""Launch controller and reconcile deployment/service/etc"""
|
"""Launch controller and reconcile deployment/service/etc"""
|
||||||
logs = []
|
logs = []
|
||||||
|
outpost: Outpost = Outpost.objects.get(pk=outpost_pk)
|
||||||
try:
|
try:
|
||||||
if outpost_type == OutpostType.PROXY:
|
if outpost.type == OutpostType.PROXY:
|
||||||
if deployment_type == OutpostDeploymentType.KUBERNETES:
|
if outpost.deployment_type == OutpostDeploymentType.KUBERNETES:
|
||||||
logs = ProxyKubernetesController(outpost_pk).run_with_logs()
|
logs = ProxyKubernetesController(outpost).run_with_logs()
|
||||||
if deployment_type == OutpostDeploymentType.DOCKER:
|
if outpost.deployment_type == OutpostDeploymentType.DOCKER:
|
||||||
logs = ProxyDockerController(outpost_pk).run_with_logs()
|
logs = ProxyDockerController(outpost).run_with_logs()
|
||||||
except ControllerException as exc:
|
except ControllerException as exc:
|
||||||
self.set_status(TaskResult(TaskResultStatus.ERROR, [str(exc)], exc))
|
self.set_status(
|
||||||
|
TaskResult(TaskResultStatus.ERROR, [str(exc)], exc, uid=outpost.name)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, logs))
|
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=outpost.name))
|
||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task()
|
@CELERY_APP.task()
|
||||||
|
|
|
@ -35,7 +35,7 @@ class DockerComposeView(LoginRequiredMixin, View):
|
||||||
)
|
)
|
||||||
manifest = ""
|
manifest = ""
|
||||||
if outpost.type == OutpostType.PROXY:
|
if outpost.type == OutpostType.PROXY:
|
||||||
controller = DockerController(outpost_pk)
|
controller = DockerController(outpost)
|
||||||
manifest = controller.get_static_deployment()
|
manifest = controller.get_static_deployment()
|
||||||
|
|
||||||
return HttpResponse(manifest, content_type="text/vnd.yaml")
|
return HttpResponse(manifest, content_type="text/vnd.yaml")
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
"""Proxy Provider Docker Contoller"""
|
"""Proxy Provider Docker Contoller"""
|
||||||
from passbook.outposts.controllers.docker import DockerController
|
from passbook.outposts.controllers.docker import DockerController
|
||||||
|
from passbook.outposts.models import Outpost
|
||||||
|
|
||||||
|
|
||||||
class ProxyDockerController(DockerController):
|
class ProxyDockerController(DockerController):
|
||||||
"""Proxy Provider Docker Contoller"""
|
"""Proxy Provider Docker Contoller"""
|
||||||
|
|
||||||
def __init__(self, outpost_pk: str):
|
def __init__(self, outpost: Outpost):
|
||||||
super().__init__(outpost_pk)
|
super().__init__(outpost)
|
||||||
self.deployment_ports = {
|
self.deployment_ports = {
|
||||||
"http": 4180,
|
"http": 4180,
|
||||||
"https": 4443,
|
"https": 4443,
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
"""Proxy Provider Kubernetes Contoller"""
|
"""Proxy Provider Kubernetes Contoller"""
|
||||||
from passbook.outposts.controllers.kubernetes import KubernetesController
|
from passbook.outposts.controllers.kubernetes import KubernetesController
|
||||||
|
from passbook.outposts.models import Outpost
|
||||||
|
|
||||||
|
|
||||||
class ProxyKubernetesController(KubernetesController):
|
class ProxyKubernetesController(KubernetesController):
|
||||||
"""Proxy Provider Kubernetes Contoller"""
|
"""Proxy Provider Kubernetes Contoller"""
|
||||||
|
|
||||||
def __init__(self, outpost_pk: str):
|
def __init__(self, outpost: Outpost):
|
||||||
super().__init__(outpost_pk)
|
super().__init__(outpost)
|
||||||
self.deployment_ports = {
|
self.deployment_ports = {
|
||||||
"http": 4180,
|
"http": 4180,
|
||||||
"https": 4443,
|
"https": 4443,
|
||||||
|
|
Reference in New Issue