diff --git a/modules/k3s/testcontainers/k3s/__init__.py b/modules/k3s/testcontainers/k3s/__init__.py index 2682df35..6e535417 100644 --- a/modules/k3s/testcontainers/k3s/__init__.py +++ b/modules/k3s/testcontainers/k3s/__init__.py @@ -11,6 +11,8 @@ # License for the specific language governing permissions and limitations # under the License. +import logging + from testcontainers.core.config import testcontainers_config from testcontainers.core.container import DockerContainer from testcontainers.core.waiting_utils import wait_for_logs @@ -37,13 +39,16 @@ class K3SContainer(DockerContainer): KUBE_SECURE_PORT = 6443 RANCHER_WEBHOOK_PORT = 8443 - def __init__(self, image="rancher/k3s:latest", **kwargs) -> None: + def __init__(self, image="rancher/k3s:latest", enable_cgroup_mount=True, **kwargs) -> None: super().__init__(image, **kwargs) self.with_exposed_ports(self.KUBE_SECURE_PORT, self.RANCHER_WEBHOOK_PORT) self.with_env("K3S_URL", f"https://{self.get_container_host_ip()}:{self.KUBE_SECURE_PORT}") self.with_command("server --disable traefik --tls-san=" + self.get_container_host_ip()) self.with_kwargs(privileged=True, tmpfs={"/run": "", "/var/run": ""}) - self.with_volume_mapping("/sys/fs/cgroup", "/sys/fs/cgroup", "rw") + if enable_cgroup_mount: + self.with_volume_mapping("/sys/fs/cgroup", "/sys/fs/cgroup", "rw") + else: + logging.warning("'enable_cgroup_mount' is experimental, see testcontainers/testcontainers-python#591)") def _connect(self) -> None: wait_for_logs(self, predicate="Node controller sync successful", timeout=testcontainers_config.timeout)