Skip to content

Commit

Permalink
Merge pull request #1173 from aaron-prindle/minikube-no-vm
Browse files Browse the repository at this point in the history
None driver
  • Loading branch information
aaron-prindle authored May 26, 2017
2 parents d5e4d45 + f4a8ece commit a7c2ff3
Show file tree
Hide file tree
Showing 28 changed files with 569 additions and 78 deletions.
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDisableUnknownAddon(t *testing.T) {
}
}

func TestDisableValidAddonNoVM(t *testing.T) {
func TestDisableValidAddonLocal(t *testing.T) {
tempDir := tests.MakeTempDir()
defer os.RemoveAll(tempDir)

Expand All @@ -60,7 +60,7 @@ func TestDisableValidAddonNoVM(t *testing.T) {
}
}

func TestDeleteAddonViaDriver(t *testing.T) {
func TestDeleteAddonSSH(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()
if err != nil {
Expand All @@ -76,7 +76,7 @@ func TestDeleteAddonViaDriver(t *testing.T) {
}

dashboard := assets.Addons["dashboard"]
if err := deleteAddonViaDriver(dashboard, d); err != nil {
if err := deleteAddonSSH(dashboard, d); err != nil {
t.Fatalf("Unexpected error %s deleting addon", err)
}
// check command(s) were run
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestEnableUnknownAddon(t *testing.T) {
}
}

func TestEnableValidAddonNoVM(t *testing.T) {
func TestEnableValidAddonLocal(t *testing.T) {
tempDir := tests.MakeTempDir()
defer os.RemoveAll(tempDir)

Expand All @@ -59,7 +59,7 @@ func TestEnableValidAddonNoVM(t *testing.T) {
}
}

func TestTransferAddonViaDriver(t *testing.T) {
func TestTransferAddonSSH(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()
if err != nil {
Expand All @@ -75,7 +75,7 @@ func TestTransferAddonViaDriver(t *testing.T) {
}

dashboard := assets.Addons["dashboard"]
if err := transferAddonViaDriver(dashboard, d); err != nil {
if err := transferAddonSSH(dashboard, d); err != nil {
t.Fatalf("Unexpected error %s transferring addon", err)
}
// check contents
Expand Down
55 changes: 51 additions & 4 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package config
import (
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/docker/machine/libmachine/drivers"
Expand Down Expand Up @@ -110,18 +111,18 @@ func EnableOrDisableAddon(name string, val string) error {
}
host, err := cluster.CheckIfApiExistsAndLoad(api)
if enable {
if err = transferAddonViaDriver(addon, host.Driver); err != nil {
if err = transferAddon(addon, host.Driver); err != nil {
return errors.Wrapf(err, "Error transferring addon %s to VM", name)
}
} else {
if err = deleteAddonViaDriver(addon, host.Driver); err != nil {
if err = deleteAddon(addon, host.Driver); err != nil {
return errors.Wrapf(err, "Error deleting addon %s from VM", name)
}
}
return nil
}

func deleteAddonViaDriver(addon *assets.Addon, d drivers.Driver) error {
func deleteAddonSSH(addon *assets.Addon, d drivers.Driver) error {
client, err := sshutil.NewSSHClient(d)
if err != nil {
return err
Expand All @@ -132,7 +133,30 @@ func deleteAddonViaDriver(addon *assets.Addon, d drivers.Driver) error {
return nil
}

func transferAddonViaDriver(addon *assets.Addon, d drivers.Driver) error {
func deleteAddon(addon *assets.Addon, d drivers.Driver) error {
if d.DriverName() == "none" {
if err := deleteAddonLocal(addon, d); err != nil {
return err
}
} else {
if err := deleteAddonSSH(addon, d); err != nil {
return err
}
}
return nil
}

func deleteAddonLocal(addon *assets.Addon, d drivers.Driver) error {
var err error
for _, f := range addon.Assets {
if err = os.Remove(filepath.Join(f.GetTargetDir(), f.GetTargetName())); err != nil {
return err
}
}
return err
}

func transferAddonSSH(addon *assets.Addon, d drivers.Driver) error {
client, err := sshutil.NewSSHClient(d)
if err != nil {
return err
Expand All @@ -158,3 +182,26 @@ func EnableOrDisableDefaultStorageClass(name, val string) error {
}
return EnableOrDisableAddon(name, val)
}

func transferAddon(addon *assets.Addon, d drivers.Driver) error {
if d.DriverName() == "none" {
if err := transferAddonLocal(addon, d); err != nil {
return err
}
} else {
if err := transferAddonSSH(addon, d); err != nil {
return err
}
}
return nil
}

func transferAddonLocal(addon *assets.Addon, d drivers.Driver) error {
var err error
for _, f := range addon.Assets {
if err = assets.CopyFileLocal(f); err != nil {
return err
}
}
return err
}
9 changes: 9 additions & 0 deletions cmd/minikube/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ var dockerEnvCmd = &cobra.Command{
os.Exit(1)
}
defer api.Close()
host, err := cluster.CheckIfApiExistsAndLoad(api)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting host: %s\n", err)
os.Exit(1)
}
if host.Driver.DriverName() == "none" {
fmt.Println(`'none' driver does not support 'minikube docker-env' command`)
os.Exit(0)
}

var shellCfg *ShellConfig

Expand Down
4 changes: 4 additions & 0 deletions cmd/minikube/cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ var mountCmd = &cobra.Command{
glog.Errorln("Error loading api: ", err)
os.Exit(1)
}
if host.Driver.DriverName() == "none" {
fmt.Println(`'none' driver does not support 'minikube mount' command`)
os.Exit(0)
}
var ip net.IP
if mountIP == "" {
ip, err = cluster.GetVMHostIP(host)
Expand Down
9 changes: 9 additions & 0 deletions cmd/minikube/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ var sshCmd = &cobra.Command{
os.Exit(1)
}
defer api.Close()
host, err := cluster.CheckIfApiExistsAndLoad(api)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting host: %s\n", err)
os.Exit(1)
}
if host.Driver.DriverName() == "none" {
fmt.Println(`'none' driver does not support 'minikube ssh' command`)
os.Exit(0)
}
err = cluster.CreateSSHShell(api, args)
if err != nil {
glog.Errorln(errors.Wrap(err, "Error attempting to ssh/run-ssh-command"))
Expand Down
28 changes: 22 additions & 6 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -30,9 +31,6 @@ import (
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"io/ioutil"

cmdUtil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube/cluster"
cfg "k8s.io/minikube/pkg/minikube/config"
Expand Down Expand Up @@ -152,8 +150,8 @@ func runStart(cmd *cobra.Command, args []string) {
ExtraOptions: extraOptions,
}

fmt.Println("SSH-ing files into VM...")
if err := cluster.UpdateCluster(host, host.Driver, kubernetesConfig); err != nil {
fmt.Println("Moving files into cluster...")
if err := cluster.UpdateCluster(host.Driver, kubernetesConfig); err != nil {
glog.Errorln("Error updating cluster: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
Expand All @@ -165,7 +163,8 @@ func runStart(cmd *cobra.Command, args []string) {
}

fmt.Println("Starting cluster components...")
if err := cluster.StartCluster(host, kubernetesConfig); err != nil {

if err := cluster.StartCluster(api, kubernetesConfig); err != nil {
glog.Errorln("Error starting cluster: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
Expand Down Expand Up @@ -237,6 +236,23 @@ func runStart(cmd *cobra.Command, args []string) {
} else {
fmt.Println("Kubectl is now configured to use the cluster.")
}

if config.VMDriver == "none" {
fmt.Println(`===================
WARNING: IT IS RECOMMENDED NOT TO RUN THE NONE DRIVER ON PERSONAL WORKSTATIONS
The 'none' driver will run an insecure kubernetes apiserver as root that may leave the host vulnerable to CSRF attacks
When using the none driver, the kubectl config and credentials generated will be root owned and will appear in the root home directory.
You will need to move the files to the appropriate location and then set the correct permissions. An example of this is below:
sudo mv /root/.kube $HOME/.kube # this will overwrite any config you have. You may have to append the file contents manually
sudo chown -R $USER $HOME/.kube
sudo chgrp -R $USER $HOME/.kube
sudo mv /root/.minikube $HOME/.minikube # this will overwrite any config you have. You may have to append the file contents manually
sudo chown -R $USER $HOME/.minikube
sudo chgrp -R $USER $HOME/.minikube
This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true`)
}
}

func validateK8sVersion(version string) {
Expand Down
12 changes: 7 additions & 5 deletions cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ var statusCmd = &cobra.Command{
os.Exit(1)
}
defer api.Close()

ms, err := cluster.GetHostStatus(api)
if err != nil {
glog.Errorln("Error getting machine status:", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
ls := "N/A"

ls := state.None.String()
if ms == state.Running.String() {
ls, err = cluster.GetLocalkubeStatus(api)
}
if err != nil {
glog.Errorln("Error getting machine status:", err)
cmdUtil.MaybeReportErrorAndExit(err)
if err != nil {
glog.Errorln("Error localkube status:", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
}
status := Status{ms, ls}

Expand Down
4 changes: 3 additions & 1 deletion hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ MINIKUBE_WANTREPORTERRORPROMPT=False sudo ./out/minikube-${OS_ARCH} delete \
|| MINIKUBE_WANTREPORTERRORPROMPT=False ./out/minikube-${OS_ARCH} delete \
|| true
sudo rm -rf $HOME/.minikube || true
sudo rm -rf $HOME/.kube || true

# See the default image
./out/minikube-${OS_ARCH} start -h | grep iso

# Allow this to fail, we'll switch on the return code below.
set +e
out/e2e-${OS_ARCH} -minikube-args="--vm-driver=${VM_DRIVER} --v=10" -test.v -test.timeout=30m -binary=out/minikube-${OS_ARCH}
${SUDO_PREFIX}out/e2e-${OS_ARCH} -minikube-args="--vm-driver=${VM_DRIVER} --v=10" -test.v -test.timeout=30m -binary=out/minikube-${OS_ARCH}
result=$?
set -e

MINIKUBE_WANTREPORTERRORPROMPT=False sudo ./out/minikube-${OS_ARCH} delete \
|| MINIKUBE_WANTREPORTERRORPROMPT=False ./out/minikube-${OS_ARCH} delete \
|| true
sudo rm -rf $HOME/.minikube || true
sudo rm -rf $HOME/.kube || true

if [[ $result -eq 0 ]]; then
status="success"
Expand Down
36 changes: 36 additions & 0 deletions hack/jenkins/linux_integration_tests_none.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Copyright 2016 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.


# This script runs the integration tests on a Linux machine for the Virtualbox Driver

# The script expects the following env variables:
# MINIKUBE_LOCATION: GIT_COMMIT from upstream build.
# COMMIT: Actual commit ID from upstream build
# EXTRA_BUILD_ARGS (optional): Extra args to be passed into the minikube integrations tests
# access_token: The Github API access token. Injected by the Jenkins credential provider.


set -e

OS_ARCH="linux-amd64"
VM_DRIVER="none"
JOB_NAME="Linux-None"
EXTRA_BUILD_ARGS="$EXTRA_BUILD_ARGS --use-vendored-driver"
SUDO_PREFIX="sudo "

# Download files and set permissions
source common.sh
48 changes: 48 additions & 0 deletions pkg/minikube/assets/vm_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"bytes"
"io"
"os"
"os/user"
"path/filepath"
"strconv"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -135,3 +138,48 @@ func (m *MemoryAsset) GetLength() int {
func (m *MemoryAsset) Read(p []byte) (int, error) {
return m.reader.Read(p)
}

func CopyFileLocal(f CopyableFile) error {
os.MkdirAll(f.GetTargetDir(), os.ModePerm)
targetPath := filepath.Join(f.GetTargetDir(), f.GetTargetName())
os.Remove(targetPath)
target, err := os.Create(targetPath)
defer target.Close()

perms, err := strconv.Atoi(f.GetPermissions())
if err != nil {
return errors.Wrap(err, "Error converting permissions to integer")
}
target.Chmod(os.FileMode(perms))
if err != nil {
return errors.Wrap(err, "Error changing file permissions")
}

_, err = io.Copy(target, f)
if err != nil {
return errors.Wrap(err, "Error copying file to target location")
}

if os.Getenv("CHANGE_MINIKUBE_NONE_USER") != "" {
username := os.Getenv("SUDO_USER")
if username == "" {
return nil
}
usr, err := user.Lookup(username)
if err != nil {
return errors.Wrap(err, "Error looking up user")
}
uid, err := strconv.Atoi(usr.Uid)
if err != nil {
return errors.Wrapf(err, "Error parsing uid for user: %s", username)
}
gid, err := strconv.Atoi(usr.Gid)
if err != nil {
return errors.Wrapf(err, "Error parsing gid for user: %s", username)
}
if err := os.Chown(targetPath, uid, gid); err != nil {
return errors.Wrapf(err, "Error changing ownership for: %s", targetPath)
}
}
return nil
}
Loading

0 comments on commit a7c2ff3

Please sign in to comment.