Merge remote-tracking branch 'origin/master' into dont_disable_container_engines_when_vmdriver_is_none

pull/4545/head
Marcos Diez 2019-06-25 13:37:30 -03:00
commit d58e727512
32 changed files with 344 additions and 179 deletions

View File

@ -20,6 +20,8 @@ import (
"bytes"
"fmt"
"testing"
"k8s.io/minikube/pkg/minikube/constants"
)
type configTestCase struct {
@ -47,7 +49,7 @@ var configTestCases = []configTestCase{
"vm-driver": "kvm"
}`,
config: map[string]interface{}{
"vm-driver": "kvm",
"vm-driver": constants.DriverKvmOld,
"cpus": 4,
"disk-size": "20g",
"v": 5,

View File

@ -21,10 +21,11 @@ import (
"k8s.io/minikube/pkg/minikube/assets"
pkgConfig "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
)
var minikubeConfig = pkgConfig.MinikubeConfig{
"vm-driver": "kvm",
"vm-driver": constants.DriverKvmOld,
"cpus": 12,
"show-libmachine-logs": true,
}
@ -47,7 +48,7 @@ func TestFindSetting(t *testing.T) {
}
func TestSetString(t *testing.T) {
err := SetString(minikubeConfig, "vm-driver", "virtualbox")
err := SetString(minikubeConfig, "vm-driver", constants.DriverVirtualbox)
if err != nil {
t.Fatalf("Couldnt set string: %v", err)
}

View File

@ -83,7 +83,7 @@ associated files.`,
console.Fatal("Failed to kill mount process: %v", err)
}
if err := os.Remove(constants.GetProfileFile(viper.GetString(pkg_config.MachineProfile))); err != nil {
if err := os.RemoveAll(constants.GetProfilePath(viper.GetString(pkg_config.MachineProfile))); err != nil {
if os.IsNotExist(err) {
console.OutStyle(console.Meh, "%q profile does not exist", profile)
os.Exit(0)

View File

@ -175,14 +175,7 @@ func runStart(cmd *cobra.Command, args []string) {
console.OutStyle(console.Happy, "minikube %s on %s (%s)", version.GetVersion(), runtime.GOOS, runtime.GOARCH)
validateConfig()
currentUser, err := user.Current()
// Display warning if minikube is being started with root and vmDriver is not HyperV
if err != nil {
glog.Errorf("Error getting the current user: %v", err)
} else if currentUser.Name == "root" && !(viper.GetString(vmDriver) == "hyperv" || viper.GetString(vmDriver) == "none") {
console.OutStyle(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.")
}
validateUser()
oldConfig, err := cfg.Load()
if err != nil && !os.IsNotExist(err) {
@ -195,15 +188,10 @@ func runStart(cmd *cobra.Command, args []string) {
}
// For non-"none", the ISO is required to boot, so block until it is downloaded
if viper.GetString(vmDriver) != constants.DriverNone {
if err := cluster.CacheISO(config.MachineConfig); err != nil {
exit.WithError("Failed to cache ISO", err)
}
} else {
// With "none", images are persistently stored in Docker, so internal caching isn't necessary.
viper.Set(cacheImages, false)
config.KubernetesConfig.ShouldLoadCachedImages = false
}
downloadISO(config)
// With "none", images are persistently stored in Docker, so internal caching isn't necessary.
skipCache(config)
// Now that the ISO is downloaded, pull images in the background while the VM boots.
var cacheGroup errgroup.Group
@ -236,11 +224,12 @@ func runStart(cmd *cobra.Command, args []string) {
host, preexisting := startHost(m, config.MachineConfig)
ip := validateNetwork(host)
// Makes minikube node ip to bypass http(s) proxy. since it is local traffic.
// Bypass proxy for minikube's vm ip
err = proxy.ExcludeIP(ip)
if err != nil {
console.ErrStyle(console.FailureType, "Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,%s`.", ip)
}
// Save IP to configuration file for subsequent use
config.KubernetesConfig.NodeIP = ip
if err := saveConfig(config); err != nil {
@ -252,14 +241,7 @@ func runStart(cmd *cobra.Command, args []string) {
}
cr := configureRuntimes(runner)
version, _ := cr.Version()
console.OutStyle(cr.Style(), "Configuring environment for Kubernetes %s on %s %s", k8sVersion, cr.Name(), version)
for _, v := range dockerOpt {
console.OutStyle(console.Option, "opt %s", v)
}
for _, v := range dockerEnv {
console.OutStyle(console.Option, "env %s", v)
}
showVersionInfo(k8sVersion, cr)
// prepareHostEnvironment uses the downloaded images, so we need to wait for background task completion.
waitCacheImages(&cacheGroup)
@ -286,6 +268,32 @@ func runStart(cmd *cobra.Command, args []string) {
}
func downloadISO(config cfg.Config) {
if viper.GetString(vmDriver) != constants.DriverNone {
if err := cluster.CacheISO(config.MachineConfig); err != nil {
exit.WithError("Failed to cache ISO", err)
}
}
}
func skipCache(config cfg.Config) {
if viper.GetString(vmDriver) == constants.DriverNone {
viper.Set(cacheImages, false)
config.KubernetesConfig.ShouldLoadCachedImages = false
}
}
func showVersionInfo(k8sVersion string, cr cruntime.Manager) {
version, _ := cr.Version()
console.OutStyle(cr.Style(), "Configuring environment for Kubernetes %s on %s %s", k8sVersion, cr.Name(), version)
for _, v := range dockerOpt {
console.OutStyle(console.Option, "opt %s", v)
}
for _, v := range dockerEnv {
console.OutStyle(console.Option, "env %s", v)
}
}
func showKubectlConnectInfo(kubeconfig *pkgutil.KubeConfigSetup) {
if kubeconfig.KeepContext {
console.OutStyle(console.Kubectl, "To connect to this cluster, use: kubectl --context=%s", kubeconfig.ClusterName)
@ -350,6 +358,18 @@ func selectImageRepository(mirrorCountry string, k8sVersion string) (bool, strin
return false, fallback, nil
}
// validerUser validates minikube is run by the recommended user (privileged or regular)
func validateUser() {
currentUser, err := user.Current()
// Display warning if minikube is being started with root and vmDriver is not HyperV
if err != nil {
glog.Errorf("Error getting the current user: %v", err)
} else if currentUser.Name == "root" && !(viper.GetString(vmDriver) == constants.DriverHyperv || viper.GetString(vmDriver) == constants.DriverNone) {
console.OutStyle(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.")
}
}
// validateConfig validates the supplied configuration against known bad combinations
func validateConfig() {
diskSizeMB := pkgutil.CalculateDiskSizeInMB(viper.GetString(humanReadableDiskSize))
@ -357,11 +377,11 @@ func validateConfig() {
exit.WithCode(exit.Config, "Requested disk size (%dMB) is less than minimum of %dMB", diskSizeMB, constants.MinimumDiskSizeMB)
}
if viper.GetBool(gpu) && viper.GetString(vmDriver) != "kvm2" {
exit.Usage("Sorry, the --gpu feature is currently only supported with --vm-driver=kvm2")
if viper.GetBool(gpu) && viper.GetString(vmDriver) != constants.DriverKvm2 {
exit.Usage("Sorry, the --gpu feature is currently only supported with --vm-driver=%s", constants.DriverKvm2)
}
if viper.GetBool(hidden) && viper.GetString(vmDriver) != "kvm2" {
exit.Usage("Sorry, the --hidden feature is currently only supported with --vm-driver=kvm2")
if viper.GetBool(hidden) && viper.GetString(vmDriver) != constants.DriverKvm2 {
exit.Usage("Sorry, the --hidden feature is currently only supported with --vm-driver=%s", constants.DriverKvm2)
}
err := autoSetOptions(viper.GetString(vmDriver))

View File

@ -1,4 +1,12 @@
[
{
"name": "v1.2.0",
"checksums": {
"darwin": "183d017d094b7783c938dc709dbdfc9a48f92299178234f89047dfbb083a592c",
"linux": "123fc9f5656333fb2927cf91666a91cd5b28ef97503418ac2a90a2109e518ed9",
"windows": "f6c30cb88ec61bc6fe17532a3ef56e4f1fcef2473e3d73fc56f352b44784490d"
}
},
{
"name": "v1.1.1",
"checksums": {

View File

@ -1,5 +1,7 @@
# Reusing the Docker daemon
## Method 1: Without minikube registry addon
When using a single VM of Kubernetes it's really handy to reuse the Docker daemon inside the VM; as this means you don't have to build on your host machine and push the image into a docker registry - you can just build inside the same docker daemon as minikube which speeds up local experiments.
To be able to work with the docker daemon on your mac/linux host use the docker-env command in your shell:
@ -14,6 +16,12 @@ You should now be able to use docker on the command line on your host mac/linux
docker ps
```
Docker may report following forbidden error if you are using http proxy and the `$(minikube ip)` is not added to `no_proxy`/`NO_PROXY`:
```shell
error during connect: Get https://192.168.39.98:2376/v1.39/containers/json: Forbidden
```
On Centos 7, docker may report the following error:
```shell
@ -31,3 +39,43 @@ The fix is to update /etc/sysconfig/docker to ensure that minikube's environment
```
Remember to turn off the _imagePullPolicy:Always_, as otherwise Kubernetes won't use images you built locally.
## Method 2: With minikube registry addon
Enable minikube registry addon and then push images directly into registry. Steps are as follows:
For illustration purpose, we will assume that minikube VM has one of the ip from `192.168.39.0/24` subnet. If you have not overridden these subnets as per [networking guide](https://github.com/kubernetes/minikube/blob/master/docs/networking.md), you can find out default subnet being used by minikube for a specific OS and driver combination [here](https://github.com/kubernetes/minikube/blob/dfd9b6b83d0ca2eeab55588a16032688bc26c348/pkg/minikube/cluster/cluster.go#L408) which is subject to change. Replace `192.168.39.0/24` with appropriate values for your environment wherever applicable.
Ensure that docker is configured to use `192.168.39.0/24` as insecure registry. Refer [here](https://docs.docker.com/registry/insecure/) for instructions.
Ensure that `192.168.39.0/24` is enabled as insecure registry in minikube. Refer [here](https://github.com/kubernetes/minikube/blob/master/docs/insecure_registry.md) for instructions..
Enable minikube registry addon:
```shell
minikube addons enable registry
```
Build docker image and tag it appropriately:
```shell
docker build --tag $(minikube ip):5000/test-img .
```
Push docker image to minikube registry:
```shell
docker push $(minikube ip):5000/test-img
```
Now run it in minikube:
```shell
kubectl run test-img --image=$(minikube ip):5000/test-img
```
Or if `192.168.39.0/24` is not enabled as insecure registry in minikube, then:
```shell
kubectl run test-img --image=localhost:5000/test-img
```

View File

@ -118,7 +118,7 @@ func (d *Driver) Create() error {
// DriverName returns the name of the driver
func (d *Driver) DriverName() string {
return "hyperkit"
return constants.DriverHyperkit
}
// GetSSHHostname returns hostname for use with ssh
@ -223,7 +223,7 @@ func (d *Driver) Start() error {
h.Memory = d.Memory
h.UUID = d.UUID
// This should stream logs from hyperkit, but doesn't seem to work.
logger := golog.New(os.Stderr, "hyperkit", golog.LstdFlags)
logger := golog.New(os.Stderr, constants.DriverHyperkit, golog.LstdFlags)
h.SetLogger(logger)
if vsockPorts, err := d.extractVSockPorts(); err != nil {

View File

@ -220,7 +220,7 @@ func (d *Driver) GetSSHHostname() (string, error) {
// DriverName returns the name of the driver
func (d *Driver) DriverName() string {
return "kvm2"
return constants.DriverKvm2
}
// Kill stops a host forcefully, including any containers that we are managing.

View File

@ -151,20 +151,6 @@ func (d *Driver) createNetwork() error {
}
func (d *Driver) deleteNetwork() error {
type source struct {
//XMLName xml.Name `xml:"source"`
Network string `xml:"network,attr"`
}
type iface struct {
//XMLName xml.Name `xml:"interface"`
Source source `xml:"source"`
}
type result struct {
//XMLName xml.Name `xml:"domain"`
Name string `xml:"name"`
Interfaces []iface `xml:"devices>interface"`
}
conn, err := getConnection()
if err != nil {
return errors.Wrap(err, "getting libvirt connection")
@ -187,6 +173,41 @@ func (d *Driver) deleteNetwork() error {
}
log.Debugf("Network %s exists", d.PrivateNetwork)
err = d.checkDomains(conn)
if err != nil {
return err
}
// when we reach this point, it means it is safe to delete the network
log.Debugf("Trying to destroy network %s...", d.PrivateNetwork)
err = network.Destroy()
if err != nil {
return errors.Wrap(err, "network destroy")
}
log.Debugf("Trying to undefine network %s...", d.PrivateNetwork)
err = network.Undefine()
if err != nil {
return errors.Wrap(err, "network undefine")
}
return nil
}
func (d *Driver) checkDomains(conn *libvirt.Connect) error {
type source struct {
//XMLName xml.Name `xml:"source"`
Network string `xml:"network,attr"`
}
type iface struct {
//XMLName xml.Name `xml:"interface"`
Source source `xml:"source"`
}
type result struct {
//XMLName xml.Name `xml:"domain"`
Name string `xml:"name"`
Interfaces []iface `xml:"devices>interface"`
}
// iterate over every (also turned off) domains, and check if it
// is using the private network. Do *not* delete the network if
// that is the case
@ -244,18 +265,6 @@ func (d *Driver) deleteNetwork() error {
}
}
// when we reach this point, it means it is safe to delete the network
log.Debugf("Trying to destroy network %s...", d.PrivateNetwork)
err = network.Destroy()
if err != nil {
return errors.Wrap(err, "network destroy")
}
log.Debugf("Trying to undefine network %s...", d.PrivateNetwork)
err = network.Undefine()
if err != nil {
return errors.Wrap(err, "network undefine")
}
return nil
}

View File

@ -130,8 +130,8 @@ ExecStart=/usr/bin/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/
}
}
func TestGenerateConfig(t *testing.T) {
extraOpts := util.ExtraOptionSlice{
func getExtraOpts() []util.ExtraOption {
return util.ExtraOptionSlice{
util.ExtraOption{
Component: Apiserver,
Key: "fail-no-swap",
@ -158,15 +158,19 @@ func TestGenerateConfig(t *testing.T) {
Value: "true",
},
}
}
extraOptsPodCidr := util.ExtraOptionSlice{
func getExtraOptsPodCidr() []util.ExtraOption {
return util.ExtraOptionSlice{
util.ExtraOption{
Component: Kubeadm,
Key: "pod-network-cidr",
Value: "192.168.32.0/20",
},
}
}
func recentReleases() ([]string, error) {
// test the 6 most recent releases
versions := []string{"v1.15", "v1.14", "v1.13", "v1.12", "v1.11", "v1.10"}
foundNewest := false
@ -182,13 +186,23 @@ func TestGenerateConfig(t *testing.T) {
}
if !foundNewest {
t.Errorf("No tests exist yet for newest minor version: %s", constants.NewestKubernetesVersion)
return nil, fmt.Errorf("No tests exist yet for newest minor version: %s", constants.NewestKubernetesVersion)
}
if !foundDefault {
t.Errorf("No tests exist yet for default minor version: %s", constants.DefaultKubernetesVersion)
return nil, fmt.Errorf("No tests exist yet for default minor version: %s", constants.DefaultKubernetesVersion)
}
return versions, nil
}
func TestGenerateConfig(t *testing.T) {
extraOpts := getExtraOpts()
extraOptsPodCidr := getExtraOptsPodCidr()
versions, err := recentReleases()
if err != nil {
t.Errorf("versions: %v", err)
}
tests := []struct {
name string
runtime string

View File

@ -254,7 +254,7 @@ func DeleteHost(api libmachine.API) error {
return errors.Wrap(err, "load")
}
// This is slow if SSH is not responding, but HyperV hangs otherwise, See issue #2914
if host.Driver.DriverName() == "hyperv" {
if host.Driver.DriverName() == constants.DriverHyperv {
trySSHPowerOff(host)
}
@ -320,21 +320,21 @@ func engineOptions(config cfg.MachineConfig) *engine.Options {
func preCreateHost(config *cfg.MachineConfig) {
switch config.VMDriver {
case "kvm":
case constants.DriverKvmOld:
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
console.Warning(`The kvm driver is deprecated and support for it will be removed in a future release.
Please consider switching to the kvm2 driver, which is intended to replace the kvm driver.
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver for more information.
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
}
case "xhyve":
case constants.DriverXhyve:
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
console.Warning(`The xhyve driver is deprecated and support for it will be removed in a future release.
Please consider switching to the hyperkit driver, which is intended to replace the xhyve driver.
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver for more information.
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
}
case "vmwarefusion":
case constants.DriverVmwareFusion:
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
console.Warning(`The vmwarefusion driver is deprecated and support for it will be removed in a future release.
Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver.
@ -407,11 +407,11 @@ func GetHostDockerEnv(api libmachine.API) (map[string]string, error) {
// GetVMHostIP gets the ip address to be used for mapping host -> VM and VM -> host
func GetVMHostIP(host *host.Host) (net.IP, error) {
switch host.DriverName {
case "kvm":
case constants.DriverKvmOld:
return net.ParseIP("192.168.42.1"), nil
case "kvm2":
case constants.DriverKvm2:
return net.ParseIP("192.168.39.1"), nil
case "hyperv":
case constants.DriverHyperv:
re := regexp.MustCompile(`"VSwitch": "(.*?)",`)
// TODO(aprindle) Change this to deserialize the driver instead
hypervVirtualSwitch := re.FindStringSubmatch(string(host.RawDriver))[1]
@ -420,7 +420,7 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
return []byte{}, errors.Wrap(err, fmt.Sprintf("ip for interface (%s)", hypervVirtualSwitch))
}
return ip, nil
case "virtualbox":
case constants.DriverVirtualbox:
out, err := exec.Command(detectVBoxManageCmd(), "showvminfo", host.Name, "--machinereadable").Output()
if err != nil {
return []byte{}, errors.Wrap(err, "vboxmanage")
@ -432,9 +432,9 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
return []byte{}, errors.Wrap(err, "Error getting VM/Host IP address")
}
return ip, nil
case "xhyve", "hyperkit":
case constants.DriverXhyve, constants.DriverHyperkit:
return net.ParseIP("192.168.64.1"), nil
case "vmware":
case constants.DriverVmware:
vmIPString, err := host.Driver.GetIP()
if err != nil {
return []byte{}, errors.Wrap(err, "Error getting VM IP address")

View File

@ -20,6 +20,8 @@ import (
"bytes"
"reflect"
"testing"
"k8s.io/minikube/pkg/minikube/constants"
)
type configTestCase struct {
@ -47,7 +49,7 @@ var configTestCases = []configTestCase{
"vm-driver": "kvm"
}`,
config: map[string]interface{}{
"vm-driver": "kvm",
"vm-driver": constants.DriverKvmOld,
"cpus": 4,
"disk-size": "20g",
"v": 5,

View File

@ -16,8 +16,10 @@ limitations under the License.
package console
// StyleEnum is an enumeration of Style
type StyleEnum int
// All the Style constants available
const (
Happy StyleEnum = iota
SuccessType

View File

@ -59,19 +59,49 @@ func ArchTag(hasTag bool) string {
return "-" + runtime.GOARCH + ":"
}
// DriverNone is the none driver.
const DriverNone = "none"
// DriverKvmOld is the depricated kvm driver option name
const DriverKvmOld = "kvm"
// DriverKvm2 is the kvm2 driver option name for in linux
const DriverKvm2 = "kvm2"
// DriverVirtualbox is the virtualbox driver option name
const DriverVirtualbox = "virtualbox"
// DriverHyperkit is the hyperkit driver option name for mac os
const DriverHyperkit = "hyperkit"
// DriverVmware is the vmware driver option name
const DriverVmware = "vmware"
// DriverVmwareFusion is the vmware fusion driver option
const DriverVmwareFusion = "vmwarefusion"
// DriverHyperv is the hyperv driver option for windows
const DriverHyperv = "hyperv"
// DriverXhyve is the depricated xhyve driver option name
const DriverXhyve = "xhyve"
// DriverParallels is the parallels driver option name
const DriverParallels = "parallels"
// SupportedVMDrivers is a list of supported drivers on all platforms. Currently
// used in gendocs.
var SupportedVMDrivers = [...]string{
"virtualbox",
"parallels",
"vmwarefusion",
"kvm",
"xhyve",
"hyperv",
"hyperkit",
"kvm2",
"vmware",
"none",
DriverVirtualbox,
DriverParallels,
DriverVmwareFusion,
DriverKvmOld,
DriverXhyve,
DriverHyperv,
DriverHyperkit,
DriverKvm2,
DriverVmware,
DriverNone,
}
// DefaultMinipath is the default Minikube path (under the home directory)
@ -130,7 +160,7 @@ const (
// MinimumDiskSizeMB is the minimum disk image size, in megabytes
MinimumDiskSizeMB = 2000
// DefaultVMDriver is the default virtual machine driver name
DefaultVMDriver = "virtualbox"
DefaultVMDriver = DriverVirtualbox
// DefaultStatusFormat is the default format of a host
DefaultStatusFormat = `host: {{.Host}}
kubelet: {{.Kubelet}}
@ -181,6 +211,11 @@ func GetProfileFile(profile string) string {
return filepath.Join(GetMinipath(), "profiles", profile, "config.json")
}
// GetProfilePath returns the Minikube profile path of config file
func GetProfilePath(profile string) string {
return filepath.Join(GetMinipath(), "profiles", profile)
}
// AddonsPath is the default path of the addons configuration
const AddonsPath = "/etc/kubernetes/addons"
@ -230,9 +265,6 @@ func GetKubernetesReleaseURLSHA1(binaryName, version, osName, archName string) s
// IsMinikubeChildProcess is the name of "is minikube child process" variable
const IsMinikubeChildProcess = "IS_MINIKUBE_CHILD_PROCESS"
// DriverNone is the none driver
const DriverNone = "none"
// FileScheme is the file scheme
const FileScheme = "file"

View File

@ -35,6 +35,7 @@ func (r *Containerd) Name() string {
return "containerd"
}
// Style is the console style for containerd
func (r *Containerd) Style() console.StyleEnum {
return console.Containerd
}

View File

@ -35,7 +35,7 @@ func (r *CRIO) Name() string {
return "CRI-O"
}
// Name is a human readable name for CRIO
// Style is the console style for CRIO
func (r *CRIO) Style() console.StyleEnum {
return console.CRIO
}

View File

@ -36,7 +36,7 @@ func (r *Docker) Name() string {
return "Docker"
}
// Name is a human readable name for Docker
// Style is the console style for Docker
func (r *Docker) Style() console.StyleEnum {
return console.Docker
}

View File

@ -31,7 +31,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: "hyperkit",
Name: constants.DriverHyperkit,
Builtin: false,
ConfigCreator: createHyperkitHost,
}); err != nil {

View File

@ -28,7 +28,7 @@ import (
func init() {
registry.Register(registry.DriverDef{
Name: "hyperv",
Name: constants.DriverHyperv,
Builtin: true,
ConfigCreator: createHypervHost,
DriverCreator: func() drivers.Driver {
@ -46,7 +46,7 @@ func createHypervHost(config cfg.MachineConfig) interface{} {
d.CPU = config.CPUs
d.DiskSize = int(config.DiskSize)
d.SSHUser = "docker"
d.DisableDynamicMemory = true //default to disable dynamic memory as minikube is unlikely to work properly with dynamic memory
d.DisableDynamicMemory = true //default to disable dynamic memory as minikube is unlikely to work properly with dynamic memory
return d
}

View File

@ -30,7 +30,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: "kvm",
Name: constants.DriverKvmOld,
Builtin: false,
ConfigCreator: createKVMHost,
}); err != nil {

View File

@ -30,7 +30,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: "kvm2",
Name: constants.DriverKvm2,
Builtin: false,
ConfigCreator: createKVM2Host,
}); err != nil {

View File

@ -30,7 +30,7 @@ import (
func init() {
err := registry.Register(registry.DriverDef{
Name: "parallels",
Name: constants.DriverParallels,
Builtin: true,
ConfigCreator: createParallelsHost,
DriverCreator: func() drivers.Driver {

View File

@ -30,7 +30,7 @@ const defaultVirtualboxNicType = "virtio"
func init() {
err := registry.Register(registry.DriverDef{
Name: "virtualbox",
Name: constants.DriverVirtualbox,
Builtin: true,
ConfigCreator: createVirtualboxHost,
DriverCreator: func() drivers.Driver {

View File

@ -27,7 +27,7 @@ import (
func init() {
err := registry.Register(registry.DriverDef{
Name: "vmware",
Name: constants.DriverVmware,
Builtin: false,
ConfigCreator: createVMwareHost,
})

View File

@ -30,7 +30,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: "vmwarefusion",
Name: constants.DriverVmwareFusion,
Builtin: true,
ConfigCreator: createVMwareFusionHost,
DriverCreator: func() drivers.Driver {

View File

@ -35,7 +35,7 @@ https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#xhyve-driver
func init() {
if err := registry.Register(registry.DriverDef{
Name: "xhyve",
Name: constants.DriverXhyve,
Builtin: false,
ConfigCreator: createXhyveHost,
DriverCreator: func() drivers.Driver {

View File

@ -237,6 +237,10 @@ func checkCallExpression(s *ast.CallExpr, e *state) {
return
}
checkArguments(s, e)
}
func checkArguments(s *ast.CallExpr, e *state) {
matched := false
for _, arg := range s.Args {
// This argument is an identifier.

View File

@ -76,12 +76,12 @@ func TestLocalClientNewHost(t *testing.T) {
}{
{
description: "host vbox correct",
driver: "virtualbox",
driver: constants.DriverVirtualbox,
rawDriver: []byte(vboxConfig),
},
{
description: "host vbox incorrect",
driver: "virtualbox",
driver: constants.DriverVirtualbox,
rawDriver: []byte("?"),
err: true,
},
@ -137,7 +137,7 @@ func TestRunDriver(t *testing.T) {
defer os.RemoveAll(tempDir)
os.Setenv(localbinary.PluginEnvKey, localbinary.PluginEnvVal)
os.Setenv(localbinary.PluginEnvDriverName, "virtualbox")
os.Setenv(localbinary.PluginEnvDriverName, constants.DriverVirtualbox)
// Capture stdout and reset it later.
old := os.Stdout

View File

@ -50,10 +50,12 @@ type FakeFile struct {
b bytes.Buffer
}
// NewFakeFile creates a FakeFile
func NewFakeFile() *FakeFile {
return &FakeFile{}
}
// Fd returns the file descriptor
func (f *FakeFile) Fd() uintptr {
return uintptr(0)
}

View File

@ -72,14 +72,8 @@ type execRequest struct {
Command string
}
// Start starts the mock SSH Server, and returns the port it's listening on.
func (s *SSHServer) Start() (int, error) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return 0, errors.Wrap(err, "Error creating tcp listener for ssh server")
}
// Main loop, listen for connections and store the commands.
// Main loop, listen for connections and store the commands.
func (s *SSHServer) mainLoop(listener net.Listener) {
go func() {
for {
nConn, err := listener.Accept()
@ -109,54 +103,68 @@ func (s *SSHServer) Start() (int, error) {
for req := range requests {
glog.Infoln("Got Req: ", req.Type)
// Store anything that comes in over stdin.
go func() {
if _, err := io.Copy(s.Transfers, channel); err != nil {
panic(fmt.Sprintf("copy failed: %v", err))
}
channel.Close()
}()
switch req.Type {
case "exec":
if err := req.Reply(true, nil); err != nil {
panic(fmt.Sprintf("reply failed: %v", err))
}
// Note: string(req.Payload) adds additional characters to start of input.
var cmd execRequest
if err := ssh.Unmarshal(req.Payload, &cmd); err != nil {
glog.Errorf("Unmarshall encountered error: %v with req: %v", err, req.Type)
return
}
s.Commands[cmd.Command] = 1
// Write specified command output as mocked ssh output
if val, err := s.GetCommandToOutput(cmd.Command); err == nil {
if _, err := channel.Write([]byte(val)); err != nil {
glog.Errorf("Write failed: %v", err)
return
}
}
if _, err := channel.SendRequest("exit-status", false, []byte{0, 0, 0, 0}); err != nil {
glog.Errorf("SendRequest failed: %v", err)
return
}
case "pty-req":
if err := req.Reply(true, nil); err != nil {
glog.Errorf("Reply failed: %v", err)
return
}
if _, err := channel.SendRequest("exit-status", false, []byte{0, 0, 0, 0}); err != nil {
glog.Errorf("SendRequest failed: %v", err)
return
}
}
s.handleRequest(channel, req)
}
}
}()
}
}()
}
func (s *SSHServer) handleRequest(channel ssh.Channel, req *ssh.Request) {
go func() {
if _, err := io.Copy(s.Transfers, channel); err != nil {
panic(fmt.Sprintf("copy failed: %v", err))
}
channel.Close()
}()
switch req.Type {
case "exec":
if err := req.Reply(true, nil); err != nil {
panic(fmt.Sprintf("reply failed: %v", err))
}
// Note: string(req.Payload) adds additional characters to start of input.
var cmd execRequest
if err := ssh.Unmarshal(req.Payload, &cmd); err != nil {
glog.Errorf("Unmarshall encountered error: %v with req: %v", err, req.Type)
return
}
s.Commands[cmd.Command] = 1
// Write specified command output as mocked ssh output
if val, err := s.GetCommandToOutput(cmd.Command); err == nil {
if _, err := channel.Write([]byte(val)); err != nil {
glog.Errorf("Write failed: %v", err)
return
}
}
if _, err := channel.SendRequest("exit-status", false, []byte{0, 0, 0, 0}); err != nil {
glog.Errorf("SendRequest failed: %v", err)
return
}
case "pty-req":
if err := req.Reply(true, nil); err != nil {
glog.Errorf("Reply failed: %v", err)
return
}
if _, err := channel.SendRequest("exit-status", false, []byte{0, 0, 0, 0}); err != nil {
glog.Errorf("SendRequest failed: %v", err)
return
}
}
}
// Start starts the mock SSH Server, and returns the port it's listening on.
func (s *SSHServer) Start() (int, error) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return 0, errors.Wrap(err, "Error creating tcp listener for ssh server")
}
s.mainLoop(listener)
// Parse and return the port.
_, p, err := net.SplitHostPort(listener.Addr().String())

View File

@ -29,6 +29,7 @@ import (
"github.com/pkg/errors"
typed_core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
)
//tunnel represents the basic API for a tunnel: periodically the state of the tunnel
@ -149,7 +150,7 @@ func setupRoute(t *tunnel, h *host.Host) {
return
}
if h.DriverName == "hyperkit" {
if h.DriverName == constants.DriverHyperkit {
//the virtio-net interface acts up with ip tunnels :(
setupBridge(t)
if t.status.RouteError != nil {

View File

@ -89,30 +89,13 @@ func testTunnel(t *testing.T) {
t.Log("getting nginx ingress...")
nginxIP := ""
err = wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
cmd := []string{"get", "svc", "nginx-svc", "-o", "jsonpath={.status.loadBalancer.ingress[0].ip}"}
stdout, err := kubectlRunner.RunCommand(cmd)
switch {
case err == nil:
nginxIP = string(stdout)
return len(stdout) != 0, nil
case !commonutil.IsRetryableAPIError(err):
t.Errorf("`%s` failed with non retriable error: %v", cmd, err)
return false, err
default:
t.Errorf("`%s` failed: %v", cmd, err)
return false, nil
}
})
nginxIP, err := getIngress(kubectlRunner)
if err != nil {
t.Errorf("error getting ingress IP for nginx: %s", err)
}
if len(nginxIP) == 0 {
stdout, err := kubectlRunner.RunCommand([]string{"get", "svc", "nginx-svc", "-o", "jsonpath={.status}"})
stdout, err := describeIngress(kubectlRunner)
if err != nil {
t.Errorf("error debugging nginx service: %s", err)
@ -130,6 +113,34 @@ func testTunnel(t *testing.T) {
}
}
func getIngress(kubectlRunner *util.KubectlRunner) (string, error) {
nginxIP := ""
var ret error
err := wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
cmd := []string{"get", "svc", "nginx-svc", "-o", "jsonpath={.status.loadBalancer.ingress[0].ip}"}
stdout, err := kubectlRunner.RunCommand(cmd)
switch {
case err == nil:
nginxIP = string(stdout)
return len(stdout) != 0, nil
case !commonutil.IsRetryableAPIError(err):
ret = fmt.Errorf("`%s` failed with non retriable error: %v", cmd, err)
return false, err
default:
ret = fmt.Errorf("`%s` failed: %v", cmd, err)
return false, nil
}
})
if err != nil {
return "", err
}
return nginxIP, ret
}
func describeIngress(kubectlRunner *util.KubectlRunner) ([]byte, error) {
return kubectlRunner.RunCommand([]string{"get", "svc", "nginx-svc", "-o", "jsonpath={.status}"})
}
// getResponseBody returns the contents of a URL
func getResponseBody(address string) (string, error) {
httpClient := http.DefaultClient