diff --git a/cmd/sonobuoy/app/worker.go b/cmd/sonobuoy/app/worker.go index 64472a101..78d472fee 100644 --- a/cmd/sonobuoy/app/worker.go +++ b/cmd/sonobuoy/app/worker.go @@ -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 @@ -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") } diff --git a/pkg/client/retrieve.go b/pkg/client/retrieve.go index 05528c08e..95ad03e60 100644 --- a/pkg/client/retrieve.go +++ b/pkg/client/retrieve.go @@ -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" @@ -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 } @@ -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)) } } diff --git a/pkg/worker/worker_test.go b/pkg/worker/worker_test.go index 3931d9f66..811011d49 100644 --- a/pkg/worker/worker_test.go +++ b/pkg/worker/worker_test.go @@ -23,7 +23,7 @@ import ( "net/http/httptest" "os" "os/exec" - "path" + "path/filepath" "strings" "testing" @@ -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")) }) } }) @@ -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")) }) }) } @@ -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")) }) }) } @@ -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) } @@ -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() }