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 the --cgroupns arg #400

Merged
merged 8 commits into from
Jan 29, 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
5 changes: 5 additions & 0 deletions python_on_whales/components/container/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def create(
cap_add: List[str] = [],
cap_drop: List[str] = [],
cgroup_parent: Optional[str] = None,
cgroupns: Optional[str] = None,
cidfile: Optional[ValidPath] = None,
cpu_period: Optional[int] = None,
cpu_quota: Optional[int] = None,
Expand Down Expand Up @@ -617,6 +618,7 @@ def create(
full_cmd.add_args_list("--cap-drop", cap_drop)

full_cmd.add_simple_arg("--cgroup-parent", cgroup_parent)
full_cmd.add_simple_arg("--cgroupns", cgroupns)
full_cmd.add_simple_arg("--cidfile", cidfile)

full_cmd.add_simple_arg("--cpu-period", cpu_period)
Expand Down Expand Up @@ -1180,6 +1182,7 @@ def run(
cap_add: List[str] = [],
cap_drop: List[str] = [],
cgroup_parent: Optional[str] = None,
cgroupns: Optional[str] = None,
cidfile: Optional[ValidPath] = None,
cpu_period: Optional[int] = None,
cpu_quota: Optional[int] = None,
Expand Down Expand Up @@ -1346,6 +1349,7 @@ def run(
`add_hosts=[("my_host_1", "192.168.30.31"), ("host2", "192.168.80.81")]`
blkio_weight: Block IO (relative weight), between 10 and 1000,
or 0 to disable (default 0)
cgroupns: Cgroup namespace mode to use, one of 'host' or 'private'.
cpu_period: Limit CPU CFS (Completely Fair Scheduler) period
cpu_quota: Limit CPU CFS (Completely Fair Scheduler) quota
cpu_rt_period: Limit CPU real-time period in microseconds
Expand Down Expand Up @@ -1449,6 +1453,7 @@ def run(
full_cmd.add_args_list("--cap-drop", cap_drop)

full_cmd.add_simple_arg("--cgroup-parent", cgroup_parent)
full_cmd.add_simple_arg("--cgroupns", cgroupns)
full_cmd.add_simple_arg("--cidfile", cidfile)

full_cmd.add_simple_arg("--cpu-period", cpu_period)
Expand Down
1 change: 1 addition & 0 deletions python_on_whales/components/container/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class ContainerHostConfig(DockerCamelModel):
capabilities: List[str]
cap_add: List[str]
cap_drop: List[str]
cgroupns_mode: str
dns: List[str]
dns_options: List[str]
dns_search: List[str]
Expand Down
7 changes: 7 additions & 0 deletions tests/python_on_whales/components/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def test_container_create_with_random_ports():
assert container.network_settings.ports["90/tcp"][0]["HostPort"] is not None


def test_container_create_with_cgroupns():
with docker.container.run(
"ubuntu", ["sleep", "infinity"], cgroupns="host", detach=True, stop_timeout=1
) as container:
assert container.host_config.cgroupns_mode == "host"


def test_fails_correctly_create_start():
python_code = """
import sys
Expand Down