Skip to content

Commit

Permalink
Add unstable podman to jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
sshnaidm committed Jun 11, 2024
1 parent ac63c58 commit 5d9039f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/podman_container_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ on:
jobs:

test_podman_container_api:
name: Podman API container ${{ matrix.ansible-version }}-${{ matrix.os || 'ubuntu-22.04' }}
name: Podman API container ${{ matrix.ansible-version }}-${{ matrix.os || 'ubuntu-22.04' }}-${{ matrix.podman-version || 'unstable' }}
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
defaults:
run:
Expand All @@ -47,6 +47,13 @@ jobs:
- ubuntu-22.04
python-version:
- "3.10"
podman-version:
- unstable
include:
- os: ubuntu-22.04
ansible-version: git+https://github.com/ansible/[email protected]
python-version: "3.10"
podman-version: stable

steps:

Expand Down Expand Up @@ -112,7 +119,8 @@ jobs:
-e host=localhost \
-i localhost, \
-e ansible_connection=local \
-e setup_python=false
-e setup_python=false \
-e podman_version_ubuntu=${{ matrix.podman-version }}
TEST2RUN=podman_container_api ./ci/run_containers_tests.sh
shell: bash
2 changes: 2 additions & 0 deletions plugins/module_utils/podman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ def diff_generic(params, info_config, module_arg, cmd_arg, boolean_type=False):
else:
before = ",".join(sorted(before)) if len(before) > 1 else before[0]
return before, after


class PodmanAPI:
def __init__(self, module, module_params):
if module_params.get('podman_socket') and not HAS_REQUESTS:
Expand Down
40 changes: 33 additions & 7 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
from ansible_collections.containers.podman.plugins.module_utils.podman.common import lower_keys
from ansible_collections.containers.podman.plugins.module_utils.podman.common import generate_systemd
from ansible_collections.containers.podman.plugins.module_utils.podman.common import delete_systemd
<<<<<<< HEAD
from ansible_collections.containers.podman.plugins.module_utils.podman.common import diff_generic
from ansible_collections.containers.podman.plugins.module_utils.podman.common import createcommand
from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import create_quadlet_state
from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import ContainerQuadlet

=======
from ansible_collections.containers.podman.plugins.module_utils.podman.common import normalize_signal
from .common import PodmanAPI
>>>>>>> e7671a8 (Add option to run with podman-py API)

__metaclass__ = type

Expand Down Expand Up @@ -1189,6 +1184,20 @@ def _diff_update_and_compare(self, param_name, before, after):
return True
return False

def clean_aliases(self, params):
aliases = {}
for k, v in ARGUMENTS_SPEC_CONTAINER.items():
if 'aliases' in v:
for alias in v['aliases']:
aliases[alias] = k
return {aliases.get(k, k): v for k, v in params.items()}

def _get_create_command_annotation(self):
if ('annotations' in self.info['config']
and 'ansible.podman.collection.cmd' in self.info['config']['annotations']):
return self.clean_aliases(json.loads(self.info['config']['annotations']['ansible.podman.collection.cmd']))
return {}

def _diff_generic(self, module_arg, cmd_arg, boolean_type=False):
"""
Generic diff function for module arguments from CreateCommand
Expand All @@ -1204,6 +1213,14 @@ def _diff_generic(self, module_arg, cmd_arg, boolean_type=False):
"""
info_config = self.info["config"]
if USE_API:
cmd = self._get_create_command_annotation()
if cmd:
params = self.clean_aliases(self.params)
self.module.log("PODMAN-DEBUG: cmd_arg = %s and param arg = %s" % (cmd.get(module_arg), params.get(module_arg)))
return self._diff_update_and_compare(module_arg, cmd.get(module_arg), params.get(module_arg))
return self._diff_update_and_compare(module_arg, None, None)

before, after = diff_generic(self.params, info_config, module_arg, cmd_arg, boolean_type)
return self._diff_update_and_compare(module_arg, before, after)

Expand Down Expand Up @@ -1707,7 +1724,10 @@ def clean_volume(x):
return "/"
return x.replace("//", "/").rstrip("/")

before = createcommand('--volume', self.info['config'])
if USE_API:
before = self._get_create_command_annotation().get('volume')
else:
before = createcommand('--volume', self.info['config'])
if before == []:
before = None
after = self.params['volume']
Expand All @@ -1716,7 +1736,6 @@ def clean_volume(x):
[clean_volume(i) for i in v.split(":")[:2]]) for v in self.params['volume']]
if before is not None:
before = [":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in before]
self.module.log("PODMAN Before: %s and After: %s" % (before, after))
if before is None and after is None:
return self._diff_update_and_compare('volume', before, after)
if after is not None:
Expand Down Expand Up @@ -1920,13 +1939,20 @@ def _perform_action(self, action):
self.client.containers.remove(self.name, force=True)
elif action == 'create':
new_params.pop('detach')
if not new_params.get('annotations'):
new_params['annotations'] = {}
new_params['annotations'].update({'ansible.podman.collection.cmd': json.dumps(self.module_params)})
try:
container = self.client.containers.create(
**new_params
)
except Exception as e:
self.module.fail_json(msg=str(e))
elif action == 'run':
new_params.pop('detach')
if not new_params.get('annotations'):
new_params['annotations'] = {}
new_params['annotations'].update({'ansible.podman.collection.cmd': json.dumps(self.module_params)})
try:
container = self.client.containers.run(
**new_params
Expand Down
10 changes: 8 additions & 2 deletions plugins/modules/podman_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@
description:
- Set custom DNS search domains (Use dns_search with '' if you don't wish
to set the search domain)
type: list
elements: str
type: str
aliases:
- dns_search_domains
entrypoint:
Expand Down Expand Up @@ -1232,6 +1231,13 @@
- |
[Install]
WantedBy=default.target
- name: Run container with Podman API
containers.podman.podman_container:
name: my_api_container
image: docker.io/library/busybox:latest
state: started
podman_socket: /var/run/podman/podman.sock
"""

RETURN = r"""
Expand Down

0 comments on commit 5d9039f

Please sign in to comment.