提交 53e80a9c 编写于 作者: A aprindle 提交者: Aaron Prindle

Changed kubernetes-version to take k8s version as input (as well as

url) and to copy files from host to the vm instead of curl within vm.
Also made it so that sshutil.Transfer is done via a Reader.
上级 d7308217
......@@ -37,7 +37,7 @@ BUILD_OS := $(shell uname -s)
# Set the version information for the Kubernetes servers, and build localkube statically
K8S_VERSION_LDFLAGS := $(shell $(PYTHON) hack/get_k8s_version.py 2>&1)
MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION)
MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION) $(K8S_VERSION_LDFLAGS)
LOCALKUBE_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w -extldflags '-static'"
MKGOPATH := if [ ! -e $(GOPATH)/src/$(ORG) ]; then mkdir -p $(GOPATH)/src/$(ORG) && ln -s -f $(shell pwd) $(GOPATH)/src/$(ORG); fi
......
......@@ -71,7 +71,6 @@ func runStart(cmd *cobra.Command, args []string) {
KubernetesVersion: kubernetesVersion,
}
fmt.Println(config.DiskSize)
var host *host.Host
start := func() (err error) {
host, err = cluster.StartHost(api, config)
......
......@@ -20,7 +20,7 @@ minikube start
--docker-env=[]: Environment variables to pass to the Docker daemon. (format: key=value)
--insecure-registry=[]: Insecure Docker registries to pass to the Docker daemon
--iso-url="https://storage.googleapis.com/minikube/minikube-0.5.iso": Location of the minikube iso
--kubernetes-version="": The kubernetes version that the minikube VM will run
--kubernetes-version="v1.3.0+$Format:%h$": The kubernetes version that the minikube VM will run
--memory=1024: Amount of RAM allocated to the minikube VM
--vm-driver="virtualbox": VM driver is one of: [virtualbox vmwarefusion kvm xhyve]
```
......
......@@ -17,6 +17,7 @@ limitations under the License.
package cluster
import (
"bytes"
"encoding/json"
"flag"
"fmt"
......@@ -232,24 +233,29 @@ func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error {
return err
}
if localkubeURLWasSpecified(config) {
cmd := GetLocalkubeDownloadCommand(config.KubernetesVersion)
glog.Infoln(cmd)
output, err := h.RunSSHCommand(cmd)
glog.Infoln(output)
resp, err := http.Get(util.GetLocalkubeDownloadURL(config.KubernetesVersion,
constants.LocalkubeLinuxFilename))
if err != nil {
return err
}
if err := sshutil.Transfer(resp.Body, int(resp.ContentLength), "/usr/local/bin",
"localkube", "0777",
client); err != nil {
return err
}
} else {
contents, err := Asset("out/localkube")
if err != nil {
glog.Infof("Error loading asset %s: %s", "out/localkube", err)
glog.Infof("Error loading asset out/localkube: %s", err)
return err
}
if err := sshutil.Transfer(contents, "/usr/local/bin", "localkube", "0777", client); err != nil {
if err := sshutil.Transfer(bytes.NewReader(contents), len(contents), "/usr/local/bin",
"localkube", "0777", client); err != nil {
return err
}
}
for _, a := range assets {
contents, err := Asset(a.AssetName)
if err != nil {
......@@ -257,7 +263,7 @@ func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error {
return err
}
if err := sshutil.Transfer(contents, a.TargetDir, a.TargetName, a.Permissions, client); err != nil {
if err := sshutil.Transfer(bytes.NewReader(contents), len(contents), a.TargetDir, a.TargetName, a.Permissions, client); err != nil {
return err
}
}
......@@ -266,10 +272,7 @@ func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error {
func localkubeURLWasSpecified(config KubernetesConfig) bool {
//see if flag is different than default -> it was passed by user
if config.KubernetesVersion != constants.DefaultKubernetesVersion {
return true
}
return false
return config.KubernetesVersion != constants.DefaultKubernetesVersion
}
// SetupCerts gets the generated credentials required to talk to the APIServer.
......@@ -305,7 +308,7 @@ func SetupCerts(d drivers.Driver) error {
if strings.HasSuffix(cert, ".key") {
perms = "0600"
}
if err := sshutil.Transfer(data, util.DefaultCertPath, cert, perms, client); err != nil {
if err := sshutil.Transfer(bytes.NewReader(data), len(data), util.DefaultCertPath, cert, perms, client); err != nil {
return err
}
}
......
......@@ -19,6 +19,7 @@ package cluster
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
......@@ -542,14 +543,14 @@ func TestUpdateDefault(t *testing.T) {
if !bytes.Contains(transferred, contents) {
t.Fatalf("File not copied. Expected transfers to contain: %s. It was: %s", contents, transferred)
}
//TODO: aprindle: add test for localkube versioning
}
var test_localkube_binary = "hello"
type K8sVersionHandlerCorrect struct{}
func (h *K8sVersionHandlerCorrect) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "test/test-localkube")
io.WriteString(w, test_localkube_binary)
}
func TestUpdateKubernetesVersion(t *testing.T) {
......@@ -580,9 +581,8 @@ func TestUpdateKubernetesVersion(t *testing.T) {
transferred := s.Transfers.Bytes()
//test that localkube is transferred properly
contents, _ := Asset("test/test-localkube")
contents := []byte(test_localkube_binary)
if !bytes.Contains(transferred, contents) {
t.Fatalf("File not copied. Expected transfers to contain: %s. It was: %s", contents, transferred)
}
}
......@@ -31,9 +31,6 @@ var startCommandFmtStr = `
# Run with nohup so it stays up. Redirect logs to useful places.
sudo sh -c 'PATH=/usr/local/sbin:$PATH nohup /usr/local/bin/localkube %s --generate-certs=false --logtostderr=true > %s 2> %s < /dev/null &'
`
var localkubeDownloadFmtStr = `sudo curl -sSL --retry 5 -o /usr/local/bin/localkube %s && sudo chmod 0777 /usr/local/bin/localkube`
var logsCommand = fmt.Sprintf("tail -n +1 %s %s", constants.RemoteLocalKubeErrPath, constants.RemoteLocalKubeOutPath)
func GetStartCommand() string {
......@@ -46,7 +43,3 @@ func GetStartCommand() string {
flags := strings.Join(flagVals, " ")
return fmt.Sprintf(startCommandFmtStr, flags, constants.RemoteLocalKubeErrPath, constants.RemoteLocalKubeOutPath)
}
func GetLocalkubeDownloadCommand(versionUrl string) string {
return fmt.Sprintf(localkubeDownloadFmtStr, versionUrl)
}
......@@ -17,7 +17,9 @@ limitations under the License.
package constants
import (
"fmt"
"path/filepath"
"strings"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/util/homedir"
......@@ -66,3 +68,11 @@ const (
RemoteLocalKubeErrPath = "/var/lib/localkube/localkube.err"
RemoteLocalKubeOutPath = "/var/lib/localkube/localkube.out"
)
<<<<<<< 77c0a09495682fa6ae6a74f0363053d2330e86be
=======
var ConfigFilePath = MakeMiniPath("config")
var LocalkubeDownloadURLPrefix = "https://storage.googleapis.com/minikube/k8sReleases/"
var LocalkubeLinuxFilename = "localkube-linux-amd64"
>>>>>>> Changed kubernetes-version to take k8s version as input (as well as
......@@ -17,7 +17,6 @@ limitations under the License.
package sshutil
import (
"bytes"
"fmt"
"io"
"path/filepath"
......@@ -60,7 +59,7 @@ func NewSSHClient(d drivers.Driver) (*ssh.Client, error) {
}
// Transfer uses an SSH session to copy a file to the remote machine.
func Transfer(data []byte, remotedir, filename string, perm string, c *ssh.Client) error {
func Transfer(reader io.Reader, readerLen int, remotedir, filename string, perm string, c *ssh.Client) error {
// Delete the old file first. This makes sure permissions get reset.
deleteCmd := fmt.Sprintf("sudo rm -f %s", filepath.Join(remotedir, filename))
mkdirCmd := fmt.Sprintf("sudo mkdir -p %s", remotedir)
......@@ -86,9 +85,8 @@ func Transfer(data []byte, remotedir, filename string, perm string, c *ssh.Clien
go func() {
defer wg.Done()
defer w.Close()
header := fmt.Sprintf("C%s %d %s\n", perm, len(data), filename)
header := fmt.Sprintf("C%s %d %s\n", perm, readerLen, filename)
fmt.Fprint(w, header)
reader := bytes.NewReader(data)
io.Copy(w, reader)
fmt.Fprint(w, "\x00")
}()
......
......@@ -17,6 +17,7 @@ limitations under the License.
package sshutil
import (
"bytes"
"testing"
"github.com/docker/machine/libmachine/drivers"
......@@ -109,7 +110,8 @@ func TestTransfer(t *testing.T) {
}
dest := "bar"
if err := Transfer([]byte("testcontents"), "/tmp", dest, "0777", c); err != nil {
contents := []byte("testcontents")
if err := Transfer(bytes.NewReader(contents), len(contents), "/tmp", dest, "0777", c); err != nil {
t.Fatalf("Unexpected error: %s", err)
}
}
......@@ -21,6 +21,8 @@ import (
"io"
"os"
"time"
"k8s.io/minikube/pkg/minikube/constants"
)
// Until endlessly loops the provided function until a message is received on the done channel.
......@@ -76,3 +78,10 @@ func RetryAfter(attempts int, callback func() error, d time.Duration) (err error
}
return err
}
func GetLocalkubeDownloadURL(version string, filename string) string {
if strings.HasPrefix(version, "http://") {
return version
}
return fmt.Sprintf("%s%s/%s", constants.LocalkubeDownloadURLPrefix, version, filename)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册