Skip to content

Commit

Permalink
Use new Podman flags for healthcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Syl <[email protected]>
  • Loading branch information
recursiveribbons committed Mar 11, 2024
1 parent abb0cb1 commit 44885b7
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 is_str(healthcheck_test):
# podman does not add shell to handle command with whitespace
podman_args.extend([
"--healthcheck-command",
"/bin/sh -c " + cmd_quote(healthcheck_test),
])
podman_args.extend(
["--health-cmd", "/bin/sh -c " + cmd_quote(healthcheck_test)]
)
elif is_list(healthcheck_test):
healthcheck_test = healthcheck_test.copy()
# If it's a list, first item is either NONE, CMD or CMD-SHELL.
Expand All @@ -1032,12 +1031,12 @@ async def container_to_args(compose, cnt, detached=True):
podman_args.append("--no-healthcheck")
elif healthcheck_type == "CMD":
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":
if len(healthcheck_test) != 1:
raise ValueError("'CMD_SHELL' takes a single string after it")
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:
raise ValueError(
f"unknown healthcheck test type [{healthcheck_type}],\
Expand All @@ -1048,15 +1047,15 @@ async def container_to_args(compose, cnt, detached=True):

# interval, timeout and start_period are specified as durations.
if "interval" in healthcheck:
podman_args.extend(["--healthcheck-interval", healthcheck["interval"]])
podman_args.extend(["--health-interval", healthcheck["interval"]])
if "timeout" in healthcheck:
podman_args.extend(["--healthcheck-timeout", healthcheck["timeout"]])
podman_args.extend(["--health-timeout", healthcheck["timeout"]])
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
if "retries" in healthcheck:
podman_args.extend(["--healthcheck-retries", str(healthcheck["retries"])])
podman_args.extend(["--health-retries", str(healthcheck["retries"])])

# handle podman extension
x_podman = cnt.get("x-podman", None)
Expand Down

0 comments on commit 44885b7

Please sign in to comment.