提交 e0913389 编写于 作者: T Thomas Stromberg

Fix docker/containerd caching, improve msgs, add tests

上级 8d6a45ec
...@@ -237,7 +237,7 @@ func beginCacheImages(g *errgroup.Group, kVersion string) { ...@@ -237,7 +237,7 @@ func beginCacheImages(g *errgroup.Group, kVersion string) {
if !viper.GetBool(cacheImages) { if !viper.GetBool(cacheImages) {
return return
} }
console.OutStyle("caching", "Caching images in the background ...") console.OutStyle("caching", "Downloading Kubernetes %s images in the background ...", kVersion)
g.Go(func() error { g.Go(func() error {
return machine.CacheImagesForBootstrapper(kVersion, viper.GetString(cmdcfg.Bootstrapper)) return machine.CacheImagesForBootstrapper(kVersion, viper.GetString(cmdcfg.Bootstrapper))
}) })
...@@ -487,7 +487,7 @@ func waitCacheImages(g *errgroup.Group) { ...@@ -487,7 +487,7 @@ func waitCacheImages(g *errgroup.Group) {
if !viper.GetBool(cacheImages) { if !viper.GetBool(cacheImages) {
return return
} }
console.OutStyle("waiting", "Waiting for image caching to complete ...") console.OutStyle("waiting", "Waiting for image downloads to complete ...")
if err := g.Wait(); err != nil { if err := g.Wait(); err != nil {
glog.Errorln("Error caching images: ", err) glog.Errorln("Error caching images: ", err)
} }
......
...@@ -313,9 +313,8 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) (string, ...@@ -313,9 +313,8 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) (string,
func (k *KubeadmBootstrapper) UpdateCluster(cfg config.KubernetesConfig) error { func (k *KubeadmBootstrapper) UpdateCluster(cfg config.KubernetesConfig) error {
if cfg.ShouldLoadCachedImages { if cfg.ShouldLoadCachedImages {
err := machine.LoadImages(k.c, constants.GetKubeadmCachedImages(cfg.KubernetesVersion), constants.ImageCacheDir) if err := machine.LoadImages(k.c, constants.GetKubeadmCachedImages(cfg.KubernetesVersion), constants.ImageCacheDir); err != nil {
if err != nil { console.Failure("Unable to load cached images: %v", err)
return errors.Wrap(err, "loading cached images")
} }
} }
r, err := cruntime.New(cruntime.Config{Type: cfg.ContainerRuntime, Socket: cfg.CRISocket}) r, err := cruntime.New(cruntime.Config{Type: cfg.ContainerRuntime, Socket: cfg.CRISocket})
......
...@@ -80,7 +80,7 @@ func (r *Containerd) Disable() error { ...@@ -80,7 +80,7 @@ func (r *Containerd) Disable() error {
// LoadImage loads an image into this runtime // LoadImage loads an image into this runtime
func (r *Containerd) LoadImage(path string) error { func (r *Containerd) LoadImage(path string) error {
glog.Infof("Loading image: %s", path) glog.Infof("Loading image: %s", path)
return r.Runner.Run(fmt.Sprintf("sudo ctr cri load %s", path)) return r.Runner.Run(fmt.Sprintf("sudo ctr images import %s", path))
} }
// KubeletOptions returns kubelet options for a containerd // KubeletOptions returns kubelet options for a containerd
......
...@@ -73,7 +73,7 @@ func (r *Docker) Disable() error { ...@@ -73,7 +73,7 @@ func (r *Docker) Disable() error {
// LoadImage loads an image into this runtime // LoadImage loads an image into this runtime
func (r *Docker) LoadImage(path string) error { func (r *Docker) LoadImage(path string) error {
glog.Infof("Loading image: %s", path) glog.Infof("Loading image: %s", path)
return r.Runner.Run(fmt.Sprintf("docker load -i %s", path)) return r.Runner.Run(fmt.Sprintf("sudo docker load -i %s", path))
} }
// KubeletOptions returns kubelet options for a runtime. // KubeletOptions returns kubelet options for a runtime.
......
...@@ -30,48 +30,47 @@ import ( ...@@ -30,48 +30,47 @@ import (
func TestStartStop(t *testing.T) { func TestStartStop(t *testing.T) {
tests := []struct { tests := []struct {
runtime string name string
args []string
}{ }{
{runtime: "docker"}, {"docker+cache", []string{"--container-runtime=docker", "--cache-images"}},
{runtime: "containerd"}, {"containerd+cache", []string{"--container-runtime=containerd", "--docker-opt containerd=/var/run/containerd/containerd.sock", "--cache-images"}},
{runtime: "crio"}, {"crio+cache", []string{"--container-runtime=crio", "--cache-images"}},
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.runtime, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
runner := NewMinikubeRunner(t) r := NewMinikubeRunner(t)
if test.runtime != "docker" && usingNoneDriver(runner) { if !strings.Contains(test.name, "docker") && usingNoneDriver(r) {
t.Skipf("skipping, can't use %s with none driver", test.runtime) t.Skipf("skipping %s - incompatible with none driver", test.name)
} }
runner.RunCommand("config set WantReportErrorPrompt false", true) r.RunCommand("config set WantReportErrorPrompt false", true)
runner.RunCommand("delete", false) r.RunCommand("delete", false)
runner.CheckStatus(state.None.String()) r.CheckStatus(state.None.String())
r.Start(test.args...)
r.CheckStatus(state.Running.String())
runner.SetRuntime(test.runtime) ip := r.RunCommand("ip", true)
runner.Start()
runner.CheckStatus(state.Running.String())
ip := runner.RunCommand("ip", true)
ip = strings.TrimRight(ip, "\n") ip = strings.TrimRight(ip, "\n")
if net.ParseIP(ip) == nil { if net.ParseIP(ip) == nil {
t.Fatalf("IP command returned an invalid address: %s", ip) t.Fatalf("IP command returned an invalid address: %s", ip)
} }
checkStop := func() error { checkStop := func() error {
runner.RunCommand("stop", true) r.RunCommand("stop", true)
return runner.CheckStatusNoFail(state.Stopped.String()) return r.CheckStatusNoFail(state.Stopped.String())
} }
if err := util.Retry(t, checkStop, 5*time.Second, 6); err != nil { if err := util.Retry(t, checkStop, 5*time.Second, 6); err != nil {
t.Fatalf("timed out while checking stopped status: %v", err) t.Fatalf("timed out while checking stopped status: %v", err)
} }
runner.Start() r.Start()
runner.CheckStatus(state.Running.String()) r.CheckStatus(state.Running.String())
runner.RunCommand("delete", true) r.RunCommand("delete", true)
runner.CheckStatus(state.None.String()) r.CheckStatus(state.None.String())
}) })
} }
} }
...@@ -202,17 +202,9 @@ func (m *MinikubeRunner) SSH(command string) (string, error) { ...@@ -202,17 +202,9 @@ func (m *MinikubeRunner) SSH(command string) (string, error) {
return string(stdout), nil return string(stdout), nil
} }
func (m *MinikubeRunner) Start() { func (m *MinikubeRunner) Start(opts ...string) {
opts := "" cmd := fmt.Sprintf("start %s %s %s --alsologtostderr --v=2", m.StartArgs, m.Args, strings.Join(opts, " "))
// TODO(tstromberg): Deprecate this in favor of making it possible for tests to define explicit flags. m.RunCommand(cmd, true)
switch r := m.Runtime; r {
case "containerd":
opts = "--container-runtime=containerd --docker-opt containerd=/var/run/containerd/containerd.sock"
case "crio":
opts = "--container-runtime=cri-o"
}
m.RunCommand(fmt.Sprintf("start %s %s %s --alsologtostderr --v=5", m.StartArgs, m.Args, opts), true)
} }
func (m *MinikubeRunner) EnsureRunning() { func (m *MinikubeRunner) EnsureRunning() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册