Skip to content

Commit

Permalink
Cleanup of initializing working dirs
Browse files Browse the repository at this point in the history
Subsumes #726, with a unit test fix and a tweak to make sure that
artifact_bucket_test doesn't try to run in parallel, since that messes
up various PipelineRun tests.

Signed-off-by: Andrew Bayer <[email protected]>
  • Loading branch information
abayer authored and tekton-robot committed May 8, 2019
1 parent b81e22d commit e2b53c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions pkg/reconciler/v1alpha1/taskrun/resources/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io"
"io/ioutil"
"path/filepath"
"sort"
"strings"

"go.uber.org/zap"
Expand Down Expand Up @@ -169,15 +170,22 @@ func makeCredentialInitializer(serviceAccountName, namespace string, kubeclient

func makeWorkingDirScript(workingDirs map[string]bool) string {
script := ""
var orderedDirs []string

for wd := range workingDirs {
if wd != "" {
p := filepath.Clean(wd)
if rel, err := filepath.Rel(workspaceDir, p); err == nil && !strings.HasPrefix(rel, ".") {
if script == "" {
script = fmt.Sprintf("mkdir -p %s", p)
} else {
script = fmt.Sprintf("%s %s", script, p)
}
orderedDirs = append(orderedDirs, wd)
}
}
sort.Strings(orderedDirs)

for _, wd := range orderedDirs {
p := filepath.Clean(wd)
if rel, err := filepath.Rel(workspaceDir, p); err == nil && !strings.HasPrefix(rel, ".") {
if script == "" {
script = fmt.Sprintf("mkdir -p %s", p)
} else {
script = fmt.Sprintf("%s %s", script, p)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/v1alpha1/taskrun/resources/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func TestMakeWorkingDirScript(t *testing.T) {
}, {
desc: "simple",
workingDirs: map[string]bool{"/workspace/foo": true, "/workspace/bar": true, "/baz": true},
want: "mkdir -p /workspace/foo /workspace/bar",
want: "mkdir -p /workspace/bar /workspace/foo",
}, {
desc: "empty",
workingDirs: map[string]bool{"/workspace": true, "": true, "/baz": true, "/workspacedir": true},
Expand Down
2 changes: 1 addition & 1 deletion test/artifact_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestStorageBucketPipelineRun(t *testing.T) {
t.Skip("GCP_SERVICE_ACCOUNT_KEY_PATH variable is not set.")
}
c, namespace := setup(t)
t.Parallel()
// Bucket tests can't run in parallel without causing issues with other tests.

knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)
Expand Down

0 comments on commit e2b53c8

Please sign in to comment.