Add --force-systemd flag to force container runtime to use systemd

pull/7815/head
Priya Wadhwa 2020-04-22 14:10:16 -07:00
parent 3ae85a1f62
commit ae388d0edb
5 changed files with 37 additions and 0 deletions

View File

@ -98,6 +98,7 @@ const (
nodes = "nodes"
preload = "preload"
deleteOnFailure = "delete-on-failure"
forceSystemd = "force-systemd"
)
// initMinikubeFlags includes commandline flags for minikube.
@ -135,6 +136,7 @@ func initMinikubeFlags() {
startCmd.Flags().IntP(nodes, "n", 1, "The number of nodes to spin up. Defaults to 1.")
startCmd.Flags().Bool(preload, true, "If set, download tarball of preloaded images if available to improve start time. Defaults to true.")
startCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again. Defaults to false.")
startCmd.Flags().Bool(forceSystemd, false, "If set, force the container runtime to use sytemd as cgroup manager. Currently avaiable for docker and crio. Defaults to false.")
}
// initKubernetesFlags inits the commandline flags for kubernetes related options

View File

@ -429,3 +429,8 @@ func addRepoTagToImageName(imgName string) string {
} // else it already has repo name dont add anything
return imgName
}
// TODO: Implement for containerd
func (r *Containerd) ForceSystemd() error {
return nil
}

View File

@ -229,3 +229,8 @@ func (r *CRIO) Preload(cfg config.KubernetesConfig) error {
}
return fmt.Errorf("not yet implemented for %s", r.Name())
}
// ForceSystemd does nothing for crio since it already uses systemd as cgroup manager
func (r *CRIO) ForceSystemd() error {
return nil
}

View File

@ -104,6 +104,8 @@ type Manager interface {
SystemLogCmd(int) string
// Preload preloads the container runtime with k8s images
Preload(config.KubernetesConfig) error
// ForceSystemd forces the container runtime to use systemd as cgroup manager
ForceSystemd() error
}
// Config is runtime configuration

View File

@ -25,6 +25,7 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/command"
@ -110,6 +111,10 @@ func (r *Docker) Enable(disOthers bool) error {
}
}
if err := r.ForceSystemd(); err != nil {
return errors.Wrap(err, "forcing systemd")
}
return r.Init.Start("docker")
}
@ -274,6 +279,24 @@ func (r *Docker) SystemLogCmd(len int) string {
return fmt.Sprintf("sudo journalctl -u docker -n %d", len)
}
// ForceSystemd forces the docker daemon to use systemd as cgroup manager
func (r *Docker) ForceSystemd() error {
if !viper.GetBool("force-systemd") {
return nil
}
daemonConfig := `{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
`
ma := assets.NewMemoryAsset([]byte(daemonConfig), "/etc/docker", "daemon.json", "0644")
return r.Runner.Copy(ma)
}
// Preload preloads docker with k8s images:
// 1. Copy over the preloaded tarball into the VM
// 2. Extract the preloaded tarball to the correct directory