11
11
# License for the specific language governing permissions and limitations
12
12
# under the License.
13
13
14
+ import logging
15
+
14
16
from testcontainers .core .config import testcontainers_config
15
17
from testcontainers .core .container import DockerContainer
16
18
from testcontainers .core .waiting_utils import wait_for_logs
@@ -37,13 +39,16 @@ class K3SContainer(DockerContainer):
37
39
KUBE_SECURE_PORT = 6443
38
40
RANCHER_WEBHOOK_PORT = 8443
39
41
40
- def __init__ (self , image = "rancher/k3s:latest" , ** kwargs ) -> None :
42
+ def __init__ (self , image = "rancher/k3s:latest" , enable_cgroup_mount = True , ** kwargs ) -> None :
41
43
super ().__init__ (image , ** kwargs )
42
44
self .with_exposed_ports (self .KUBE_SECURE_PORT , self .RANCHER_WEBHOOK_PORT )
43
45
self .with_env ("K3S_URL" , f"https://{ self .get_container_host_ip ()} :{ self .KUBE_SECURE_PORT } " )
44
46
self .with_command ("server --disable traefik --tls-san=" + self .get_container_host_ip ())
45
47
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)" )
47
52
48
53
def _connect (self ) -> None :
49
54
wait_for_logs (self , predicate = "Node controller sync successful" , timeout = testcontainers_config .timeout )
0 commit comments