minikube/test/integration/preload_test.go

79 lines
2.5 KiB
Go
Raw Normal View History

2021-09-13 18:58:43 +00:00
//go:build integration
/*
Copyright 2020 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2020-04-17 18:59:27 +00:00
package integration
import (
"context"
"fmt"
"os/exec"
"strings"
"testing"
)
// TestPreload verifies the preload tarballs get pulled in properly by minikube
func TestPreload(t *testing.T) {
if NoneDriver() {
t.Skipf("skipping %s - incompatible with none driver", t.Name())
}
profile := UniqueProfileName("test-preload")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
defer CleanupWithLogs(t, profile, cancel)
startArgs := []string{"start", "-p", profile, "--memory=2200", "--alsologtostderr", "--wait=true", "--preload=false"}
startArgs = append(startArgs, StartArgs()...)
2022-10-04 16:59:38 +00:00
k8sVersion := "v1.24.4"
startArgs = append(startArgs, fmt.Sprintf("--kubernetes-version=%s", k8sVersion))
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
t.Fatalf("%s failed: %v", rr.Command(), err)
}
2021-02-09 19:16:42 +00:00
// Now, pull the busybox image into minikube
2021-12-21 19:58:24 +00:00
image := "gcr.io/k8s-minikube/busybox"
cmd := exec.CommandContext(ctx, Target(), "-p", profile, "image", "pull", image)
2021-02-09 19:16:42 +00:00
rr, err = Run(t, cmd)
if err != nil {
t.Fatalf("%s failed: %v", rr.Command(), err)
}
2023-01-05 00:52:57 +00:00
// stop the cluster
rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile))
if err != nil {
t.Fatalf("%s failed: %v", rr.Command(), err)
}
// re-start the cluster and check if image is preserved
startArgs = []string{"start", "-p", profile, "--memory=2200", "--alsologtostderr", "-v=1", "--wait=true"}
startArgs = append(startArgs, StartArgs()...)
rr, err = Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
t.Fatalf("%s failed: %v", rr.Command(), err)
}
cmd = exec.CommandContext(ctx, Target(), "-p", profile, "image", "list")
2021-02-09 19:16:42 +00:00
rr, err = Run(t, cmd)
if err != nil {
t.Fatalf("%s failed: %v", rr.Command(), err)
}
if !strings.Contains(rr.Output(), image) {
2022-12-27 04:27:48 +00:00
t.Fatalf("Expected to find %s in image list output, instead got %s", image, rr.Output())
}
}