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 missing parameters for podman container quadlet #847

Merged
merged 9 commits into from
Oct 6, 2024
24 changes: 12 additions & 12 deletions plugins/module_utils/podman/quadlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ class ContainerQuadlet(Quadlet):
'dns_option': 'DNSOption',
'dns_search': 'DNSSearch',
'cap_drop': 'DropCapability',
'cgroups': 'CgroupsMode',
'entrypoint': 'Entrypoint',
'env': 'Environment',
'env_file': 'EnvironmentFile',
'env_host': 'EnvironmentHost',
'etc_hosts': 'AddHost',
'command': 'Exec',
'expose': 'ExposeHostPort',
'gidmap': 'GIDMap',
'global_args': 'GlobalArgs',
'group': 'Group', # Does not exist in module parameters
'group_add': 'GroupAdd',
'healthcheck': 'HealthCmd',
'healthcheck_interval': 'HealthInterval',
'healthcheck_failure_action': 'HealthOnFailure',
Expand All @@ -105,9 +108,11 @@ class ContainerQuadlet(Quadlet):
'ip6': 'IP6',
'label': 'Label',
'log_driver': 'LogDriver',
'log_opt': 'LogOpt',
"Mask": "Mask", # add it in security_opt
'mount': 'Mount',
'network': 'Network',
'network_aliases': 'NetworkAlias',
'no_new_privileges': 'NoNewPrivileges',
'sdnotify': 'Notify',
'pids_limit': 'PidsLimit',
Expand All @@ -127,6 +132,7 @@ class ContainerQuadlet(Quadlet):
'SecurityLabelNested': 'SecurityLabelNested',
'SecurityLabelType': 'SecurityLabelType',
'shm_size': 'ShmSize',
'stop_signal': 'StopSignal',
'stop_timeout': 'StopTimeout',
'subgidname': 'SubGIDMap',
'subuidname': 'SubUIDMap',
Expand Down Expand Up @@ -216,6 +222,8 @@ def custom_prepare_params(self, params: dict) -> dict:
params["podman_args"].append(f"--cidfile {params['cidfile']}")
if params["conmon_pidfile"]:
params["podman_args"].append(f"--conmon-pidfile {params['conmon_pidfile']}")
if params['cpus']:
params["podman_args"].append(f"--cpus {params['cpus']}")
if params["cpuset_cpus"]:
params["podman_args"].append(f"--cpuset-cpus {params['cpuset_cpus']}")
if params["cpuset_mems"]:
Expand Down Expand Up @@ -247,16 +255,12 @@ def custom_prepare_params(self, params: dict) -> dict:
for i in params["device_write_iops"]:
params["podman_args"].append(f"--device-write-iops {i}")
if params["etc_hosts"]:
for host_ip in params['etc_hosts'].items():
params["podman_args"].append(f"--add-host {':'.join(host_ip)}")
params['etc_hosts'] = ["%s:%s" % (k, v) for k, v in params['etc_hosts'].items()]
if params["env_merge"]:
for k, v in params["env_merge"].items():
params["podman_args"].append(f"--env {k}={v}")
if params["gpus"]:
params["podman_args"].append(f"--gpus {params['gpus']}")
if params["group_add"]:
for group in params["group_add"]:
params["podman_args"].append(f"--group-add {group}")
if params["group_entry"]:
params["podman_args"].append(f"--group-entry {params['group_entry']}")
if params["hostuser"]:
Expand All @@ -281,8 +285,7 @@ def custom_prepare_params(self, params: dict) -> dict:
if params["label_file"]:
params["podman_args"].append(f"--label-file {params['label_file']}")
if params["log_opt"]:
for k, v in params['log_opt'].items():
params["podman_args"].append(f"--log-opt {k.replace('max_size', 'max-size')}={v}")
params["log_opt"] = ["%s=%s" % (k.replace('max_size', 'max-size'), v) for k, v in params['log_opt'].items()]
if params["mac_address"]:
params["podman_args"].append(f"--mac-address {params['mac_address']}")
if params["memory"]:
Expand All @@ -293,9 +296,6 @@ def custom_prepare_params(self, params: dict) -> dict:
params["podman_args"].append(f"--memory-swap {params['memory_swap']}")
if params["memory_swappiness"]:
params["podman_args"].append(f"--memory-swappiness {params['memory_swappiness']}")
if params["network_aliases"]:
for alias in params["network_aliases"]:
params["podman_args"].append(f"--network-alias {alias}")
if params["no_healthcheck"]:
params["podman_args"].append("--no-healthcheck")
if params["no_hosts"] is not None:
Expand All @@ -316,6 +316,8 @@ def custom_prepare_params(self, params: dict) -> dict:
params["podman_args"].append(f"--pid {params['pid']}")
if params["pid_file"]:
params["podman_args"].append(f"--pid-file {params['pid_file']}")
if params['platform']:
params["podman_args"].append(f"--platform {params['platform']}")
if params["preserve_fd"]:
for pres in params["preserve_fd"]:
params["podman_args"].append(f"--preserve-fd {pres}")
Expand Down Expand Up @@ -348,8 +350,6 @@ def custom_prepare_params(self, params: dict) -> dict:
params["podman_args"].append(f"--shm-size-systemd {params['shm_size_systemd']}")
if params["sig_proxy"]:
params["podman_args"].append(f"--sig-proxy {params['sig_proxy']}")
if params["stop_signal"]:
params["podman_args"].append(f"--stop-signal {params['stop_signal']}")
if params["systemd"]:
params["podman_args"].append(f"--systemd={str(params['systemd']).lower()}")
if params["timeout"]:
Expand Down
55 changes: 54 additions & 1 deletion tests/integration/targets/podman_container/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,18 @@
quadlet_dir: /tmp
command: sleep 1d
recreate: true
stop_signal: 9 #SIGKILL
group_add:
- admin
- users
etc_hosts:
host1: 127.0.0.1
host2: 127.0.0.1
network_aliases:
- web
- db
cpus: 0.5
platform: linux/amd64
annotation:
this: "annotation_value"
dns:
Expand All @@ -1224,8 +1233,13 @@
label:
somelabel: labelvalue
otheralbe: othervalue
log_opt:
max_size: 10mb
path: /var/log/container/mycontainer.json
tag: TestTag
volumes:
- /tmp:/data
cgroups: no-conmon
mounts:
- type=devpts,destination=/dev/pts
quadlet_options:
Expand Down Expand Up @@ -1264,15 +1278,26 @@
- "Image=alpine:3.12"
- "Exec=sleep 1d"
- "Volume=/tmp:/data"
- "CgroupsMode=no-conmon"
- "Mount=type=devpts,destination=/dev/pts"
- "WorkingDir=/bin"
- "Unmask=ALL"
- "SecurityLabelFileType=usr_t"
- "Environment=BOOL=False"
- "PublishPort=9001:8000"
- "PodmanArgs=--add-host host2:127.0.0.1"
- "AddHost=host2:127.0.0.1"
- "Label=somelabel=labelvalue"
- "WantedBy=default.target"
- "GroupAdd=admin"
- "GroupAdd=users"
- "NetworkAlias=web"
- "NetworkAlias=db"
- "StopSignal=9"
- "PodmanArgs=--cpus 0.5"
- "PodmanArgs=--platform linux/amd64"
- "LogOpt=max-size=10mb"
- "LogOpt=path=/var/log/container/mycontainer.json"
- "LogOpt=tag=TestTag"
loop_control:
label: "{{ item }}"

Expand All @@ -1293,9 +1318,18 @@
quadlet_dir: /tmp
command: sleep 1d
recreate: true
stop_signal: 9 #SIGKILL
group_add:
- admin
- users
etc_hosts:
host1: 127.0.0.1
host2: 127.0.0.1
network_aliases:
- web
- db
cpus: 0.5
platform: linux/amd64
annotation:
this: "annotation_value"
dns:
Expand All @@ -1317,8 +1351,13 @@
label:
somelabel: labelvalue
otheralbe: othervalue
log_opt:
max_size: 10mb
path: /var/log/container/mycontainer.json
tag: TestTag
volumes:
- /tmp:/data
cgroups: no-conmon
mounts:
- type=devpts,destination=/dev/pts
quadlet_options:
Expand Down Expand Up @@ -1346,9 +1385,18 @@
quadlet_dir: /tmp
command: sleep 1d
recreate: true
stop_signal: 9 #SIGKILL
group_add:
- admin
- users
etc_hosts:
host1: 127.0.0.45
host2: 127.0.0.1
network_aliases:
- web
- db
cpus: 0.5
platform: linux/amd64
annotation:
this: "annotation_value"
dns:
Expand All @@ -1370,8 +1418,13 @@
label:
somelabel: labelvalue
otheralbe: othervalue
log_opt:
max_size: 10mb
path: /var/log/container/mycontainer.json
tag: TestTag
volumes:
- /tmp:/data
cgroups: no-conmon
mounts:
- type=devpts,destination=/dev/pts
quadlet_options:
Expand Down