outposts: fix Kubernetes Controller not exporting dicts, secrets not being b64 encoded
This commit is contained in:
parent
7fe9b8f0b4
commit
a8744f443c
|
@ -19,6 +19,8 @@ values =
|
||||||
|
|
||||||
[bumpversion:file:docs/installation/docker-compose.md]
|
[bumpversion:file:docs/installation/docker-compose.md]
|
||||||
|
|
||||||
|
[bumpversion:file:docs/installation/kubernetes.md]
|
||||||
|
|
||||||
[bumpversion:file:docker-compose.yml]
|
[bumpversion:file:docker-compose.yml]
|
||||||
|
|
||||||
[bumpversion:file:helm/values.yaml]
|
[bumpversion:file:helm/values.yaml]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Kubernetes deployment controller"""
|
"""Kubernetes deployment controller"""
|
||||||
|
from base64 import b64encode
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
from kubernetes.client import (
|
from kubernetes.client import (
|
||||||
|
@ -24,6 +25,11 @@ from passbook import __version__
|
||||||
from passbook.outposts.controllers.base import BaseController
|
from passbook.outposts.controllers.base import BaseController
|
||||||
|
|
||||||
|
|
||||||
|
def b64encode_str(input_string: str) -> str:
|
||||||
|
"""base64 encode string"""
|
||||||
|
return b64encode(input_string.encode()).decode()
|
||||||
|
|
||||||
|
|
||||||
class KubernetesController(BaseController):
|
class KubernetesController(BaseController):
|
||||||
"""Manage deployment of outpost in kubernetes"""
|
"""Manage deployment of outpost in kubernetes"""
|
||||||
|
|
||||||
|
@ -37,9 +43,9 @@ class KubernetesController(BaseController):
|
||||||
with StringIO() as _str:
|
with StringIO() as _str:
|
||||||
dump_all(
|
dump_all(
|
||||||
[
|
[
|
||||||
self.get_deployment_secret(),
|
self.get_deployment_secret().to_dict(),
|
||||||
self.get_deployment(),
|
self.get_deployment().to_dict(),
|
||||||
self.get_service(),
|
self.get_service().to_dict(),
|
||||||
],
|
],
|
||||||
stream=_str,
|
stream=_str,
|
||||||
default_flow_style=False,
|
default_flow_style=False,
|
||||||
|
@ -63,15 +69,18 @@ class KubernetesController(BaseController):
|
||||||
def get_deployment_secret(self) -> V1Secret:
|
def get_deployment_secret(self) -> V1Secret:
|
||||||
"""Get secret with token and passbook host"""
|
"""Get secret with token and passbook host"""
|
||||||
return V1Secret(
|
return V1Secret(
|
||||||
|
api_version="v1",
|
||||||
|
kind="secret",
|
||||||
|
type="Opaque",
|
||||||
metadata=self.get_object_meta(
|
metadata=self.get_object_meta(
|
||||||
name=f"passbook-outpost-{self.outpost.name}-api"
|
name=f"passbook-outpost-{self.outpost.name}-api"
|
||||||
),
|
),
|
||||||
data={
|
data={
|
||||||
"passbook_host": self.outpost.config.passbook_host,
|
"passbook_host": b64encode_str(self.outpost.config.passbook_host),
|
||||||
"passbook_host_insecure": str(
|
"passbook_host_insecure": b64encode_str(
|
||||||
self.outpost.config.passbook_host_insecure
|
str(self.outpost.config.passbook_host_insecure)
|
||||||
),
|
),
|
||||||
"token": self.outpost.token.token_uuid.hex,
|
"token": b64encode_str(self.outpost.token.token_uuid.hex),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -82,6 +91,8 @@ class KubernetesController(BaseController):
|
||||||
for port_name, port in self.deployment_ports.items():
|
for port_name, port in self.deployment_ports.items():
|
||||||
ports.append(V1ServicePort(name=port_name, port=port))
|
ports.append(V1ServicePort(name=port_name, port=port))
|
||||||
return V1Service(
|
return V1Service(
|
||||||
|
api_version="v1",
|
||||||
|
kind="service",
|
||||||
metadata=meta,
|
metadata=meta,
|
||||||
spec=V1ServiceSpec(ports=ports, selector=meta.labels, type="ClusterIP"),
|
spec=V1ServiceSpec(ports=ports, selector=meta.labels, type="ClusterIP"),
|
||||||
)
|
)
|
||||||
|
@ -94,6 +105,8 @@ class KubernetesController(BaseController):
|
||||||
container_ports.append(V1ContainerPort(container_port=port, name=port_name))
|
container_ports.append(V1ContainerPort(container_port=port, name=port_name))
|
||||||
meta = self.get_object_meta(name=f"passbook-outpost-{self.outpost.name}")
|
meta = self.get_object_meta(name=f"passbook-outpost-{self.outpost.name}")
|
||||||
return V1Deployment(
|
return V1Deployment(
|
||||||
|
api_version="apps/v1",
|
||||||
|
kind="deployment",
|
||||||
metadata=meta,
|
metadata=meta,
|
||||||
spec=V1DeploymentSpec(
|
spec=V1DeploymentSpec(
|
||||||
replicas=1,
|
replicas=1,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Outpost models"""
|
"""Outpost models"""
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from json import dumps, loads
|
|
||||||
from typing import Iterable, Optional
|
from typing import Iterable, Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
|
@ -84,12 +83,12 @@ class Outpost(models.Model):
|
||||||
@property
|
@property
|
||||||
def config(self) -> OutpostConfig:
|
def config(self) -> OutpostConfig:
|
||||||
"""Load config as OutpostConfig object"""
|
"""Load config as OutpostConfig object"""
|
||||||
return from_dict(OutpostConfig, loads(self._config))
|
return from_dict(OutpostConfig, self._config)
|
||||||
|
|
||||||
@config.setter
|
@config.setter
|
||||||
def config(self, value):
|
def config(self, value):
|
||||||
"""Dump config into json"""
|
"""Dump config into json"""
|
||||||
self._config = dumps(asdict(value))
|
self._config = asdict(value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def health_cache_key(self) -> str:
|
def health_cache_key(self) -> str:
|
||||||
|
|
Reference in New Issue