Working build, scp of localkube to the VM.
parent
92d0c94d7b
commit
5eaae409aa
|
@ -25,3 +25,5 @@ _testmain.go
|
||||||
|
|
||||||
/out
|
/out
|
||||||
/.gopath
|
/.gopath
|
||||||
|
|
||||||
|
pkg/minikube/cluster/localkubecontents.go
|
8
Makefile
8
Makefile
|
@ -54,3 +54,11 @@ docker/localkube:
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: gopath
|
test: gopath
|
||||||
./test.sh
|
./test.sh
|
||||||
|
|
||||||
|
docker/minikube-full: docker/localkube-incremental
|
||||||
|
go-bindata -nomemcopy -o pkg/minikube/cluster/localkubecontents.go -pkg cluster ./out/localkube
|
||||||
|
make minikube
|
||||||
|
|
||||||
|
minikube-full: localkube
|
||||||
|
go-bindata -nomemcopy -o pkg/minikube/cluster/localkubecontents.go -pkg cluster ./out/localkube
|
||||||
|
make minikube
|
|
@ -56,6 +56,11 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
LocalkubeURL: localkubeURL,
|
LocalkubeURL: localkubeURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := cluster.UpdateCluster(host.Driver); err != nil {
|
||||||
|
log.Println("Error updating cluster: ", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
if err := cluster.StartCluster(host, config); err != nil {
|
if err := cluster.StartCluster(host, config); err != nil {
|
||||||
log.Println("Error starting cluster: ", err)
|
log.Println("Error starting cluster: ", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -27,9 +27,11 @@ import (
|
||||||
|
|
||||||
"github.com/docker/machine/drivers/virtualbox"
|
"github.com/docker/machine/drivers/virtualbox"
|
||||||
"github.com/docker/machine/libmachine"
|
"github.com/docker/machine/libmachine"
|
||||||
|
"github.com/docker/machine/libmachine/drivers"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
"github.com/docker/machine/libmachine/state"
|
"github.com/docker/machine/libmachine/state"
|
||||||
"k8s.io/minikube/pkg/minikube/constants"
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
|
"k8s.io/minikube/pkg/minikube/sshutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -145,7 +147,7 @@ type KubernetesConfig struct {
|
||||||
|
|
||||||
// StartCluster starts a k8s cluster on the specified Host.
|
// StartCluster starts a k8s cluster on the specified Host.
|
||||||
func StartCluster(h sshAble, config KubernetesConfig) error {
|
func StartCluster(h sshAble, config KubernetesConfig) error {
|
||||||
output, err := h.RunSSHCommand(getStartCommand(config.LocalkubeURL))
|
output, err := h.RunSSHCommand(getStartCommand())
|
||||||
log.Println(output)
|
log.Println(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -154,6 +156,20 @@ func StartCluster(h sshAble, config KubernetesConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateCluster(d drivers.Driver) error {
|
||||||
|
localkube, err := Asset("out/localkube")
|
||||||
|
if err != nil {
|
||||||
|
log.Println("error loadking localkube: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := sshutil.NewSSHClient(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return sshutil.Transfer(localkube, "/usr/local/bin/", "localkube", "0777", client)
|
||||||
|
}
|
||||||
|
|
||||||
// GetCreds gets the generated credentials required to talk to the APIServer.
|
// GetCreds gets the generated credentials required to talk to the APIServer.
|
||||||
func GetCreds(h sshAble) error {
|
func GetCreds(h sshAble) error {
|
||||||
localPath := constants.Minipath
|
localPath := constants.Minipath
|
||||||
|
|
|
@ -1,17 +1,10 @@
|
||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import "fmt"
|
var startCommand = `
|
||||||
|
|
||||||
var startCommand = `sudo killall localkube || true
|
|
||||||
# Download and install localkube, if it doesn't exist yet.
|
|
||||||
if [ ! -e /usr/local/bin/localkube ]; then
|
|
||||||
sudo curl --compressed -L %s -o /usr/local/bin/localkube
|
|
||||||
sudo chmod a+x /usr/local/bin/localkube
|
|
||||||
fi
|
|
||||||
# Run with nohup so it stays up. Redirect logs to useful places.
|
# Run with nohup so it stays up. Redirect logs to useful places.
|
||||||
PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube start > /var/log/localkube.out 2> /var/log/localkube.err < /dev/null &
|
PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube start > /var/log/localkube.out 2> /var/log/localkube.err < /dev/null &
|
||||||
`
|
`
|
||||||
|
|
||||||
func getStartCommand(localkubeURL string) string {
|
func getStartCommand() string {
|
||||||
return fmt.Sprintf(startCommand, localkubeURL)
|
return startCommand
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,10 @@ limitations under the License.
|
||||||
package sshutil
|
package sshutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/docker/machine/libmachine/drivers"
|
"github.com/docker/machine/libmachine/drivers"
|
||||||
machinessh "github.com/docker/machine/libmachine/ssh"
|
machinessh "github.com/docker/machine/libmachine/ssh"
|
||||||
|
@ -31,12 +31,12 @@ import (
|
||||||
type SSHSession interface {
|
type SSHSession interface {
|
||||||
Close() error
|
Close() error
|
||||||
StdinPipe() (io.WriteCloser, error)
|
StdinPipe() (io.WriteCloser, error)
|
||||||
Start(cmd string) error
|
Run(cmd string) error
|
||||||
Wait() error
|
Wait() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSSHSession returns an SSHSession object for running commands.
|
// NewSSHClient returns an SSH client object for running commands.
|
||||||
func NewSSHSession(d drivers.Driver) (SSHSession, error) {
|
func NewSSHClient(d drivers.Driver) (*ssh.Client, error) {
|
||||||
h, err := newSSHHost(d)
|
h, err := newSSHHost(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -55,37 +55,51 @@ func NewSSHSession(d drivers.Driver) (SSHSession, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
session, err := client.NewSession()
|
return client, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return session, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer uses an SSH session to copy a file to the remote machine.
|
// Transfer uses an SSH session to copy a file to the remote machine.
|
||||||
func Transfer(localpath, remotepath string, r SSHSession) error {
|
func Transfer(data []byte, remotedir, filename string, perm string, c *ssh.Client) error {
|
||||||
f, err := os.Open(localpath)
|
// Delete the old file first. This makes sure permissions get reset.
|
||||||
if err != nil {
|
deleteCmd := fmt.Sprintf("sudo rm -f %s", filepath.Join(remotedir, filename))
|
||||||
|
if err := runCommand(c, deleteCmd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
reader := bufio.NewReader(f)
|
|
||||||
|
|
||||||
cmd := fmt.Sprintf("cat > %s", remotepath)
|
s, err := c.NewSession()
|
||||||
stdin, err := r.StdinPipe()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.Start(cmd); err != nil {
|
go func() {
|
||||||
|
w, err := s.StdinPipe()
|
||||||
|
defer w.Close()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
header := fmt.Sprintf("C%s %d %s\n", perm, len(data), filename)
|
||||||
|
fmt.Fprint(w, header)
|
||||||
|
reader := bytes.NewReader(data)
|
||||||
|
io.Copy(w, reader)
|
||||||
|
fmt.Fprint(w, "\x00")
|
||||||
|
}()
|
||||||
|
|
||||||
|
scpcmd := fmt.Sprintf("sudo /usr/local/bin/scp -t %s", remotedir)
|
||||||
|
if err := s.Run(scpcmd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = io.Copy(stdin, reader)
|
|
||||||
stdin.Close()
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCommand(c *ssh.Client, cmd string) error {
|
||||||
|
s, err := c.NewSession()
|
||||||
|
defer s.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Wait()
|
return s.Run(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshHost struct {
|
type sshHost struct {
|
||||||
|
|
Loading…
Reference in New Issue