Skip to content
Merged
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
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