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.
This commit is contained in:
Tom Gundersen 2022-03-16 00:08:45 +00:00 committed by Ondřej Budai
parent 15c2044b3c
commit d3cd3197c0
2 changed files with 11 additions and 5 deletions

View file

@ -9,6 +9,7 @@ a container.
import argparse import argparse
import contextlib import contextlib
import os import os
import pathlib
import socket import socket
import subprocess import subprocess
import sys import sys
@ -301,6 +302,10 @@ class Cli(contextlib.AbstractContextManager):
res = 0 res = 0
sockets = self._prepare_sockets() sockets = self._prepare_sockets()
liveness = pathlib.Path('/run/live')
liveness.touch()
try: try:
if self.args.builtin_worker: if self.args.builtin_worker:
proc_worker = self._spawn_worker() proc_worker = self._spawn_worker()
@ -324,7 +329,6 @@ class Cli(contextlib.AbstractContextManager):
proc_dnf_json.terminate() proc_dnf_json.terminate()
proc_dnf_json.wait() proc_dnf_json.wait()
return res
except KeyboardInterrupt: except KeyboardInterrupt:
if proc_worker: if proc_worker:
proc_worker.terminate() proc_worker.terminate()
@ -343,6 +347,8 @@ class Cli(contextlib.AbstractContextManager):
if proc_composer: if proc_composer:
proc_composer.kill() proc_composer.kill()
raise raise
finally:
liveness.unlink()
return res return res

View file

@ -41,10 +41,10 @@ objects:
name: composer name: composer
livenessProbe: livenessProbe:
failureThreshold: 3 failureThreshold: 3
httpGet: exec:
path: ${LIVENESS_URI} command:
port: ${{COMPOSER_API_PORT}} - cat
scheme: HTTP - /tmp/live
periodSeconds: 10 periodSeconds: 10
successThreshold: 1 successThreshold: 1
timeoutSeconds: 1 timeoutSeconds: 1