Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract preloaded tarball as soon as minikube volume is created (2.5s speedup) #7490

Merged
merged 4 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os/exec"
"strconv"
"strings"
"sync"
"time"

"github.com/docker/machine/libmachine/drivers"
Expand Down Expand Up @@ -112,6 +113,28 @@ func (d *Driver) Create() error {
}
}

if err := oci.SetupContainerNode(params); err != nil {
return errors.Wrap(err, "setting up container node")
}

var waitForPreload sync.WaitGroup
waitForPreload.Add(1)
go func() {
defer waitForPreload.Done()
// If preload doesn't exist, don't bother extracting tarball to volume
if !download.PreloadExists(d.NodeConfig.KubernetesVersion, d.NodeConfig.ContainerRuntime) {
return
}
t := time.Now()
glog.Infof("Starting extracting preloaded images to volume")
// Extract preloaded images to container
if err := oci.ExtractTarballToVolume(download.TarballPath(d.NodeConfig.KubernetesVersion, d.NodeConfig.ContainerRuntime), params.Name, BaseImage); err != nil {
glog.Infof("Unable to extract preloaded tarball to volume: %v", err)
} else {
glog.Infof("duration metric: took %f seconds to extract preloaded images to volume", time.Since(t).Seconds())
}
}()

if err := oci.CreateContainerNode(params); err != nil {
return errors.Wrap(err, "create kic node")
}
Expand All @@ -120,19 +143,7 @@ func (d *Driver) Create() error {
return errors.Wrap(err, "prepare kic ssh")
}

// If preload doesn't exist, don't bother extracting tarball to volume
if !download.PreloadExists(d.NodeConfig.KubernetesVersion, d.NodeConfig.ContainerRuntime) {
return nil
}
t := time.Now()
glog.Infof("Starting extracting preloaded images to volume")
// Extract preloaded images to container
if err := oci.ExtractTarballToVolume(download.TarballPath(d.NodeConfig.KubernetesVersion, d.NodeConfig.ContainerRuntime), params.Name, BaseImage); err != nil {
glog.Infof("Unable to extract preloaded tarball to volume: %v", err)
} else {
glog.Infof("Took %f seconds to extract preloaded images to volume", time.Since(t).Seconds())
}

waitForPreload.Wait()
return nil
}

Expand Down
16 changes: 12 additions & 4 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ func DeleteContainer(ociBin string, name string) error {
return nil
}

// SetupContainerNode sets up the container node
func SetupContainerNode(p CreateParams) error {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
if p.OCIBinary != Docker {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
if err := createDockerVolume(p.Name, p.Name); err != nil {
return errors.Wrapf(err, "creating volume for %s container", p.Name)
}
glog.Infof("Successfully created a docker volume %s", p.Name)
return nil
}

// CreateContainerNode creates a new container node
func CreateContainerNode(p CreateParams) error {
runArgs := []string{
Expand Down Expand Up @@ -122,10 +134,6 @@ func CreateContainerNode(p CreateParams) error {
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var:exec", hostVarVolPath))
}
if p.OCIBinary == Docker {
if err := createDockerVolume(p.Name, p.Name); err != nil {
return errors.Wrapf(err, "creating volume for %s container", p.Name)
}
glog.Infof("Successfully created a docker volume %s", p.Name)
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var", p.Name))
// setting resource limit in privileged mode is only supported by docker
// podman error: "Error: invalid configuration, cannot set resources with rootless containers not using cgroups v2 unified mode"
Expand Down