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

Use filepath instead of path when possible #1073

Merged
merged 1 commit into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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: 5 additions & 4 deletions cmd/sonobuoy/app/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ import (
"os"
"os/signal"
"path"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vmware-tanzu/sonobuoy/pkg/errlog"
"github.com/vmware-tanzu/sonobuoy/pkg/plugin"
"github.com/vmware-tanzu/sonobuoy/pkg/plugin/aggregation"
"github.com/vmware-tanzu/sonobuoy/pkg/worker"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// NewCmdWorker is the cobra command that acts as the entrypoint for Sonobuoy when running
Expand Down Expand Up @@ -163,7 +164,7 @@ func runGather(global bool) error {
}

go worker.RelayProgressUpdates(cfg.ProgressUpdatesPort, progressURL.String(), client)
err = worker.GatherResults(cfg.ResultsDir+"/done", resultURL.String(), client, sigHandler(plugin.GracefulShutdownPeriod*time.Second))
err = worker.GatherResults(filepath.Join(cfg.ResultsDir, "done"), resultURL.String(), client, sigHandler(plugin.GracefulShutdownPeriod*time.Second))

return errors.Wrap(err, "gathering results")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

"github.com/vmware-tanzu/sonobuoy/pkg/config"
pluginaggregation "github.com/vmware-tanzu/sonobuoy/pkg/plugin/aggregation"
"github.com/pkg/errors"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/remotecommand"
Expand Down Expand Up @@ -142,7 +142,7 @@ func UntarAll(reader io.Reader, destFile, prefix string) (filenames []string, re
entrySeq++
mode := header.FileInfo().Mode()
outFileName := path.Join(destFile, header.Name[len(prefix):])
baseName := path.Dir(outFileName)
baseName := filepath.Dir(outFileName)
if err := os.MkdirAll(baseName, 0755); err != nil {
return filenames, err
}
Expand All @@ -160,7 +160,7 @@ func UntarAll(reader io.Reader, destFile, prefix string) (filenames []string, re
return filenames, err
}
if exists {
outFileName = filepath.Join(outFileName, path.Base(header.Name))
outFileName = filepath.Join(outFileName, filepath.Base(header.Name))
}
}

Expand Down
36 changes: 18 additions & 18 deletions pkg/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"net/http/httptest"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -52,14 +52,14 @@ func TestRun(t *testing.T) {
}

withTempDir(t, func(tmpdir string) {
ioutil.WriteFile(tmpdir+"/systemd_logs", []byte("{}"), 0755)
ioutil.WriteFile(tmpdir+"/done", []byte(tmpdir+"/systemd_logs"), 0755)
err := GatherResults(tmpdir+"/done", URL, srv.Client(), nil)
ioutil.WriteFile(filepath.Join(tmpdir, "systemd_logs"), []byte("{}"), 0755)
ioutil.WriteFile(filepath.Join(tmpdir, "done"), []byte(filepath.Join(tmpdir, "systemd_logs")), 0755)
err := GatherResults(filepath.Join(tmpdir, "done"), URL, srv.Client(), nil)
if err != nil {
t.Fatalf("Got error running agent: %v", err)
}

ensureExists(t, path.Join(aggr.OutputDir, "systemd_logs", "results", "node1"))
ensureExists(t, filepath.Join(aggr.OutputDir, "systemd_logs", "results", "node1"))
})
}
})
Expand All @@ -79,14 +79,14 @@ func TestRunGlobal(t *testing.T) {
}

withTempDir(t, func(tmpdir string) {
ioutil.WriteFile(tmpdir+"/systemd_logs.json", []byte("{}"), 0755)
ioutil.WriteFile(tmpdir+"/done", []byte(tmpdir+"/systemd_logs.json"), 0755)
err := GatherResults(tmpdir+"/done", url, srv.Client(), nil)
ioutil.WriteFile(filepath.Join(tmpdir, "systemd_logs.json"), []byte("{}"), 0755)
ioutil.WriteFile(filepath.Join(tmpdir, "done"), []byte(filepath.Join(tmpdir, "systemd_logs.json")), 0755)
err := GatherResults(filepath.Join(tmpdir, "done"), url, srv.Client(), nil)
if err != nil {
t.Fatalf("Got error running agent: %v", err)
}

ensureExists(t, path.Join(aggr.OutputDir, "systemd_logs", "results"))
ensureExists(t, filepath.Join(aggr.OutputDir, "systemd_logs", "results"))
})
})
}
Expand All @@ -104,14 +104,14 @@ func TestRunGlobal_noExtension(t *testing.T) {
t.Fatalf("unexpected error getting global result url %v", err)
}
withTempDir(t, func(tmpdir string) {
ioutil.WriteFile(tmpdir+"/systemd_logs", []byte("{}"), 0755)
ioutil.WriteFile(tmpdir+"/done", []byte(tmpdir+"/systemd_logs"), 0755)
err := GatherResults(tmpdir+"/done", url, srv.Client(), nil)
ioutil.WriteFile(filepath.Join(tmpdir, "systemd_logs"), []byte("{}"), 0755)
ioutil.WriteFile(filepath.Join(tmpdir, "done"), []byte(filepath.Join(tmpdir, "systemd_logs")), 0755)
err := GatherResults(filepath.Join(tmpdir, "done"), url, srv.Client(), nil)
if err != nil {
t.Fatalf("Got error running agent: %v", err)
}

ensureExists(t, path.Join(aggr.OutputDir, "systemd_logs", "results"))
ensureExists(t, filepath.Join(aggr.OutputDir, "systemd_logs", "results"))
})
})
}
Expand All @@ -131,7 +131,7 @@ func TestRunGlobalCleanup(t *testing.T) {
}

withTempDir(t, func(tmpdir string) {
err := GatherResults(tmpdir+"/done", url, srv.Client(), stopc)
err := GatherResults(filepath.Join(tmpdir, "done"), url, srv.Client(), stopc)
if err != nil {
t.Fatalf("Got error running agent: %v", err)
}
Expand Down Expand Up @@ -188,10 +188,10 @@ func TestRelayProgress(t *testing.T) {
}
}

func ensureExists(t *testing.T, filepath string) {
if _, err := os.Stat(filepath); err != nil && os.IsNotExist(err) {
t.Logf("Plugin agent ran, but couldn't find expected results at %v:", filepath)
output, _ := exec.Command("ls", "-l", path.Dir(filepath)).CombinedOutput()
func ensureExists(t *testing.T, checkPath string) {
if _, err := os.Stat(checkPath); err != nil && os.IsNotExist(err) {
t.Logf("Plugin agent ran, but couldn't find expected results at %v:", checkPath)
output, _ := exec.Command("ls", "-l", filepath.Dir(checkPath)).CombinedOutput()
t.Log(string(output))
t.Fail()
}
Expand Down