Use new Podman flags for healthcheck

Signed-off-by: Robin Syl <robin@robinsyl.dev>
This commit is contained in:
Robin Syl
2023-09-23 12:04:17 +02:00
parent abb0cb1649
commit 44885b7e0c

View File

@ -1020,10 +1020,9 @@ async def container_to_args(compose, cnt, detached=True):
# If it's a string, it's equivalent to specifying CMD-SHELL # If it's a string, it's equivalent to specifying CMD-SHELL
if is_str(healthcheck_test): if is_str(healthcheck_test):
# podman does not add shell to handle command with whitespace # podman does not add shell to handle command with whitespace
podman_args.extend([ podman_args.extend(
"--healthcheck-command", ["--health-cmd", "/bin/sh -c " + cmd_quote(healthcheck_test)]
"/bin/sh -c " + cmd_quote(healthcheck_test), )
])
elif is_list(healthcheck_test): elif is_list(healthcheck_test):
healthcheck_test = healthcheck_test.copy() healthcheck_test = healthcheck_test.copy()
# If it's a list, first item is either NONE, CMD or CMD-SHELL. # If it's a list, first item is either NONE, CMD or CMD-SHELL.
@ -1032,12 +1031,12 @@ async def container_to_args(compose, cnt, detached=True):
podman_args.append("--no-healthcheck") podman_args.append("--no-healthcheck")
elif healthcheck_type == "CMD": elif healthcheck_type == "CMD":
cmd_q = "' '".join([cmd_quote(i) for i in healthcheck_test]) cmd_q = "' '".join([cmd_quote(i) for i in healthcheck_test])
podman_args.extend(["--healthcheck-command", "/bin/sh -c " + cmd_q]) podman_args.extend(["--health-cmd", "/bin/sh -c " + cmd_q])
elif healthcheck_type == "CMD-SHELL": elif healthcheck_type == "CMD-SHELL":
if len(healthcheck_test) != 1: if len(healthcheck_test) != 1:
raise ValueError("'CMD_SHELL' takes a single string after it") raise ValueError("'CMD_SHELL' takes a single string after it")
cmd_q = cmd_quote(healthcheck_test[0]) cmd_q = cmd_quote(healthcheck_test[0])
podman_args.extend(["--healthcheck-command", "/bin/sh -c " + cmd_q]) podman_args.extend(["--health-cmd", "/bin/sh -c " + cmd_q])
else: else:
raise ValueError( raise ValueError(
f"unknown healthcheck test type [{healthcheck_type}],\ f"unknown healthcheck test type [{healthcheck_type}],\
@ -1048,15 +1047,15 @@ async def container_to_args(compose, cnt, detached=True):
# interval, timeout and start_period are specified as durations. # interval, timeout and start_period are specified as durations.
if "interval" in healthcheck: if "interval" in healthcheck:
podman_args.extend(["--healthcheck-interval", healthcheck["interval"]]) podman_args.extend(["--health-interval", healthcheck["interval"]])
if "timeout" in healthcheck: if "timeout" in healthcheck:
podman_args.extend(["--healthcheck-timeout", healthcheck["timeout"]]) podman_args.extend(["--health-timeout", healthcheck["timeout"]])
if "start_period" in healthcheck: if "start_period" in healthcheck:
podman_args.extend(["--healthcheck-start-period", healthcheck["start_period"]]) podman_args.extend(["--health-start-period", healthcheck["start_period"]])
# convert other parameters to string # convert other parameters to string
if "retries" in healthcheck: if "retries" in healthcheck:
podman_args.extend(["--healthcheck-retries", str(healthcheck["retries"])]) podman_args.extend(["--health-retries", str(healthcheck["retries"])])
# handle podman extension # handle podman extension
x_podman = cnt.get("x-podman", None) x_podman = cnt.get("x-podman", None)