Skip to content

Commit

Permalink
Reorganize buildroot.go by container runtime and remove unnecessary "…
Browse files Browse the repository at this point in the history
…sudo systemctl restart crio" to save time on 'minikube start'
  • Loading branch information
Priya Wadhwa committed Jan 22, 2020
1 parent 8562d1c commit 43259cc
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions pkg/provision/buildroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,25 @@ WantedBy=multi-user.target
return nil, err
}

return &provision.DockerOptions{
dockerCfg := &provision.DockerOptions{
EngineOptions: engineCfg.String(),
EngineOptionsPath: "/lib/systemd/system/docker.service",
}, nil
}

log.Info("Setting Docker configuration on the remote daemon...")

if _, err = p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s && printf %%s \"%s\" | sudo tee %s", path.Dir(dockerCfg.EngineOptionsPath), dockerCfg.EngineOptions, dockerCfg.EngineOptionsPath)); err != nil {
return nil, err
}

if err := p.Service("docker", serviceaction.Enable); err != nil {
return nil, err
}

if err := p.Service("docker", serviceaction.Restart); err != nil {
return nil, err
}
return dockerCfg, nil
}

func rootFileSystemType(p *BuildrootProvisioner) (string, error) {
Expand Down Expand Up @@ -218,7 +233,7 @@ func (p *BuildrootProvisioner) Provision(swarmOptions swarm.Options, authOptions
}

log.Debugf("setting minikube options for container-runtime")
if err := setMinikubeOptions(p); err != nil {
if err := setContainerRuntimeOptions(p); err != nil {
log.Debugf("Error setting container-runtime options during provisioning %v", err)
return err
}
Expand All @@ -239,7 +254,24 @@ func setRemoteAuthOptions(p provision.Provisioner) auth.Options {
return authOptions
}

func setMinikubeOptions(p *BuildrootProvisioner) error {
func setContainerRuntimeOptions(p *BuildrootProvisioner) error {
c, err := config.Load(p.Driver.GetMachineName())
if err != nil {
return errors.Wrap(err, "getting cluster config")
}

switch c.ContainerRuntime {
case "crio", "cri-o":
return p.setCrioOptions()
case "containerd":
return nil
default:
_, err := p.GenerateDockerOptions(engine.DefaultPort)
return err
}
}

func (p *BuildrootProvisioner) setCrioOptions() error {
// pass through --insecure-registry
var (
crioOptsTmpl = `
Expand All @@ -260,11 +292,6 @@ CRIO_MINIKUBE_OPTIONS='{{ range .EngineOptions.InsecureRegistry }}--insecure-reg
return err
}

// This is unlikely to cause issues unless the user has explicitly requested CRIO, so just log a warning.
if err := p.Service("crio", serviceaction.Restart); err != nil {
log.Warn("Unable to restart crio service. Error: %v", err)
}

return nil
}

Expand Down Expand Up @@ -314,33 +341,6 @@ func configureAuth(p *BuildrootProvisioner) error {
return err
}

config, err := config.Load(p.Driver.GetMachineName())
if err != nil {
return errors.Wrap(err, "getting cluster config")
}

dockerCfg, err := p.GenerateDockerOptions(engine.DefaultPort)
if err != nil {
return errors.Wrap(err, "generating docker options")
}

log.Info("Setting Docker configuration on the remote daemon...")

if _, err = p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s && printf %%s \"%s\" | sudo tee %s", path.Dir(dockerCfg.EngineOptionsPath), dockerCfg.EngineOptions, dockerCfg.EngineOptionsPath)); err != nil {
return err
}

if config.ContainerRuntime == "" {

if err := p.Service("docker", serviceaction.Enable); err != nil {
return err
}

if err := p.Service("docker", serviceaction.Restart); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit 43259cc

Please sign in to comment.