2019-12-18 23:15:48 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2019 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-03-03 00:54:05 +00:00
|
|
|
"crypto/md5"
|
2019-12-18 23:15:48 +00:00
|
|
|
"fmt"
|
2020-03-03 00:54:05 +00:00
|
|
|
"io/ioutil"
|
2019-12-18 23:15:48 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2020-02-12 06:23:37 +00:00
|
|
|
"runtime"
|
2019-12-18 23:15:48 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
|
|
|
|
"k8s.io/minikube/pkg/minikube/constants"
|
2020-03-05 02:57:12 +00:00
|
|
|
"k8s.io/minikube/pkg/minikube/download"
|
2019-12-18 23:15:48 +00:00
|
|
|
"k8s.io/minikube/pkg/minikube/localpath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDownloadOnly(t *testing.T) {
|
2020-03-21 14:53:03 +00:00
|
|
|
for _, r := range []string{"crio", "docker", "containerd"} {
|
|
|
|
t.Run(r, func(t *testing.T) {
|
|
|
|
// Stores the startup run result for later error messages
|
|
|
|
var rrr *RunResult
|
|
|
|
var err error
|
|
|
|
|
|
|
|
profile := UniqueProfileName(r)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), Minutes(30))
|
|
|
|
defer Cleanup(t, profile, cancel)
|
|
|
|
|
|
|
|
versions := []string{
|
|
|
|
constants.OldestKubernetesVersion,
|
|
|
|
constants.DefaultKubernetesVersion,
|
|
|
|
constants.NewestKubernetesVersion,
|
|
|
|
}
|
2019-12-18 23:15:48 +00:00
|
|
|
|
2020-03-21 14:53:03 +00:00
|
|
|
for _, v := range versions {
|
|
|
|
t.Run(v, func(t *testing.T) {
|
|
|
|
// Explicitly does not pass StartArgs() to test driver default
|
|
|
|
// --force to avoid uid check
|
|
|
|
args := append([]string{"start", "--download-only", "-p", profile, "--force", "--alsologtostderr", fmt.Sprintf("--kubernetes-version=%s", v), fmt.Sprintf("--container-runtime=%s", r)}, StartArgs()...)
|
|
|
|
|
|
|
|
// Preserve the initial run-result for debugging
|
|
|
|
if rrr == nil {
|
|
|
|
rrr, err = Run(t, exec.CommandContext(ctx, Target(), args...))
|
|
|
|
} else {
|
|
|
|
_, err = Run(t, exec.CommandContext(ctx, Target(), args...))
|
|
|
|
}
|
2019-12-18 23:15:48 +00:00
|
|
|
|
2020-03-21 14:53:03 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s failed: %v", args, err)
|
|
|
|
}
|
2019-12-18 23:15:48 +00:00
|
|
|
|
2020-03-21 17:22:45 +00:00
|
|
|
if download.PreloadExists(v, r) {
|
2020-03-21 14:53:03 +00:00
|
|
|
// Just make sure the tarball path exists
|
|
|
|
if _, err := os.Stat(download.TarballPath(v)); err != nil {
|
|
|
|
t.Errorf("preloaded tarball path doesn't exist: %v", err)
|
|
|
|
}
|
|
|
|
return
|
2020-03-18 20:50:24 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 14:53:03 +00:00
|
|
|
imgs, err := images.Kubeadm("", v)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("kubeadm images: %v %+v", v, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip verify for cache images if --driver=none
|
|
|
|
if !NoneDriver() {
|
|
|
|
for _, img := range imgs {
|
|
|
|
img = strings.Replace(img, ":", "_", 1) // for example kube-scheduler:v1.15.2 --> kube-scheduler_v1.15.2
|
|
|
|
fp := filepath.Join(localpath.MiniPath(), "cache", "images", img)
|
|
|
|
_, err := os.Stat(fp)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("expected image file exist at %q but got error: %v", fp, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-18 23:15:48 +00:00
|
|
|
|
2020-03-21 14:53:03 +00:00
|
|
|
// checking binaries downloaded (kubelet,kubeadm)
|
|
|
|
for _, bin := range constants.KubernetesReleaseBinaries {
|
|
|
|
fp := filepath.Join(localpath.MiniPath(), "cache", "linux", v, bin)
|
2020-02-23 04:16:01 +00:00
|
|
|
_, err := os.Stat(fp)
|
|
|
|
if err != nil {
|
2020-03-21 14:53:03 +00:00
|
|
|
t.Errorf("expected the file for binary exist at %q but got error %v", fp, err)
|
2020-02-23 04:16:01 +00:00
|
|
|
}
|
2019-12-18 23:15:48 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 14:53:03 +00:00
|
|
|
// If we are on darwin/windows, check to make sure OS specific kubectl has been downloaded
|
|
|
|
// as well for the `minikube kubectl` command
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
binary := "kubectl"
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
binary = "kubectl.exe"
|
|
|
|
}
|
|
|
|
fp := filepath.Join(localpath.MiniPath(), "cache", runtime.GOOS, v, binary)
|
|
|
|
if _, err := os.Stat(fp); err != nil {
|
2019-12-18 23:15:48 +00:00
|
|
|
t.Errorf("expected the file for binary exist at %q but got error %v", fp, err)
|
|
|
|
}
|
2020-03-21 14:53:03 +00:00
|
|
|
})
|
|
|
|
}
|
2020-02-12 06:23:37 +00:00
|
|
|
|
2020-03-21 14:53:03 +00:00
|
|
|
// This is a weird place to test profile deletion, but this test is serial, and we have a profile to delete!
|
|
|
|
t.Run("DeleteAll", func(t *testing.T) {
|
|
|
|
if !CanCleanup() {
|
|
|
|
t.Skip("skipping, as cleanup is disabled")
|
|
|
|
}
|
|
|
|
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "--all"))
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s failed: %v", rr.Args, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// Delete should always succeed, even if previously partially or fully deleted.
|
|
|
|
t.Run("DeleteAlwaysSucceeds", func(t *testing.T) {
|
|
|
|
if !CanCleanup() {
|
|
|
|
t.Skip("skipping, as cleanup is disabled")
|
|
|
|
}
|
|
|
|
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s failed: %v", rr.Args, err)
|
|
|
|
}
|
|
|
|
})
|
2019-12-18 23:15:48 +00:00
|
|
|
})
|
2020-03-21 14:53:03 +00:00
|
|
|
}
|
2019-12-18 23:15:48 +00:00
|
|
|
}
|
2020-03-21 14:53:03 +00:00
|
|
|
|
2020-03-03 00:54:05 +00:00
|
|
|
func TestDownloadOnlyDocker(t *testing.T) {
|
|
|
|
if !runningDockerDriver(StartArgs()) {
|
|
|
|
t.Skip("this test only runs with the docker driver")
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := UniqueProfileName("download-docker")
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
|
|
|
defer Cleanup(t, profile, cancel)
|
|
|
|
|
2020-03-04 21:48:21 +00:00
|
|
|
args := []string{"start", "--download-only", "-p", profile, "--force", "--alsologtostderr", "--driver=docker"}
|
2020-03-03 00:54:05 +00:00
|
|
|
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s failed: %v:\n%s", args, err, rr.Output())
|
|
|
|
}
|
|
|
|
|
2020-03-05 02:57:12 +00:00
|
|
|
// Make sure the downloaded image tarball exists
|
|
|
|
tarball := download.TarballPath(constants.DefaultKubernetesVersion)
|
2020-03-03 00:54:05 +00:00
|
|
|
contents, err := ioutil.ReadFile(tarball)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("reading tarball: %v", err)
|
|
|
|
}
|
|
|
|
// Make sure it has the correct checksum
|
|
|
|
checksum := md5.Sum(contents)
|
2020-03-05 02:57:12 +00:00
|
|
|
remoteChecksum, err := ioutil.ReadFile(download.PreloadChecksumPath(constants.DefaultKubernetesVersion))
|
2020-03-03 00:54:05 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("reading checksum file: %v", err)
|
|
|
|
}
|
|
|
|
if string(remoteChecksum) != string(checksum[:]) {
|
|
|
|
t.Errorf("checksum of %s does not match remote checksum (%s != %s)", tarball, string(remoteChecksum), string(checksum[:]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runningDockerDriver(startArgs []string) bool {
|
|
|
|
for _, s := range startArgs {
|
2020-03-04 21:48:21 +00:00
|
|
|
if s == "--driver=docker" {
|
2020-03-03 00:54:05 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|