outposts: improve error handling for outpost service connection state
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
bd283c506d
commit
71dffb21a9
|
@ -9,6 +9,7 @@ from docker import DockerClient as UpstreamDockerClient
|
||||||
from docker.errors import DockerException, NotFound
|
from docker.errors import DockerException, NotFound
|
||||||
from docker.models.containers import Container
|
from docker.models.containers import Container
|
||||||
from docker.utils.utils import kwargs_from_env
|
from docker.utils.utils import kwargs_from_env
|
||||||
|
from paramiko.ssh_exception import SSHException
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
from yaml import safe_dump
|
from yaml import safe_dump
|
||||||
|
|
||||||
|
@ -49,10 +50,13 @@ class DockerClient(UpstreamDockerClient, BaseClient):
|
||||||
authentication_kp=connection.tls_authentication,
|
authentication_kp=connection.tls_authentication,
|
||||||
)
|
)
|
||||||
tls_config = self.tls.write()
|
tls_config = self.tls.write()
|
||||||
|
try:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
base_url=connection.url,
|
base_url=connection.url,
|
||||||
tls=tls_config,
|
tls=tls_config,
|
||||||
)
|
)
|
||||||
|
except SSHException as exc:
|
||||||
|
raise ServiceConnectionInvalid from exc
|
||||||
self.logger = get_logger()
|
self.logger = get_logger()
|
||||||
# Ensure the client actually works
|
# Ensure the client actually works
|
||||||
self.containers.list()
|
self.containers.list()
|
||||||
|
|
|
@ -77,8 +77,12 @@ def outpost_service_connection_state(connection_pk: Any):
|
||||||
cls = DockerClient
|
cls = DockerClient
|
||||||
if isinstance(connection, KubernetesServiceConnection):
|
if isinstance(connection, KubernetesServiceConnection):
|
||||||
cls = KubernetesClient
|
cls = KubernetesClient
|
||||||
|
try:
|
||||||
with cls(connection) as client:
|
with cls(connection) as client:
|
||||||
state = client.fetch_state()
|
state = client.fetch_state()
|
||||||
|
except ServiceConnectionInvalid as exc:
|
||||||
|
LOGGER.warning("Failed to get client status", exc=exc)
|
||||||
|
return
|
||||||
cache.set(connection.state_key, state, timeout=None)
|
cache.set(connection.state_key, state, timeout=None)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue