Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Support podman 4.0.0-
Browse files Browse the repository at this point in the history
This patch makes container healthcheck work also with versions of
podman(-remote) lower than 4.0.0. For more infor please check [1].

[1] containers/podman#11645

Resolves: rhbz#2223294
Change-Id: I4acdb425f19802424800876c11838364b623bc07
  • Loading branch information
paramite committed Sep 19, 2023
1 parent df461df commit edc2784
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions container_config_scripts/monitoring/collectd_check_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import subprocess
import sys

from pkg_resources import packaging


SOCKET = "unix:/run/podman/podman.sock"
FORMAT = ("{service: .Name, container: .Id, status: .State.Running, "
"healthy: .State.Health.Status}")
BASE_FORMAT = "{service: .Name, container: .Id, status: .State.Running, "
SKIP_LIST = ['_bootstrap', 'container-puppet-', '_db_sync',
'_ensure_', '_fix_', '_init_', '_map_', '_wait_',
'mysql_data_ownership', 'configure_cms_options']
Expand Down Expand Up @@ -55,14 +56,27 @@ def execute(cmd, workdir: str = None,


def fetch_container_health(containers):
proc = execute([shutil.which('podman-remote'),
'--url', SOCKET, 'version',
'--format', r'{{.Server.Version}}'])
o, e = proc.communicate()
try:
if packaging.version.parse(o.decode().strip()) >= packaging.version.parse("4.0.0"):
fmt = BASE_FORMAT + "healthy: .State.Health.Status}"
else:
fmt = BASE_FORMAT + "healthy: .State.Healthcheck.Status}"
except Exception:
# keep podman-4.0.0+ format in case of version decoding error
fmt = BASE_FORMAT + "healthy: .State.Health.Status}"

out = []
for cont in set(containers.split('\n')) - set(SKIP_LIST):
if not cont:
continue
proc = execute([
[shutil.which('podman-remote'),
'--url', SOCKET, 'inspect', cont],
[shutil.which('jq'), '.[] | %s' % FORMAT]
[shutil.which('jq'), '.[] | %s' % fmt]
])
o, e = proc.communicate()
if proc.returncode != 0:
Expand Down

0 comments on commit edc2784

Please sign in to comment.