Reduce cyclotomic complexity of CreateContainerNode to fix lint
parent
a2c2a83903
commit
eab92dc455
|
@ -146,14 +146,31 @@ func CreateContainerNode(p CreateParams) error {
|
||||||
"--label", p.NodeLabel,
|
"--label", p.NodeLabel,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/
|
||||||
|
var virtualization string
|
||||||
if p.OCIBinary == Podman { // enable execing in /var
|
if p.OCIBinary == Podman { // enable execing in /var
|
||||||
// podman mounts var/lib with no-exec by default https://github.com/containers/libpod/issues/5103
|
// podman mounts var/lib with no-exec by default https://github.com/containers/libpod/issues/5103
|
||||||
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var:exec", p.Name))
|
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var:exec", p.Name))
|
||||||
|
if _, err := os.Stat("/sys/fs/cgroup/memory/memsw.limit_in_bytes"); runtime.GOOS == "linux" && os.IsNotExist(err) {
|
||||||
|
// requires CONFIG_MEMCG_SWAP_ENABLED or cgroup_enable=memory in grub
|
||||||
|
glog.Warning("Your kernel does not support swap limit capabilities or the cgroup is not mounted.")
|
||||||
|
} else {
|
||||||
|
runArgs = append(runArgs, fmt.Sprintf("--memory=%s", p.Memory))
|
||||||
|
// Disable swap by setting the value to match
|
||||||
|
runArgs = append(runArgs, fmt.Sprintf("--memory-swap=%s", p.Memory))
|
||||||
|
}
|
||||||
|
virtualization = "podman" // VIRTUALIZATION_PODMAN
|
||||||
}
|
}
|
||||||
if p.OCIBinary == Docker {
|
if p.OCIBinary == Docker {
|
||||||
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var", p.Name))
|
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var", p.Name))
|
||||||
// ignore apparmore github actions docker: https://github.com/kubernetes/minikube/issues/7624
|
// ignore apparmore github actions docker: https://github.com/kubernetes/minikube/issues/7624
|
||||||
runArgs = append(runArgs, "--security-opt", "apparmor=unconfined")
|
runArgs = append(runArgs, "--security-opt", "apparmor=unconfined")
|
||||||
|
|
||||||
|
runArgs = append(runArgs, fmt.Sprintf("--memory=%s", p.Memory))
|
||||||
|
// Disable swap by setting the value to match
|
||||||
|
runArgs = append(runArgs, fmt.Sprintf("--memory-swap=%s", p.Memory))
|
||||||
|
|
||||||
|
virtualization = "docker" // VIRTUALIZATION_DOCKER
|
||||||
}
|
}
|
||||||
|
|
||||||
cpuCfsPeriod := true
|
cpuCfsPeriod := true
|
||||||
|
@ -175,35 +192,6 @@ func CreateContainerNode(p CreateParams) error {
|
||||||
runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs))
|
runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs))
|
||||||
}
|
}
|
||||||
|
|
||||||
memcgSwap := true
|
|
||||||
if runtime.GOOS == "linux" {
|
|
||||||
if _, err := os.Stat("/sys/fs/cgroup/memory/memsw.limit_in_bytes"); os.IsNotExist(err) {
|
|
||||||
// requires CONFIG_MEMCG_SWAP_ENABLED or cgroup_enable=memory in grub
|
|
||||||
glog.Warning("Your kernel does not support swap limit capabilities or the cgroup is not mounted.")
|
|
||||||
memcgSwap = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.OCIBinary == Podman && memcgSwap { // swap is required for memory
|
|
||||||
runArgs = append(runArgs, fmt.Sprintf("--memory=%s", p.Memory))
|
|
||||||
// Disable swap by setting the value to match
|
|
||||||
runArgs = append(runArgs, fmt.Sprintf("--memory-swap=%s", p.Memory))
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.OCIBinary == Docker {
|
|
||||||
runArgs = append(runArgs, fmt.Sprintf("--memory=%s", p.Memory))
|
|
||||||
// Disable swap by setting the value to match
|
|
||||||
runArgs = append(runArgs, fmt.Sprintf("--memory-swap=%s", p.Memory))
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/
|
|
||||||
var virtualization string
|
|
||||||
if p.OCIBinary == Podman {
|
|
||||||
virtualization = "podman" // VIRTUALIZATION_PODMAN
|
|
||||||
}
|
|
||||||
if p.OCIBinary == Docker {
|
|
||||||
virtualization = "docker" // VIRTUALIZATION_DOCKER
|
|
||||||
}
|
|
||||||
runArgs = append(runArgs, "-e", fmt.Sprintf("%s=%s", "container", virtualization))
|
runArgs = append(runArgs, "-e", fmt.Sprintf("%s=%s", "container", virtualization))
|
||||||
|
|
||||||
for key, val := range p.Envs {
|
for key, val := range p.Envs {
|
||||||
|
|
Loading…
Reference in New Issue