Skip to content

Commit 8917772

Browse files
fix(k3s): add configuration parameter for disabling cgroup mount to avoid "unable to apply cgroup configuration" (#592)
relates to #591
1 parent 111bd09 commit 8917772

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/k3s/testcontainers/k3s/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
1313

14+
import logging
15+
1416
from testcontainers.core.config import testcontainers_config
1517
from testcontainers.core.container import DockerContainer
1618
from testcontainers.core.waiting_utils import wait_for_logs
@@ -37,13 +39,16 @@ class K3SContainer(DockerContainer):
3739
KUBE_SECURE_PORT = 6443
3840
RANCHER_WEBHOOK_PORT = 8443
3941

40-
def __init__(self, image="rancher/k3s:latest", **kwargs) -> None:
42+
def __init__(self, image="rancher/k3s:latest", enable_cgroup_mount=True, **kwargs) -> None:
4143
super().__init__(image, **kwargs)
4244
self.with_exposed_ports(self.KUBE_SECURE_PORT, self.RANCHER_WEBHOOK_PORT)
4345
self.with_env("K3S_URL", f"https://{self.get_container_host_ip()}:{self.KUBE_SECURE_PORT}")
4446
self.with_command("server --disable traefik --tls-san=" + self.get_container_host_ip())
4547
self.with_kwargs(privileged=True, tmpfs={"/run": "", "/var/run": ""})
46-
self.with_volume_mapping("/sys/fs/cgroup", "/sys/fs/cgroup", "rw")
48+
if enable_cgroup_mount:
49+
self.with_volume_mapping("/sys/fs/cgroup", "/sys/fs/cgroup", "rw")
50+
else:
51+
logging.warning("'enable_cgroup_mount' is experimental, see testcontainers/testcontainers-python#591)")
4752

4853
def _connect(self) -> None:
4954
wait_for_logs(self, predicate="Node controller sync successful", timeout=testcontainers_config.timeout)

0 commit comments

Comments
 (0)