Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for health-on-failure action #658

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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']
Expand Down
11 changes: 11 additions & 0 deletions plugins/modules/podman_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down