From ac14eff5549ac3cc7b9ceee3b0bde785d61750df Mon Sep 17 00:00:00 2001 From: dlorenc Date: Thu, 9 Jun 2016 11:38:33 -0700 Subject: [PATCH] Move the addon-manager and dashboard configuration from the iso to minikube. Minikube now copies these into the VM, just like it copies in localkube. New ISOs will not contain these files, but this is compatible with the existing ISO because minikube will overwrite existing files. --- .gitignore | 2 +- Makefile | 10 ++--- deploy/iso/Dockerfile | 5 --- deploy/iso/build.sh | 2 - pkg/minikube/cluster/cluster.go | 54 +++++++++++++++++++---- pkg/minikube/cluster/cluster_test.go | 28 ++++++++++++ pkg/minikube/tests/ssh_mock.go | 64 ++++++++++++++-------------- test.sh | 2 +- 8 files changed, 113 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index aa17e102b5..f39754f19a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,5 +26,5 @@ _testmain.go /out /_gopath -/pkg/minikube/cluster/localkubecontents.go +/pkg/minikube/cluster/assets.go /minikube diff --git a/Makefile b/Makefile index 38c5f61c7f..4788a047d6 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ LOCALKUBE_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w -extldfla clean: rm -rf $(GOPATH) rm -rf $(BUILD_DIR) - rm pkg/minikube/cluster/localkubecontents.go + rm pkg/minikube/cluster/assets.go MKGOPATH := mkdir -p $(shell dirname $(GOPATH)/src/$(REPOPATH)) && ln -s -f $(shell pwd) $(GOPATH)/src/$(REPOPATH) @@ -61,7 +61,7 @@ else docker run -w /go/src/$(REPOPATH) -e IN_DOCKER=1 -v $(shell pwd):/go/src/$(REPOPATH) $(BUILD_IMAGE) make out/localkube endif -out/minikube-$(GOOS)-$(GOARCH): $(MINIKUBEFILES) pkg/minikube/cluster/localkubecontents.go +out/minikube-$(GOOS)-$(GOARCH): $(MINIKUBEFILES) pkg/minikube/cluster/assets.go $(MKGOPATH) CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) go build --installsuffix cgo -ldflags="$(MINIKUBE_LDFLAGS)" -a -o $(BUILD_DIR)/minikube-$(GOOS)-$(GOARCH) ./cmd/minikube @@ -76,12 +76,12 @@ integration: out/minikube go test -v $(REPOPATH)/test/integration --tags=integration .PHONY: test -test: pkg/minikube/cluster/localkubecontents.go +test: pkg/minikube/cluster/assets.go $(MKGOPATH) ./test.sh -pkg/minikube/cluster/localkubecontents.go: out/localkube $(GOPATH)/bin/go-bindata - $(GOPATH)/bin/go-bindata -nomemcopy -o pkg/minikube/cluster/localkubecontents.go -pkg cluster ./out/localkube +pkg/minikube/cluster/assets.go: out/localkube $(GOPATH)/bin/go-bindata deploy/iso/addon-manager.yaml deploy/addons/dashboard-rc.yaml deploy/addons/dashboard-svc.yaml + $(GOPATH)/bin/go-bindata -nomemcopy -o pkg/minikube/cluster/assets.go -pkg cluster ./out/localkube deploy/iso/addon-manager.yaml deploy/addons/dashboard-rc.yaml deploy/addons/dashboard-svc.yaml $(GOPATH)/bin/go-bindata: $(MKGOPATH) diff --git a/deploy/iso/Dockerfile b/deploy/iso/Dockerfile index 9145994803..4bc01d0955 100644 --- a/deploy/iso/Dockerfile +++ b/deploy/iso/Dockerfile @@ -26,11 +26,6 @@ ADD socat $ROOTFS/usr/bin ADD ethtool $ROOTFS/usr/bin ADD conntrack $ROOTFS/usr/bin -# Add addons -ADD addon-manager.yaml $ROOTFS/etc/kubernetes/manifests/ -ADD dashboard-rc.yaml $ROOTFS/etc/kubernetes/addons/ -ADD dashboard-svc.yaml $ROOTFS/etc/kubernetes/addons/ - # Get a specific version of Docker. This will overwrite the binary installed # in the base image. # The --strip-components=3 flag will have to change as we switch docker versions diff --git a/deploy/iso/build.sh b/deploy/iso/build.sh index f1a67e2188..a9769d9af6 100755 --- a/deploy/iso/build.sh +++ b/deploy/iso/build.sh @@ -20,8 +20,6 @@ ISO=minikube.iso tmpdir=$(mktemp -d) echo "Building in $tmpdir." cp -r . $tmpdir/ -# Copy in the addons -cp ../addons/* $tmpdir/ pushd $tmpdir diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index 69daa139ee..22c982aa7f 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -173,21 +173,57 @@ func StartCluster(h sshAble) error { return nil } -func UpdateCluster(d drivers.Driver) error { - localkube, err := Asset("out/localkube") - if err != nil { - glog.Infoln("Error loading localkube: ", err) - return err - } +type fileToCopy struct { + AssetName string + TargetDir string + TargetName string + Permissions string +} +var assets = []fileToCopy{ + { + AssetName: "out/localkube", + TargetDir: "/usr/local/bin", + TargetName: "localkube", + Permissions: "0777", + }, + { + AssetName: "deploy/iso/addon-manager.yaml", + TargetDir: "/etc/kubernetes/manifests/", + TargetName: "addon-manager.yaml", + Permissions: "0640", + }, + { + AssetName: "deploy/addons/dashboard-rc.yaml", + TargetDir: "/etc/kubernetes/addons/", + TargetName: "dashboard-rc.yaml", + Permissions: "0640", + }, + { + AssetName: "deploy/addons/dashboard-svc.yaml", + TargetDir: "/etc/kubernetes/addons/", + TargetName: "dashboard-svc.yaml", + Permissions: "0640", + }, +} + +func UpdateCluster(d drivers.Driver) error { client, err := sshutil.NewSSHClient(d) if err != nil { return err } - if err := sshutil.Transfer(localkube, "/usr/local/bin/", "localkube", "0777", client); err != nil { - return err - } + for _, a := range assets { + contents, err := Asset(a.AssetName) + if err != nil { + glog.Infof("Error loading asset %s: %s", a.AssetName, err) + return err + } + + if err := sshutil.Transfer(contents, a.TargetDir, a.TargetName, a.Permissions, client); err != nil { + return err + } + } return nil } diff --git a/pkg/minikube/cluster/cluster_test.go b/pkg/minikube/cluster/cluster_test.go index 20445ac9a4..52ec3c159b 100644 --- a/pkg/minikube/cluster/cluster_test.go +++ b/pkg/minikube/cluster/cluster_test.go @@ -459,3 +459,31 @@ func TestGetDashboardURL(t *testing.T) { } } + +func TestUpdate(t *testing.T) { + s, _ := tests.NewSSHServer() + port, err := s.Start() + if err != nil { + t.Fatalf("Error starting ssh server: %s", err) + } + + d := &tests.MockDriver{ + Port: port, + BaseDriver: drivers.BaseDriver{ + IPAddress: "127.0.0.1", + SSHKeyPath: "", + }, + } + + if err := UpdateCluster(d); err != nil { + t.Fatalf("Error updating cluster: %s", err) + } + transferred := s.Transfers.Bytes() + + for _, a := range assets { + contents, _ := Asset(a.AssetName) + if !bytes.Contains(transferred, contents) { + t.Fatalf("File not copied. Expected transfers to contain: %s. It was: %s", contents, transferred) + } + } +} diff --git a/pkg/minikube/tests/ssh_mock.go b/pkg/minikube/tests/ssh_mock.go index 58a6a4c36b..fbad6a6225 100644 --- a/pkg/minikube/tests/ssh_mock.go +++ b/pkg/minikube/tests/ssh_mock.go @@ -74,44 +74,46 @@ func (s *SSHServer) Start() (int, error) { go func() { for { nConn, err := listener.Accept() - if err != nil { - return - } - - _, chans, reqs, err := ssh.NewServerConn(nConn, s.Config) - if err != nil { - return - } - // The incoming Request channel must be serviced. - go ssh.DiscardRequests(reqs) - - // Service the incoming Channel channel. - for newChannel := range chans { - if newChannel.ChannelType() == "session" { - s.HadASessionRequested = true - } - channel, requests, err := newChannel.Accept() - s.Connected = true + go func() { if err != nil { return } - req := <-requests - req.Reply(true, nil) - - //Note: string(req.Payload) adds additional characters to start of input, execRequest used to solve this issue - var cmd execRequest - if err := ssh.Unmarshal(req.Payload, &cmd); err != nil { - glog.Errorln("Unmarshall encountered error: %s", err) + _, chans, reqs, err := ssh.NewServerConn(nConn, s.Config) + if err != nil { return } - s.Commands[cmd.Command] = 1 - channel.SendRequest("exit-status", false, []byte{0, 0, 0, 0}) + // The incoming Request channel must be serviced. + go ssh.DiscardRequests(reqs) - // Store anything that comes in over stdin. - io.Copy(s.Transfers, channel) - channel.Close() - } + // Service the incoming Channel channel. + for newChannel := range chans { + if newChannel.ChannelType() == "session" { + s.HadASessionRequested = true + } + channel, requests, err := newChannel.Accept() + s.Connected = true + if err != nil { + return + } + + req := <-requests + req.Reply(true, nil) + + //Note: string(req.Payload) adds additional characters to start of input, execRequest used to solve this issue + var cmd execRequest + if err := ssh.Unmarshal(req.Payload, &cmd); err != nil { + glog.Errorln("Unmarshall encountered error: %s", err) + return + } + s.Commands[cmd.Command] = 1 + channel.SendRequest("exit-status", false, []byte{0, 0, 0, 0}) + + // Store anything that comes in over stdin. + io.Copy(s.Transfers, channel) + channel.Close() + } + }() } }() diff --git a/test.sh b/test.sh index 337b823bdf..896c3af9ce 100755 --- a/test.sh +++ b/test.sh @@ -32,7 +32,7 @@ TESTS=$(go list -f '{{ if .TestGoFiles }} {{.ImportPath}} {{end}}' ./...) go test -v ${TESTS} # Ignore these paths in the following tests. -ignore="vendor\|\_gopath\|localkubecontents.go" +ignore="vendor\|\_gopath\|assets.go" # Check gofmt echo "Checking gofmt..."