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

Conversation

DenisMedeirosBBD
Copy link
Contributor

This adds the new parameter healthcheck_failure_action, which maps into the podman argument --health-on-failure. As explained in the podman docs:

--health-on-failure=action
Action to take once the container transitions to an unhealthy state. The default is none.

none: Take no action.

kill: Kill the container.

restart: Restart the container. Do not combine the restart action with the --restart flag. When running inside of a systemd unit, consider using the kill or stop action instead to make use of systemd’s restart policy.

stop: Stop the container.

This argument is useful to be combined with the existing ones in the current podman_container Ansible module because it determines what should happen with the container when it becomes unhealthy.

After testing the new parameter locally, my container shows the --health-on-failure argument correctly:

[podman@bbd-rhel8 ~]$ podman inspect --format="{{.Config.CreateCommand}}" nginx
[podman container create --name nginx --hostname nginx --restart=on-failure --network nginx-network --ipc shareable --blkio-weight 100 --cpu-shares 2 --memory 524288000 --memory-swap 524288000 --healthcheck-command /etc/nginx/healthcheck.sh --healthcheck-interval 30s --healthcheck-retries 1 --healthcheck-start-period 10s --healthcheck-timeout 30s --health-on-failure restart --publish 80:80 --publish 443:443 --volume /home/podman/.podman/nginx/nginx.conf:/etc/nginx/nginx.conf:ro --volume /home/podman/.podman/nginx/conf.d/:/etc/nginx/conf.d/:ro --volume /home/podman/.podman/nginx/ssl/:/etc/nginx/ssl/:ro --volume /home/podman/.podman/nginx/ssl/:/etc/bbd/ssl/:ro --volume /home/podman/.podman/nginx/healthcheck.sh:/etc/nginx/healthcheck.sh:ro nginx:stable]

Fixes: #653

@sshnaidm
Copy link
Member

Thanks for the patch! Please fix docs issue from CI job:

ERROR: Found 1 validate-modules issue(s) which need to be resolved:
ERROR: plugins/modules/podman_container.py:0:0: doc-choices-do-not-match-spec: Argument 'healthcheck_failure_action' in argument_spec defines choices as ([]) but documentation defines choices as (['none', 'kill', 'restart', 'stop'])

@DenisMedeirosBBD
Copy link
Contributor Author

DenisMedeirosBBD commented Oct 30, 2023

Thanks for the patch! Please fix docs issue from CI job:

ERROR: Found 1 validate-modules issue(s) which need to be resolved:
ERROR: plugins/modules/podman_container.py:0:0: doc-choices-do-not-match-spec: Argument 'healthcheck_failure_action' in argument_spec defines choices as ([]) but documentation defines choices as (['none', 'kill', 'restart', 'stop'])

I hope I fixed the right location: I added the field choices to the ARGUMENTS_SPEC_CONTAINER:

https://github.com/containers/ansible-podman-collections/pull/658/files#diff-262ddb89a7e02409c9fc3537ca45add047b49678f03323ab4e3ebf1541a637c2R70

@sshnaidm
Copy link
Member

sshnaidm commented Nov 1, 2023

Awesome, thanks for contribution!

@sshnaidm sshnaidm merged commit 3c0d2cc into containers:master Nov 1, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for option --health-on-failure in containers.podman.podman_container module
2 participants