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

Improve error reporting when invoking weave script #2335

Merged
merged 4 commits into from
Mar 21, 2017
Merged
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
30 changes: 24 additions & 6 deletions common/weave/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -164,7 +165,11 @@ func (c *client) AddDNSEntry(fqdn, containerID string, ip net.IP) error {

func (c *client) PS() (map[string]PSEntry, error) {
cmd := weaveCommand("--local", "ps")
out, err := cmd.StdoutPipe()
stdOut, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
stdErr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
Expand All @@ -173,7 +178,7 @@ func (c *client) PS() (map[string]PSEntry, error) {
}

psEntriesByPrefix := map[string]PSEntry{}
scanner := bufio.NewScanner(out)
scanner := bufio.NewScanner(stdOut)
for scanner.Scan() {
line := scanner.Text()
groups := weavePsMatch.FindStringSubmatch(line)
Expand All @@ -193,7 +198,8 @@ func (c *client) PS() (map[string]PSEntry, error) {
scannerErr := scanner.Err()
cmdErr := cmd.Wait()
if cmdErr != nil {
return nil, cmdErr
slurp, _ := ioutil.ReadAll(stdErr)
return nil, fmt.Errorf("%s: %q", cmdErr, slurp)
}
if scannerErr != nil {
return nil, scannerErr
Expand All @@ -202,17 +208,29 @@ func (c *client) PS() (map[string]PSEntry, error) {
}

func (c *client) Expose() error {
output, err := weaveCommand("--local", "ps", "weave:expose").Output()
cmd := weaveCommand("--local", "ps", "weave:expose")
stdErr, err := cmd.StderrPipe()
if err != nil {
return err
}
output, err := cmd.Output()
if err != nil {
slurp, _ := ioutil.ReadAll(stdErr)
return fmt.Errorf("Error running weave ps: %s: %q", err, slurp)
}
ips := ipMatch.FindAllSubmatch(output, -1)
if ips != nil {
// Alread exposed!
return nil
}
if err := weaveCommand("--local", "expose").Run(); err != nil {
return fmt.Errorf("Error running weave expose: %v", err)
cmd = weaveCommand("--local", "expose")
stdErr, err = cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
slurp, _ := ioutil.ReadAll(stdErr)
return fmt.Errorf("Error running weave expose: %s: %q", err, slurp)
}
return nil
}
Expand Down