1111# License for the specific language governing permissions and limitations
1212# under the License.
1313
14+ import logging
15+
1416from testcontainers .core .config import testcontainers_config
1517from testcontainers .core .container import DockerContainer
1618from 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