Repository navigation
feat(filer): upload wildcard output matches - #134
Conversation
Reviewer's GuideData structuresDefine wildcard detection and the deepest non-wildcard directory used as the mount root.
Uses of the APIUse the wildcard root for TES 1.1 outputs while preserving existing mounts for inputs and outputs without a path prefix, and reject patterns that would require mounting at the filesystem root.
ImplementationExpand prefixed wildcard outputs, validate every match before uploading, map matches beneath the destination URL, and copy file-scheme matches as concrete paths.
DocumentationExplain TES 1.1 wildcard-output expansion, matching and safety behavior, mount requirements, and unchanged TES 1.0 behavior.
TestsCover wildcard recognition, mount-root selection, URL joining, uploads across schemes, optional and directory matches, safety failures, and legacy behavior.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #134 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 1484 1556 +72
=========================================
+ Hits 1484 1556 +72 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/tesk_core/path.py" line_range="134" />
<code_context>
+ if hasWildcards(part):
+ break
+ root.append(part)
+ return "/" + "/".join(root) if root else ""
+
+
</code_context>
<issue_to_address>
**Root-level wildcard tasks cannot start**
When an output pattern has a wildcard in its first path component, such as `/*.txt`, `wildcardRoot` returns an empty path, which `dirname` passes to `append_mount` as a Kubernetes `mountPath`; Kubernetes rejects the mount and the task cannot start.
Make root-level patterns use a valid, nonempty mount root before `dirname` passes it to `append_mount`.
Also at `src/tesk_core/taskmaster.py:219`.
</issue_to_address>
### Comment 2
<location path="src/tesk_core/taskmaster.py" line_range="218-219" />
<code_context>
"""
- if iodata["type"] == "FILE":
+ dirname: str
+ if hasWildcards(iodata["path"]):
+ dirname = wildcardRoot(iodata["path"])
+ logger.debug("dirname of pattern %s is: %s", iodata["path"], dirname)
+ elif iodata["type"] == "FILE":
</code_context>
<issue_to_address>
**Literal input paths mis-mount**
When an input filename or directory component contains `*`, `?`, or `[` as a literal character, `generate_mounts` also calls `dirname` for inputs, so an input path with a literal `*`, `?`, or `[` is treated as an output pattern and `wildcardRoot` mounts an ancestor instead of the input’s containing directory. The input is then attached at the wrong task path and is unavailable to the executor.
Apply wildcard-root mounting only to outputs; keep the existing directory calculation for inputs.
</issue_to_address>
### Comment 3
<location path="src/tesk_core/filer.py" line_range="1149" />
<code_context>
+ for part in relative.split("/"):
+ url = http_join(url, part)
+ return url
+ return url.rstrip("/") + "/" + relative
+
+
</code_context>
<issue_to_address>
**Matched files use wrong destination names**
When a wildcard matches a file or directory whose relative name contains `?` or `#`, and the destination uses a non-HTTP scheme, `url_join` appends the relative name raw, so `Transput` parses `?` as a query delimiter and `#` as a fragment; the transfer uses a truncated destination path and stores the output under the wrong name.
Percent-encode each relative path component before joining it to a non-HTTP destination URL.
</issue_to_address>
### Comment 4
<location path="src/tesk_core/filer.py" line_range="1193" />
<code_context>
+ relative = os.path.relpath(match, prefix).replace(os.sep, "/")
+ ftype = Type.Directory if os.path.isdir(match) else Type.File
+ try:
+ with trans(match, url_join(filedata["url"], relative), ftype) as transfer:
+ if transfer.upload(check_links=False):
+ return 1
</code_context>
<issue_to_address>
**Nested file outputs fail to copy**
When a wildcard match has a nested relative path and its corresponding parent directory under the file URL does not exist, `FileTransput.upload_file` calls `copyFile` and `shutil.copy` without creating the destination parent directories, so the copy raises `FileNotFoundError` and the output fails.
Create the destination parent directories before copying a file to its joined URL path.
</issue_to_address>
### Comment 5
<location path="src/tesk_core/filer.py" line_range="1195" />
<code_context>
+ match,
+ filedata["path_prefix"],
+ )
+ return 1
+ if output_has_symlink(match, recursive=True):
+ return 1
</code_context>
<issue_to_address>
**Failed outputs leave partial uploads**
When a match upload fails after one or more earlier matches have succeeded, a later match’s transfer can fail after earlier matches have already been uploaded, and `upload_matches` returns failure without removing those objects. The output therefore remains partially visible at its destination even though the filer job failed.
Stage or track the uploaded destinations and remove them on failure, or otherwise ensure failed output sets are not exposed as complete.
</issue_to_address>
### Comment 6
<location path="src/tesk_core/filer.py" line_range="1172" />
<code_context>
+ pattern = filerPath(filedata["path"])
+ prefix = filerPath(filedata["path_prefix"])
+ parsed_url = urlparse(filedata["url"])
+ trans = newTransput(parsed_url.scheme or "file", parsed_url.netloc)
+ matches = sorted(glob(pattern))
+ if not matches:
</code_context>
<issue_to_address>
**Empty optional outputs fail**
When a `file:` wildcard output has no matches while the file protocol is disabled, `upload_matches` calls `newTransput` before checking the glob results, so `FileProtocolDisabled` is raised instead of taking the empty-match success path.
Check for matches before calling `newTransput`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 6 findings to address first, and if wildcard or prefix handling selects unintended files, the filer can send their contents to the output URL; those remote copies may remain after the change is reverted.
Blocking findings: src/tesk_core/path.py:134, src/tesk_core/taskmaster.py:219, src/tesk_core/filer.py:1149, src/tesk_core/filer.py:1193, src/tesk_core/filer.py:1195, and 1 more
Outputs whose path has wildcards (*, ?, [) and a path_prefix, as in TES 1.1, are expanded in the filer for every scheme, not only file: URLs. Each match goes to the output's URL plus its path below path_prefix; a pattern that matches nothing uploads nothing and succeeds. Matches that are or contain symbolic links, or that aren't below path_prefix, fail the output before anything is uploaded. The taskmaster mounts such an output at the pattern's deepest directory without wildcards, instead of at a path with wildcards in it.
113f570 to
ab22e84
Compare
uniqueg
left a comment
There was a problem hiding this comment.
Thanks, Anurag, this is a nice piece of work, and the sarek run is convincing. Checking every match before uploading anything, and the realpath check against path_prefix, are exactly right.
Two things I'd like fixed before merging, both small:
- Patterns with a wildcard in the first component (
/*.txt) get an empty mount path (Sourcery's thread onpath.py), so the job is rejected by Kubernetes rather than with a clear message. I'd refuse those, in tesk-api with a 400 or here with a clear error. file:URLs withpath_prefixgo throughFileTransput.upload_file→copyFile, which doesn't create the destination's parent directory (nested matches raiseFileNotFoundError), and which globs the matched path again (a match namedout[1].txtcopies nothing, but still returns 0). A plain copy withmakedirsfor matches would fix both. Afile:test would cover it, as the current tests are S3 only.
Smaller points inline. Could you reply to the Sourcery threads too? Some of them are fine to decline with a reason (partial uploads, file protocol disabled).
- Refuse patterns with wildcards in their first component (/*.txt): they would need a mount at /, and got an empty mountPath, which Kubernetes rejects. - Only outputs with path_prefix get the pattern's root as their mount; inputs and TES 1.0 outputs are mounted as before, so a literal [ in their names keeps its meaning. - file: matches are copied as concrete paths, creating the directories below the URL: nested matches no longer raise FileNotFoundError, and a match whose name has [ is no longer globbed again (and skipped). - A match whose name has # or ? fails the output for non-HTTP URLs, whose paths the transfers read as they are, instead of being stored under a shorter name. - A pattern that matches nothing succeeds before a transfer is created, also when file: is disabled.
|
Thanks for the review, @uniqueg. Both requested changes are in 3e2b7bb, as are your optional points, and every thread has a reply:
Checks: 702 tests pass with 100% coverage, and ruff, mypy and the strict docs build are clean. |
Summary
Part of elixir-cloud-aai/TESK#276 (TES 1.1 wildcard outputs); tesk-api's part is elixir-cloud-aai/tesk-api#133.
upload_matches): an output whosepathhas wildcards (*,?,[; POSIX pattern matching, as TES 1.1 specifies) and apath_prefixis expanded for every scheme, not onlyfile:URLs.url, a directory, plus its path belowpath_prefix:/data/s1/out.txtforpath/data/*/out.txtandpath_prefix/datagoes tourl/s1/out.txt.*skips dot-files and.command.*matches them, as in the shell.out.tx[*t]makes an optional output.path_prefix, or that are or contain symbolic links, fail the output before anything is uploaded, in keeping with fix(filer): don't follow symlinks in outputs #124.http_join, keeping the query (url_join).dirname): an output with wildcards is mounted at the pattern's deepest directory without wildcards (/datafor/data/*/out.txt). Before, it was mounted at/data/*, a directory the executor never writes to. The helpershasWildcardsandwildcardRootare inpath.py.path_prefix(TES 1.0) behave as before, includingfile:globs.docs/filer.md.Verification
Locally (Python 3.10, rebased on
devat 3035e26):ruff check,ruff format --check: passmypy: no issues in 43 source filespytest tests/unit: 634 passed, 26 of them new intests/unit/test_filer_wildcards.py(S3 via moto: plain, directory-level and hidden-file patterns, matched directories, no match, single-file classes, outside-prefix and symlink refusals, the TES 1.0 path;url_join; mounts)mkdocs build --strict: passOn a cluster
Filer and taskmaster images built from this branch, with tesk-api from the companion PR, installed with the
TESKdevchart (Talos, Kubernetes 1.33, local-path PVCs). Outputs went to presigned S3 URLs over HTTP through a TES gateway. nf-core/sarek 3.8.1 (test, Strelka) ran with every task sent to TESK:On images without this change, none of these 23 tasks could run on TESK: each declares wildcard outputs.
Open questions
path_prefixneeds. Which release should they name?Summary by Sourcery
Enable safe TES 1.1 wildcard output handling across filer uploads and taskmaster mounts.
New Features:
path_prefixand including matched directories.Bug Fixes:
path_prefix, symbolic-link matches, and URL-incompatible names before uploading any files.Enhancements:
path_prefixis absent and apply shell-compatible hidden-file matching and URL path escaping for wildcard outputs.Documentation:
Tests: