From a309a7026f321bf578a31e18f0c7a22dd7e7d793 Mon Sep 17 00:00:00 2001 From: Phoevos Kalemkeris Date: Thu, 29 Jun 2023 10:55:34 +0300 Subject: [PATCH] pebble: Sleep before starting KFP API server (#221) Sleep for 1.1 seconds before attempting to start the KFP API server, in order to avoid issues with Pebble when the corresponding service fails fast. This is a temporary measure until a fix for canonical/pebble#240 is provided. Refs #220 Signed-off-by: Phoevos Kalemkeris --- charms/kfp-api/src/charm.py | 7 +++++-- charms/kfp-api/tests/unit/test_operator.py | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/charms/kfp-api/src/charm.py b/charms/kfp-api/src/charm.py index 4959c2028..90728353f 100755 --- a/charms/kfp-api/src/charm.py +++ b/charms/kfp-api/src/charm.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright 2021 Canonical Ltd. +# Copyright 2023 Canonical Ltd. # See LICENSE file for licensing details. """Charm the Kubeflow Pipelines API. @@ -67,6 +67,9 @@ def __init__(self, *args): self._grcp_port = self.model.config["grpc-port"] self._http_port = self.model.config["http-port"] self._exec_command = ( + # TODO: Remove 'sleep' as soon as a fix for + # https://github.com/canonical/pebble/issues/240 is provided + "sleep 1.1 && " "/bin/apiserver " f"--config={CONFIG_DIR} " f"--sampleconfig={SAMPLE_CONFIG} " @@ -184,7 +187,7 @@ def _kfp_api_layer(self) -> Layer: self._container_name: { "override": "replace", "summary": "ML Pipeline API Server", - "command": self._exec_command, + "command": f"bash -c '{self._exec_command}'", "startup": "enabled", "environment": self.service_environment, "on-check-failure": {"kfp-api-up": "restart"}, diff --git a/charms/kfp-api/tests/unit/test_operator.py b/charms/kfp-api/tests/unit/test_operator.py index eac9cff04..cc28ffdaa 100644 --- a/charms/kfp-api/tests/unit/test_operator.py +++ b/charms/kfp-api/tests/unit/test_operator.py @@ -1,4 +1,4 @@ -# Copyright 2021 Canonical Ltd. +# Copyright 2023 Canonical Ltd. # See LICENSE file for licensing details. from contextlib import nullcontext as does_not_raise @@ -418,12 +418,17 @@ def test_install_with_all_inputs_and_pebble( assert pebble_plan assert pebble_plan.services pebble_plan_info = pebble_plan.to_dict() - assert pebble_plan_info["services"]["ml-pipeline-api-server"]["command"] == ( + pebble_exec_command = pebble_plan_info["services"]["ml-pipeline-api-server"]["command"] + exec_command = ( + # TODO: Remove 'sleep' as soon as a fix for + # https://github.com/canonical/pebble/issues/240 is provided + "sleep 1.1 && " "/bin/apiserver " "--config=/config " "--sampleconfig=/config/sample_config.json " "-logtostderr=true " ) + assert pebble_exec_command == f"bash -c '{exec_command}'" test_env = pebble_plan_info["services"]["ml-pipeline-api-server"]["environment"] # there should be 1 environment variable assert 1 == len(test_env)