From 0540d7596d5233c14cd86574c7585a37103c4ff8 Mon Sep 17 00:00:00 2001 From: Denis Medeiros Date: Wed, 25 Oct 2023 20:26:27 -0400 Subject: [PATCH] Add support for health-on-failure action Signed-off-by: Denis Medeiros --- .../module_utils/podman/podman_container_lib.py | 14 ++++++++++++++ plugins/modules/podman_container.py | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/module_utils/podman/podman_container_lib.py b/plugins/module_utils/podman/podman_container_lib.py index 962ce7c7..0433619a 100644 --- a/plugins/module_utils/podman/podman_container_lib.py +++ b/plugins/module_utils/podman/podman_container_lib.py @@ -67,6 +67,8 @@ healthcheck_retries=dict(type='int'), healthcheck_start_period=dict(type='str'), healthcheck_timeout=dict(type='str'), + healthcheck_failure_action=dict(type='str', choices=[ + 'none', 'kill', 'restart', 'stop']), hooks_dir=dict(type='list', elements='str'), hostname=dict(type='str'), http_proxy=dict(type='bool'), @@ -411,6 +413,10 @@ def addparam_healthcheck_timeout(self, c): return c + ['--healthcheck-timeout', self.params['healthcheck_timeout']] + def addparam_healthcheck_failure_action(self, c): + return c + ['--health-on-failure', + self.params['healthcheck_failure_action']] + def addparam_hooks_dir(self, c): for hook_dir in self.params['hooks_dir']: c += ['--hooks-dir=%s' % hook_dir] @@ -952,6 +958,14 @@ def diffparam_healthcheck(self): after = self.params['healthcheck'] or before return self._diff_update_and_compare('healthcheck', before, after) + def diffparam_healthcheck_failure_action(self): + if 'healthcheckonfailureaction' in self.info['config']: + before = self.info['config']['healthcheckonfailureaction'] + else: + before = '' + after = self.params['healthcheck_failure_action'] or before + return self._diff_update_and_compare('healthcheckonfailureaction', before, after) + # Because of hostname is random generated, this parameter has partial idempotency only. def diffparam_hostname(self): before = self.info['config']['hostname'] diff --git a/plugins/modules/podman_container.py b/plugins/modules/podman_container.py index c02c4cf0..47492bec 100644 --- a/plugins/modules/podman_container.py +++ b/plugins/modules/podman_container.py @@ -436,6 +436,17 @@ is considered failed. Like start-period, the value can be expressed in a time format such as 1m22s. The default value is 30s type: str + healthcheck_failure_action: + description: + - The action to be taken when the container is considered unhealthy. The action must be one of + "none", "kill", "restart", or "stop". + The default policy is "none". + type: str + choices: + - 'none' + - 'kill' + - 'restart' + - 'stop' hooks_dir: description: - Each .json file in the path configures a hook for Podman containers.