Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Makefile deploy rule dependency and improve error checking for invalid assets #4203

Merged
merged 4 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/minikube/assets/vm_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package assets

import (
"bytes"
"fmt"
"html/template"
"io"
"os"
"path"

"github.com/golang/glog"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -197,6 +199,10 @@ func (m *BinDataAsset) loadData(isTemplate bool) error {
m.data = contents
m.Length = len(contents)
m.reader = bytes.NewReader(m.data)
glog.Infof("Created asset %s with %d bytes", m.AssetName, m.Length)
if m.Length == 0 {
return fmt.Errorf("%s is an empty asset", m.AssetName)
}
return nil
}

Expand Down Expand Up @@ -227,5 +233,8 @@ func (m *BinDataAsset) GetLength() int {

// Read reads the asset
func (m *BinDataAsset) Read(p []byte) (int, error) {
if m.Length == 0 {
return 0, fmt.Errorf("attempted read from a 0 length asset")
}
return m.reader.Read(p)
}
22 changes: 20 additions & 2 deletions pkg/minikube/bootstrapper/ssh_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,30 @@ func (s *SSHRunner) Copy(f assets.CopyableFile) error {
// StdinPipe is closed. But let's use a WaitGroup to make it expicit.
var wg sync.WaitGroup
wg.Add(1)
var ierr error
var copied int64

go func() {
defer wg.Done()
defer w.Close()
glog.Infof("Transferring %d bytes to %s", f.GetLength(), f.GetTargetName())
header := fmt.Sprintf("C%s %d %s\n", f.GetPermissions(), f.GetLength(), f.GetTargetName())
fmt.Fprint(w, header)
io.Copy(w, f)
if f.GetLength() == 0 {
glog.Warningf("%s is a 0 byte asset!", f.GetTargetName())
fmt.Fprint(w, "\x00")
return
}

copied, ierr = io.Copy(w, f)
if copied != int64(f.GetLength()) {
glog.Warningf("%s: expected to copy %d bytes, but copied %d instead", f.GetTargetName(), f.GetLength(), copied)
} else {
glog.Infof("%s: copied %d bytes", f.GetTargetName(), copied)
}
if ierr != nil {
glog.Errorf("io.Copy failed: %v", ierr)
}
fmt.Fprint(w, "\x00")
}()

Expand All @@ -187,5 +205,5 @@ func (s *SSHRunner) Copy(f assets.CopyableFile) error {
return err
}
wg.Wait()
return nil
return ierr
}