Repository navigation
refactor(linux): allow synchronous log bundle uploads before cleanup - #10209
Open
Abigail Liang (abigailliang-aks-sig-node) wants to merge 1 commit into
Open
Abigail Liang (abigailliang-aks-sig-node) wants to merge 1 commit into
Abigail Liang (abigailliang-aks-sig-node) wants to merge 1 commit into
Conversation
Expose a sourceable collection entry point and synchronous upload function while retaining the existing Host sender and bundle cleanup. Scope the collection EXIT trap to a subshell so a sourced caller regains control only after cleanup, with upload failure status preserved. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1b5a8171-5163-48fa-810e-1054bb3eada0
Contributor
Windows Unit Test Results 3 files 21 suites 1m 22s ⏱️ Results for commit bb972b4. |
Contributor
Contributor
Contributor
|
Abigail Liang (abigailliang-aks-sig-node)
marked this pull request as ready for review
November 27, 2026 22:48
Abigail Liang (abigailliang-aks-sig-node)
requested review from
a team
as code owners
November 27, 2026 22:48
Abigail Liang (abigailliang-aks-sig-node)
enabled auto-merge (squash)
November 27, 2026 22:48
Copilot started reviewing on behalf of
Abigail Liang (abigailliang-aks-sig-node)
November 27, 2026 22:48
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The ZIP test fixture can overwrite host archives, while signal-handling, inherited strict-mode options, and cleanup-function conflicts can abort uploads, leave collection running, or prevent cleanup.
4 open issues
What changed in this PR
Adds a synchronous upload hook to AgentBaker’s Linux node-log collector so sourced callers can consume bundles before cleanup without duplicating collection logic.
Changes:
- Wraps collection in a subshell-based
collectLogs()to isolate its working directory and EXIT trap. - Extracts an overridable
uploadLogBundle()while retaining the default Host uploader. - Adds ShellSpec coverage for upload results, bundle permissions, cleanup, interruption, and caller state.
| File | Description |
|---|---|
spec/parts/linux/cloud-init/artifacts/aks_log_collector_spec.sh |
Adds fixture-based tests for synchronous uploads and collection lifecycle behavior. |
parts/linux/cloud-init/artifacts/aks-log-collector.sh |
Introduces the sourced collection entry point and overridable upload hook. |
Review effort: Max
| zip) | ||
| # Consume only relative fixture FIFOs, never the host's log files. | ||
| for arg; do | ||
| if [[ "$arg" == *.zip ]]; then |
| exit 255 | ||
| } | ||
| # Keep EXIT cleanup scoped to collection, including when called after sourcing. | ||
| collectLogs() ( |
| exit 255 | ||
| } | ||
| # Keep EXIT cleanup scoped to collection, including when called after sourcing. | ||
| collectLogs() ( |
|
|
||
| # Execute the cleanup function if the script terminates | ||
| trap "exit 1" HUP INT PIPE QUIT TERM | ||
| trap "cleanup" EXIT |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What this PR does / why we need it:
Allow a caller to consume/upload the node-log bundle synchronously, before the collector's existing EXIT cleanup removes it. This supports test harnesses without rewriting the installed collector or maintaining another copy of its collection logic.
collectLogs(), using a subshell so its EXIT trap runs before returning to a sourced caller and does not replace the caller's trap or working directory.uploadLogBundle. Direct script execution still uses the same Python sender. A trusted caller may source the script using its existing__SOURCED__guard, override this function, and invokecollectLogs.$1. The override must finish consuming/uploading it before returning and return a nonzero status on failure.Example caller structure:
The protections from #9783 are retained: owner-only publishing and the existing published-bundle/temporary-directory cleanup are unchanged. This adds no CLI upload options, IMDS-configured command execution, persistent-export mode, or additional upload transport. The collection/configuration body is unchanged apart from indentation and the upload-function call; hide whitespace when reviewing.
This is the producer-side hook only. Consumers still need to adopt it, and existing images without these functions are not repaired by this source change. No workload failure or live end-to-end log recovery is claimed.
Validation:
make validate-shellandgit diff --checkpassed.Which issue(s) this PR fixes:
No linked issue. Follow-up integration support for #9783; it does not revert that change.