From d3cd3197c01f1ca13a006a219fa3264e229758d8 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Wed, 16 Mar 2022 00:08:45 +0000 Subject: [PATCH] container: make liveness probe independent of webserver Currently liveness and readiness was treated the same. However, their behaviour at shutdown is meant to be different. When a service is not read no new connections are made to it, and when a service is not live it can be cleaned up. By considering our service live if and only if it listens to HTTP requests we don't have the opportunity to clean up after we stop listening to new requests. Leave readiness probes as they are, and instead use a file in the filesystem to indicate when the service is live. It is created before composer is spawned and deleted once composer exits. --- containers/osbuild-composer/entrypoint.py | 8 +++++++- templates/composer.yml | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/containers/osbuild-composer/entrypoint.py b/containers/osbuild-composer/entrypoint.py index c01b577a1..83759b91c 100644 --- a/containers/osbuild-composer/entrypoint.py +++ b/containers/osbuild-composer/entrypoint.py @@ -9,6 +9,7 @@ a container. import argparse import contextlib import os +import pathlib import socket import subprocess import sys @@ -301,6 +302,10 @@ class Cli(contextlib.AbstractContextManager): res = 0 sockets = self._prepare_sockets() + liveness = pathlib.Path('/run/live') + + liveness.touch() + try: if self.args.builtin_worker: proc_worker = self._spawn_worker() @@ -324,7 +329,6 @@ class Cli(contextlib.AbstractContextManager): proc_dnf_json.terminate() proc_dnf_json.wait() - return res except KeyboardInterrupt: if proc_worker: proc_worker.terminate() @@ -343,6 +347,8 @@ class Cli(contextlib.AbstractContextManager): if proc_composer: proc_composer.kill() raise + finally: + liveness.unlink() return res diff --git a/templates/composer.yml b/templates/composer.yml index f965fc980..09ef60568 100644 --- a/templates/composer.yml +++ b/templates/composer.yml @@ -41,10 +41,10 @@ objects: name: composer livenessProbe: failureThreshold: 3 - httpGet: - path: ${LIVENESS_URI} - port: ${{COMPOSER_API_PORT}} - scheme: HTTP + exec: + command: + - cat + - /tmp/live periodSeconds: 10 successThreshold: 1 timeoutSeconds: 1