Merge branch 'master' of github.com:kubernetes/minikube into cluster-name

pull/7219/head
Sharif Elgamal 2020-03-25 15:43:12 -07:00
commit dc7bdecda4
24 changed files with 178 additions and 52 deletions

View File

@ -123,6 +123,7 @@ const (
hostOnlyNicType = "host-only-nic-type"
natNicType = "nat-nic-type"
nodes = "nodes"
preload = "preload"
)
var (
@ -175,11 +176,12 @@ func initMinikubeFlags() {
startCmd.Flags().Bool(autoUpdate, true, "If set, automatically updates drivers to the latest version. Defaults to true.")
startCmd.Flags().Bool(installAddons, true, "If set, install addons. Defaults to true.")
startCmd.Flags().IntP(nodes, "n", 1, "The number of nodes to spin up. Defaults to 1.")
startCmd.Flags().Bool(preload, true, "If set, download tarball of preloaded images if available to improve start time. Defaults to true.")
}
// initKubernetesFlags inits the commandline flags for kubernetes related options
func initKubernetesFlags() {
startCmd.Flags().String(kubernetesVersion, "", "The kubernetes version that the minikube VM will use (ex: v1.2.3)")
startCmd.Flags().String(kubernetesVersion, "", fmt.Sprintf("The kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for %s, 'latest' for %s). Defaults to 'stable'.", constants.DefaultKubernetesVersion, constants.NewestKubernetesVersion))
startCmd.Flags().Var(&config.ExtraOptions, "extra-config",
`A set of key=value pairs that describe configuration that may be passed to different components.
The key should be '.' separated, and the first part before the dot is the component to apply the configuration to.
@ -198,6 +200,7 @@ func initDriverFlags() {
startCmd.Flags().String("driver", "", fmt.Sprintf("Driver is one of: %v (defaults to auto-detect)", driver.DisplaySupportedDrivers()))
startCmd.Flags().String("vm-driver", "", "DEPRECATED, use `driver` instead.")
startCmd.Flags().Bool(disableDriverMounts, false, "Disables the filesystem mounts provided by the hypervisors")
startCmd.Flags().Bool("vm", false, "Filter to use only VM Drivers")
// kvm2
startCmd.Flags().String(kvmNetwork, "default", "The KVM network name. (kvm2 driver only)")
@ -480,10 +483,10 @@ func selectDriver(existing *config.ClusterConfig) registry.DriverState {
if vmd := viper.GetString("vm-driver"); vmd != "" {
// Output a warning
warning := `Both driver={{.driver}} and vm-driver={{.vmd}} have been set.
Since vm-driver is deprecated, minikube will default to driver={{.driver}}.
If vm-driver is set in the global config, please run "minikube config unset vm-driver" to resolve this warning.
If vm-driver is set in the global config, please run "minikube config unset vm-driver" to resolve this warning.
`
out.T(out.Warning, warning, out.V{"driver": d, "vmd": vmd})
}
@ -505,7 +508,7 @@ func selectDriver(existing *config.ClusterConfig) registry.DriverState {
return ds
}
pick, alts := driver.Suggest(driver.Choices())
pick, alts := driver.Suggest(driver.Choices(viper.GetBool("vm")))
if pick.Name == "" {
exit.WithCodeT(exit.Config, "Unable to determine a default driver to use. Try specifying --driver, or see https://minikube.sigs.k8s.io/docs/start/")
}
@ -1065,13 +1068,15 @@ func autoSetDriverOptions(cmd *cobra.Command, drvName string) (err error) {
func getKubernetesVersion(old *config.ClusterConfig) string {
paramVersion := viper.GetString(kubernetesVersion)
if paramVersion == "" { // if the user did not specify any version then ...
if old != nil { // .. use the old version from config (if any)
paramVersion = old.KubernetesConfig.KubernetesVersion
}
if paramVersion == "" { // .. otherwise use the default version
paramVersion = constants.DefaultKubernetesVersion
}
// try to load the old version first if the user didn't specify anything
if paramVersion == "" && old != nil {
paramVersion = old.KubernetesConfig.KubernetesVersion
}
if paramVersion == "" || strings.EqualFold(paramVersion, "stable") {
paramVersion = constants.DefaultKubernetesVersion
} else if strings.EqualFold(paramVersion, "latest") {
paramVersion = constants.NewestKubernetesVersion
}
nvs, err := semver.Make(strings.TrimPrefix(paramVersion, version.VersionPrefix))

View File

@ -26,7 +26,7 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
)
func TestGetKuberneterVersion(t *testing.T) {
func TestGetKubernetesVersion(t *testing.T) {
var tests = []struct {
description string
expectedVersion string
@ -55,6 +55,16 @@ func TestGetKuberneterVersion(t *testing.T) {
paramVersion: "v1.16.0",
cfg: &cfg.ClusterConfig{KubernetesConfig: cfg.KubernetesConfig{KubernetesVersion: "v1.15.0"}},
},
{
description: "kubernetes-version given as 'stable', no config",
expectedVersion: constants.DefaultKubernetesVersion,
paramVersion: "stable",
},
{
description: "kubernetes-version given as 'latest', no config",
expectedVersion: constants.NewestKubernetesVersion,
paramVersion: "latest",
},
}
for _, test := range tests {

2
go.sum
View File

@ -421,8 +421,6 @@ github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8=
github.com/johanneswuerbach/nfsexports v0.0.0-20181204082207-1aa528dcb345 h1:XP1VL9iOZu4yz/rq8zj+yvB23XEY5erXRzp8JYmkWu0=
github.com/johanneswuerbach/nfsexports v0.0.0-20181204082207-1aa528dcb345/go.mod h1:+c1/kUpg2zlkoWqTOvzDs36Wpbm3Gd1nlmtXAEB0WGU=
github.com/johanneswuerbach/nfsexports v0.0.0-20200318065542-c48c3734757f h1:tL0xH80QVHQOde6Qqdohv6PewABH8l8N9pywZtuojJ0=
github.com/johanneswuerbach/nfsexports v0.0.0-20200318065542-c48c3734757f/go.mod h1:+c1/kUpg2zlkoWqTOvzDs36Wpbm3Gd1nlmtXAEB0WGU=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=

View File

@ -34,6 +34,7 @@ import (
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/storageclass"
"k8s.io/minikube/pkg/util/retry"
)
// defaultStorageClassProvisioner is the name of the default storage class provisioner
@ -211,13 +212,17 @@ func enableOrDisableAddonInternal(cc *config.ClusterConfig, addon *assets.Addon,
}
command := kubectlCommand(cc, deployFiles, enable)
glog.Infof("Running: %v", command)
rr, err := cmd.RunCmd(command)
if err != nil {
return errors.Wrapf(err, "addon apply")
// Retry, because sometimes we race against an apiserver restart
apply := func() error {
_, err := cmd.RunCmd(command)
if err != nil {
glog.Warningf("apply failed, will retry: %v", err)
}
return err
}
glog.Infof("output:\n%s", rr.Output())
return nil
return retry.Expo(apply, 1*time.Second, time.Second*30)
}
// enableOrDisableStorageClasses enables or disables storage classes

View File

@ -121,6 +121,10 @@ func (d *Driver) Create() error {
return errors.Wrap(err, "prepare kic ssh")
}
// If preload doesn't exist, don't both 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

View File

@ -120,7 +120,10 @@ func (f *FileAsset) GetLength() (flen int) {
// GetModTime returns modification time of the file
func (f *FileAsset) GetModTime() (time.Time, error) {
fi, err := os.Stat(f.AssetName)
return fi.ModTime(), err
if err != nil {
return time.Time{}, err
}
return fi.ModTime(), nil
}
// Read reads the asset

View File

@ -61,8 +61,8 @@ func extraKubeletOpts(mc config.ClusterConfig, nc config.Node, r cruntime.Manage
if _, ok := extraOpts["node-ip"]; !ok {
extraOpts["node-ip"] = cp.IP
}
nodeName := KubeNodeName(mc, nc)
if nodeName != "" {
if _, ok := extraOpts["hostname-override"]; !ok {
nodeName := KubeNodeName(mc, nc)
extraOpts["hostname-override"] = nodeName
}

View File

@ -524,17 +524,22 @@ func (k *Bootstrapper) UpdateCluster(cfg config.ClusterConfig) error {
return errors.Wrap(err, "kubeadm images")
}
if cfg.KubernetesConfig.ShouldLoadCachedImages {
if err := machine.LoadImages(&cfg, k.c, images, constants.ImageCacheDir); err != nil {
out.FailureT("Unable to load cached images: {{.error}}", out.V{"error": err})
}
}
r, err := cruntime.New(cruntime.Config{Type: cfg.KubernetesConfig.ContainerRuntime,
Runner: k.c, Socket: cfg.KubernetesConfig.CRISocket})
if err != nil {
return errors.Wrap(err, "runtime")
}
if err := r.Preload(cfg.KubernetesConfig); err != nil {
return errors.Wrap(err, "preloading")
}
if cfg.KubernetesConfig.ShouldLoadCachedImages {
if err := machine.LoadImages(&cfg, k.c, images, constants.ImageCacheDir); err != nil {
out.FailureT("Unable to load cached images: {{.error}}", out.V{"error": err})
}
}
for _, n := range cfg.Nodes {
err := k.UpdateNode(cfg, n, r)
if err != nil {

View File

@ -30,6 +30,7 @@ import (
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/out"
)
@ -313,5 +314,8 @@ func (r *Containerd) SystemLogCmd(len int) string {
// Preload preloads the container runtime with k8s images
func (r *Containerd) Preload(cfg config.KubernetesConfig) error {
if !download.PreloadExists(cfg.KubernetesVersion, cfg.ContainerRuntime) {
return nil
}
return fmt.Errorf("not yet implemented for %s", r.Name())
}

View File

@ -26,6 +26,7 @@ import (
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/out"
)
@ -230,5 +231,8 @@ func (r *CRIO) SystemLogCmd(len int) string {
// Preload preloads the container runtime with k8s images
func (r *CRIO) Preload(cfg config.KubernetesConfig) error {
if !download.PreloadExists(cfg.KubernetesVersion, cfg.ContainerRuntime) {
return nil
}
return fmt.Errorf("not yet implemented for %s", r.Name())
}

View File

@ -290,6 +290,9 @@ func (r *Docker) SystemLogCmd(len int) string {
// 2. Extract the preloaded tarball to the correct directory
// 3. Remove the tarball within the VM
func (r *Docker) Preload(cfg config.KubernetesConfig) error {
if !download.PreloadExists(cfg.KubernetesVersion, cfg.ContainerRuntime) {
return nil
}
k8sVersion := cfg.KubernetesVersion
// If images already exist, return

View File

@ -23,7 +23,7 @@ import (
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"cloud.google.com/go/storage"
"google.golang.org/api/option"
@ -31,6 +31,7 @@ import (
"github.com/golang/glog"
"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
)
@ -59,14 +60,14 @@ func targetDir() string {
return localpath.MakeMiniPath("cache", "preloaded-tarball")
}
// PreloadChecksumPath returns path to checksum file
// PreloadChecksumPath returns the local path to the cached checksum file
func PreloadChecksumPath(k8sVersion string) string {
return path.Join(targetDir(), checksumName(k8sVersion))
return filepath.Join(targetDir(), checksumName(k8sVersion))
}
// TarballPath returns the path to the preloaded tarball
// TarballPath returns the local path to the cached preload tarball
func TarballPath(k8sVersion string) string {
return path.Join(targetDir(), TarballName(k8sVersion))
return filepath.Join(targetDir(), TarballName(k8sVersion))
}
// remoteTarballURL returns the URL for the remote tarball in GCS
@ -76,6 +77,13 @@ func remoteTarballURL(k8sVersion string) string {
// PreloadExists returns true if there is a preloaded tarball that can be used
func PreloadExists(k8sVersion, containerRuntime string) bool {
if !viper.GetBool("preload") {
return false
}
// See https://github.com/kubernetes/minikube/issues/6933
// and https://github.com/kubernetes/minikube/issues/6934
// to track status of adding containerd & crio
if containerRuntime != "docker" {
return false
}
@ -122,7 +130,7 @@ func Preload(k8sVersion, containerRuntime string) error {
return nil
}
out.T(out.FileDownload, "Downloading preloaded images tarball for k8s {{.version}} ...", out.V{"version": k8sVersion})
out.T(out.FileDownload, "Downloading Kubernetes {{.version}} preload ...", out.V{"version": k8sVersion})
url := remoteTarballURL(k8sVersion)
tmpDst := targetPath + ".download"

View File

@ -164,8 +164,8 @@ func FlagDefaults(name string) FlagHints {
}
// Choices returns a list of drivers which are possible on this system
func Choices() []registry.DriverState {
options := registry.Available()
func Choices(vm bool) []registry.DriverState {
options := registry.Available(vm)
// Descending priority for predictability and appearance
sort.Slice(options, func(i, j int) bool {

View File

@ -162,7 +162,7 @@ func TestSuggest(t *testing.T) {
}
}
got := Choices()
got := Choices(false)
gotNames := []string{}
for _, c := range got {
gotNames = append(gotNames, c.Name)

View File

@ -100,6 +100,7 @@ func doCacheBinaries(k8sVersion string) error {
// BeginDownloadKicArtifacts downloads the kic image + preload tarball, returns true if preload is available
func beginDownloadKicArtifacts(g *errgroup.Group) {
out.T(out.Pulling, "Pulling base image ...")
glog.Info("Beginning downloading kic artifacts")
g.Go(func() error {
glog.Infof("Downloading %s to local daemon", kic.BaseImage)

View File

@ -48,6 +48,7 @@ import (
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/logs"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/proxy"
"k8s.io/minikube/pkg/util"
@ -320,11 +321,34 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node) (runner command.
}
// startHost starts a new minikube host using a VM or None
func startHost(api libmachine.API, mc config.ClusterConfig, n config.Node) (*host.Host, bool) {
host, exists, err := machine.StartHost(api, mc, n)
if err != nil {
exit.WithError("Unable to start VM. Please investigate and run 'minikube delete' if possible", err)
func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*host.Host, bool) {
host, exists, err := machine.StartHost(api, cc, n)
if err == nil {
return host, exists
}
out.T(out.Embarrassed, "StartHost failed, but will try again: {{.error}}", out.V{"error": err})
// NOTE: People get very cranky if you delete their prexisting VM. Only delete new ones.
if !exists {
err := machine.DeleteHost(api, driver.MachineName(cc, n))
if err != nil {
glog.Warningf("delete host: %v", err)
}
}
// Try again, but just once to avoid making the logs overly confusing
time.Sleep(5 * time.Second)
host, exists, err = machine.StartHost(api, cc, n)
if err == nil {
return host, exists
}
out.T(out.FailureType, "StartHost failed again: {{.error}}", out.V{"error": err})
out.T(out.Workaround, `Run: "{{.delete}}", then "{{.start}} --alsologtostderr -v=1" to try again with more logging`,
out.V{"delete": mustload.ExampleCmd(cc.Name, "delete"), "start": mustload.ExampleCmd(cc.Name, "start")})
exit.WithError("Unable to start VM after repeated tries. Please try {{'minikube delete' if possible", err)
return host, exists
}

View File

@ -68,6 +68,9 @@ func T(style StyleEnum, format string, a ...V) {
// String writes a basic formatted string to stdout
func String(format string, a ...interface{}) {
// Flush log buffer so that output order makes sense
glog.Flush()
if outFile == nil {
glog.Warningf("[unset outFile]: %s", fmt.Sprintf(format, a...))
return

View File

@ -92,7 +92,7 @@ var styles = map[StyleEnum]style{
Caching: {Prefix: "🤹 "},
StartingVM: {Prefix: "🔥 "},
StartingNone: {Prefix: "🤹 "},
Provisioner: {Prefix: " "},
Provisioner: {Prefix: " "},
Resetting: {Prefix: "🔄 "},
DeletingHost: {Prefix: "🔥 "},
Copying: {Prefix: "✨ "},
@ -117,7 +117,7 @@ var styles = map[StyleEnum]style{
Unmount: {Prefix: "🔥 "},
MountOptions: {Prefix: "💾 "},
Fileserver: {Prefix: "🚀 ", OmitNewline: true},
DryRun: {Prefix: "🏜️ "},
DryRun: {Prefix: "🌵 "},
AddonEnable: {Prefix: "🌟 "},
AddonDisable: {Prefix: "🌑 "},
}

View File

@ -24,6 +24,40 @@ import (
"github.com/golang/glog"
)
const (
// Podman is Kubernetes in container using podman driver
Podman = "podman"
// Docker is Kubernetes in container using docker driver
Docker = "docker"
// Mock driver
Mock = "mock"
// None driver
None = "none"
)
// IsKIC checks if the driver is a kubernetes in container
func IsKIC(name string) bool {
return name == Docker || name == Podman
}
// IsMock checks if the driver is a mock
func IsMock(name string) bool {
return name == Mock
}
// IsVM checks if the driver is a VM
func IsVM(name string) bool {
if IsKIC(name) || IsMock(name) || BareMetal(name) {
return false
}
return true
}
// BareMetal returns if this driver is unisolated
func BareMetal(name string) bool {
return name == None || name == Mock
}
var (
// globalRegistry is a globally accessible driver registry
globalRegistry = newRegistry()
@ -59,7 +93,7 @@ func Driver(name string) DriverDef {
}
// Available returns a list of available drivers in the global registry
func Available() []DriverState {
func Available(vm bool) []DriverState {
sts := []DriverState{}
glog.Infof("Querying for installed drivers using PATH=%s", os.Getenv("PATH"))
@ -76,7 +110,13 @@ func Available() []DriverState {
priority = Unhealthy
}
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
if vm {
if IsVM(d.Name) {
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
}
} else {
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s})
}
}
// Descending priority for predictability

View File

@ -102,7 +102,7 @@ func TestGlobalAvailable(t *testing.T) {
},
}
if diff := cmp.Diff(Available(), expected); diff != "" {
if diff := cmp.Diff(Available(false), expected); diff != "" {
t.Errorf("available mismatch (-want +got):\n%s", diff)
}
}

View File

@ -38,12 +38,13 @@ func CalculateSizeInMB(humanReadableSize string) (int, error) {
if err == nil {
humanReadableSize += "mb"
}
size, err := units.FromHumanSize(humanReadableSize)
// parse the size suffix binary instead of decimal so that 1G -> 1024MB instead of 1000MB
size, err := units.RAMInBytes(humanReadableSize)
if err != nil {
return 0, fmt.Errorf("FromHumanSize: %v", err)
}
return int(size / units.MB), nil
return int(size / units.MiB), nil
}
// GetBinaryDownloadURL returns a suitable URL for the platform

View File

@ -51,6 +51,7 @@ func TestCalculateSizeInMB(t *testing.T) {
{"1024KB", 1},
{"1024mb", 1024},
{"1024b", 0},
{"1g", 1024},
}
for _, tt := range testData {
@ -59,7 +60,7 @@ func TestCalculateSizeInMB(t *testing.T) {
t.Fatalf("unexpected err: %v", err)
}
if number != tt.expectedNumber {
t.Fatalf("Expected '%d'' but got '%d'", tt.expectedNumber, number)
t.Fatalf("Expected '%d' but got '%d' from size '%s'", tt.expectedNumber, number, tt.size)
}
}
}

View File

@ -267,9 +267,17 @@ func validateHelmTillerAddon(ctx context.Context, t *testing.T, profile string)
t.Fatalf("wait: %v", err)
}
if NoneDriver() {
_, err := exec.LookPath("socat")
if err != nil {
t.Skipf("socat is required by kubectl to complete this test")
}
}
want := "Server: &version.Version"
// Test from inside the cluster (`helm version` use pod.list permission. we use tiller serviceaccount in kube-system to list pod)
checkHelmTiller := func() error {
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "run", "--rm", "helm-test", "--restart=Never", "--image=alpine/helm:2.16.3", "-it", "--namespace=kube-system", "--serviceaccount=tiller", "--", "version"))
if err != nil {
return err

View File

@ -175,7 +175,7 @@ func TestStartStopWithPreload(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
defer CleanupWithLogs(t, profile, cancel)
startArgs := []string{"start", "-p", profile, "--memory=2200", "--alsologtostderr", "-v=3", "--wait=true"}
startArgs := []string{"start", "-p", profile, "--memory=2200", "--alsologtostderr", "-v=3", "--wait=true", "--preload=false"}
startArgs = append(startArgs, StartArgs()...)
k8sVersion := "v1.17.0"
startArgs = append(startArgs, fmt.Sprintf("--kubernetes-version=%s", k8sVersion))
@ -191,6 +191,7 @@ func TestStartStopWithPreload(t *testing.T) {
if err != nil {
t.Fatalf("%s failed: %v", rr.Args, err)
}
// Restart minikube with v1.17.3, which has a preloaded tarball
startArgs = []string{"start", "-p", profile, "--memory=2200", "--alsologtostderr", "-v=3", "--wait=true"}
startArgs = append(startArgs, StartArgs()...)
@ -200,8 +201,6 @@ func TestStartStopWithPreload(t *testing.T) {
if err != nil {
t.Fatalf("%s failed: %v", rr.Args, err)
}
// Ensure that busybox still exists in the daemon
rr, err = Run(t, exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "docker", "images"))
if err != nil {
t.Fatalf("%s failed: %v", rr.Args, err)