Skip to content

Commit

Permalink
fix(k3s): add configuration parameter for disabling cgroup mount to a…
Browse files Browse the repository at this point in the history
…void "unable to apply cgroup configuration" (#592)

relates to #591
  • Loading branch information
alexanderankin authored May 31, 2024
1 parent 111bd09 commit 8917772
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/k3s/testcontainers/k3s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 8917772

Please # to comment.