Skip to content

fix: reduce legacy Linux custom data encoding overhead - #9880

Open
Shun Lyu (sinmentis) wants to merge 2 commits into
mainfrom
sinmentis/40305782
Open

Shun Lyu (sinmentis) wants to merge 2 commits into
mainfrom
sinmentis/40305782

Conversation

@sinmentis

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Remove per-file gzip/Base64 encoding from traditional Linux CustomData, which is already gzipped as a whole. Render file contents as JSON-quoted YAML strings so script bytes, whitespace, permissions, ownership, and paths stay unchanged.

Keep scriptless, Flatcar, and ACL encoding unchanged. Deliver every existing module, including LocalDNS, without relying on newer VHD contents. No size-limit increase, dependency, or shell behavior change.

This fixes the independently reproduced main Go-test failure also seen in #9717. Measured final production payloads for the existing public-cloud fixtures:

Distro Before After Limit
Ubuntu 22.04 Gen2 87,988 81,068 87,380
Azure Linux 2/3 Gen2 85,324 78,120 87,380

Ubuntu custom-cloud still exceeds the limit at 89,176 characters. That broader overflow remains separate in #9790. Unrelated E2E failures from #9717 are not addressed.

Validation:

  • Root-module CI build and non-E2E Go tests, plus both nested Go modules, pass.
  • Regression coverage checks decoded file equivalence, LocalDNS on/off, pre-provisioning, custom clouds, unchanged alternate modes, and whitespace preservation.
  • Local encoding benchmark remains about 20 ms/render, with roughly 5% more allocated bytes.
  • Hotfix Python tests pass 28/29. The remaining custom cloud only expectation in test_production_renderer_omits_empty_platform_payloads also fails on unchanged main at 732fedcbe0.

Which issue(s) this PR fixes:

AB#40305782

Avoid encoding each script separately when the complete traditional payload is already gzipped. Preserve file contents and alternate delivery modes.

AB#40305782

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 162f68f8-110a-4d60-b4fe-b9fb42253542
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Windows Unit Test Results

  3 files   18 suites   1m 10s ⏱️
563 tests 563 ✅ 0 💤 0 ❌
585 runs  585 ✅ 0 💤 0 ❌

Results for commit d4da1bb.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Production bootstrap serialization changes need human confirmation of cloud-init compatibility across supported Linux images beyond the offline regression coverage.

No open issues 🎉

What changed in this PR

Reduces legacy Linux CustomData size by removing per-file gzip/Base64 encoding while retaining whole-payload compression. This addresses the public-cloud payload overflow; the remaining Ubuntu custom-cloud overflow stays separate in #9790.

Changes:

  • Renders legacy file contents as JSON-quoted YAML strings, preserving scriptless, Flatcar, and ACL encoding.
  • Keeps existing file delivery, including LocalDNS, without requiring newer VHD contents.
  • Adds encoding-equivalence, whitespace, delivery-mode, and payload-size regression coverage, plus a rendering benchmark.
File Description
pkg/​agent/​variables.go Selects plain or compressed script content by delivery mode.
pkg/​agent/​utils.go Separates script rendering from compression.
pkg/​agent/​utils_test.go Updates script discovery for the encoder wrapper.
pkg/​agent/​mariner_live_patching_delivery_test.go Checks size using the production Azure Linux payload.
pkg/​agent/​live_patching_delivery_test.go Checks size using the production Ubuntu payload.
pkg/​agent/​cloud_init_encoding_test.go Adds equivalence, mode, whitespace, size, and benchmark coverage.
pkg/​agent/​baker.go Adds mode-aware encoding helpers and JSON serialization.
pkg/​agent/​baker_test.go Checks delivered file paths rather than script references.
parts/​linux/​cloud-init/​nodecustomdata.yml Uses encoding helpers for embedded file entries.
hotfix/​render-nodecustomdata/​main_test.go Updates hotfix fixtures and verifies plain encoding.
hotfix/​hotfix_generate_test.py Updates expectations for template encoding helpers.

Review effort: Balanced

Keep template registration and the test matrix below the cognitive complexity limit without changing behavior.

AB#40305782

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 162f68f8-110a-4d60-b4fe-b9fb42253542
Copilot AI balanced review requested due to automatic review settings October 23, 2026 03:57
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
test 0% ❌
windows 27% ❌
staging_cse_windows Package 1 65% ➖
debug 0% ❌
provisioningscripts 2% ❌
parts_windows Package 1 73% ➖
Summary 38% (1652 / 6834) ❌

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
github.com/Azure/agentbaker/aks-node-controller 72% ➖
github.com/Azure/agentbaker/aks-node-controller/common 100% ✔
github.com/Azure/agentbaker/aks-node-controller/helpers 68% ➖
github.com/Azure/agentbaker/aks-node-controller/parser 88% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/gpu 100% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils 89% ✔
github.com/Azure/agentbaker/aks-node-controller/utils 0% ❌
github.com/Azure/agentbaker/apiserver 24% ❌
github.com/Azure/agentbaker/cmd 0% ❌
github.com/Azure/agentbaker/cmd/starter 0% ❌
github.com/Azure/agentbaker/fuzz/api 0% ❌
github.com/Azure/agentbaker/hotfix/render-nodecustomdata 35% ❌
github.com/Azure/agentbaker/pkg/agent 78% ➖
github.com/Azure/agentbaker/pkg/agent/datamodel 77% ➖
github.com/Azure/agentbaker/pkg/agent/toggles 0% ❌
github.com/Azure/agentbaker/pkg/vhdbuilder/datamodel 87% ✔
Summary 75% (5929 / 7891) ➖

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
shellspec spec 28% ❌
Summary 28% (4591 / 16082) ❌

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The production bootstrap serialization change needs human confirmation of cloud-init compatibility across supported distributions and older VHDs.

No open issues 🎉

Review effort: Balanced

@timmy-wright

Copy link
Copy Markdown
Contributor

Review: fix: reduce legacy Linux custom data encoding overhead

What is good

The change reduces encoding overhead without dropping delivered modules or depending on a newer VHD. LocalDNS remains an unconditional file entry, preserving old-image provisioning behavior (template, lines 140-144).

One mode predicate selects both script representation and YAML formatting. Scriptless, Flatcar and ACL retain their existing encoding; JSON serialization handles quoting at both the YAML-scalar and outer JSON boundaries (baker.go, lines 348-364, lines 702-735).

The regression tests inspect the final production payload and compare decoded file contents and metadata across distro, custom-cloud, LocalDNS and pre-provisioning combinations, rather than checking encoding labels alone (tests, lines 16-120). An additional review-time comparison of actual base/head output confirmed identical decoded cloud-config for both Ubuntu and Azure Linux custom-cloud fixtures, including all 18 files.

Review outcome

PR: #9880

Reviewed head: d4da1bb717df4fac1a8861bdaacaa93aac5ce104
Base: 732fedcbe0fcc8258a8f627b18a66d889b9edaed
Report version: v1, draft-only pending reviewer approval.

Intent: Remove inner gzip/base64 only for traditional Linux CustomData, retaining outer compression, decoded file bytes, paths, ownership, permissions and existing delivery behavior. Preserve alternate modes and six-month VHD compatibility. No increased payload limit, dependency or shell-body change.

Risk and depth: Medium-high review risk because this serialization path feeds Linux node bootstrap. Planned units were encoder selection, YAML/JSON/compression boundaries, alternate modes/hotfix consumers, and behavioral validation. All seven distinct lenses completed against the current revision, including refreshes where needed; agents ran in waves of at most three. The eighth agent completed sequential previous-comment verification. All planned units received source review; deployed cloud-init/image-version validation remains outside the completed evidence.

Conclusion: No supported introduced defect was found. Current-head focused tests, Go CI, CodeQL and all three lint jobs pass. This is not an unconditional merge-readiness assessment: infrastructure checks remain pending, and an existing request for supported-image cloud-init confirmation remains unverified. Ubuntu custom-cloud overflow remains outside this PR under #9790; it is not resolved by this change.

The PR moved from 18c6ca86a65853bd6f094d1a5da59e7a586771a2 during review. Current source was read and tested from an immutable archive without switching or modifying the original checkout.

Comments, ordered by importance

No retained blocking defects, additional blocking validation gates, non-blocking recommendations or nitpicks.

The readability lens suggested documenting the YAML-value helper's input/output contract. Current callers already obey the documented paired-helper convention; no present defect was demonstrated. This optional documentation preference was not promoted to a finding.

H1. Existing question: supported-image cloud-init confirmation

Canonical discussion: existing review summary. Classification: Question, report-only; do not create a duplicate inline comment.

The earlier reviewer requested human confirmation using actual cloud-init on supported Linux images. Current source, Go tests and review-time PyYAML comparisons support the serialization contract, but none executes the guest write_files module across the supported-image window. If an implementation rejects or misdecodes the representation, bootstrap file delivery could fail; no such implementation or failure was demonstrated.

The narrow next action is to supply representative supported-image cloud-init/write-files evidence tied to this revision, including image and cloud-init versions and resulting file bytes/metadata. Existing provisioning-gate evidence may suffice if it actually exercises that path. This review does not impose a new exhaustive image matrix or assert an unproven compatibility defect. Source: encoding helpers, lines 702-720. Confidence: high that the requested evidence is missing, not that a defect exists.

Security findings

# Severity File Lines Vulnerability Confidence
- - - - No supported exploitable finding in the reviewed changes -

This is a bounded manual security review, not a completed automated security audit. Gitleaks, Semgrep, OSV-Scanner, Trivy and Checkov were unavailable; no tools were installed.

Automation evidence

Current-head Go CI, CodeQL Analyze(go), shell tests/checks, Pester, and root/nested lint checks pass. The exact head was verified for Go CI, CodeQL and lint runs. Passing checks support their respective contracts, not operational safety or production performance.

Historical lint run 39897053855 reported two cognitive-complexity violations at the earlier head. Helper extraction in the current head addresses them; run 39897767878 passes all three lint jobs. No obsolete lint finding is retained.

The Python hotfix suite has one failing custom-cloud subcase. The same failure was independently reproduced at the immutable base revision, so it is not attributed to this PR.

Previous review comments

Inventory cutoff: 2026-10-23 04:01:27 UTC. All pages retrieved for general comments, review bodies, inline comments and review threads. Five unique source comments, five concern-level todos; all five sequential adjudications are done, zero blocked or pending. Four outcomes are not actionable, one cannot verify; addressed, partial, unaddressed and duplicate counts are each zero. No inline threads, replies or provider-resolution discrepancies were present. A completed todo means adjudicated, not fixed; the history must not be described as "all comments resolved."

Detailed concern ledger: session ledger. Every concern ID below has prefix pr9880-history-d4da-.

Source comment Concern todo suffix Provider state Independent result Current evidence / missing evidence
6356952326 6356952326-1 General comment; resolved/outdated N/A Not actionable Windows results at current head; no independent request and no Windows production changes
6356972643 6356972643-1 General comment; resolved/outdated N/A Not actionable Go coverage metrics, no requested behavior/threshold; body does not identify revision
6356974310 6356974310-1 General comment; resolved/outdated N/A Not actionable ShellSpec coverage metrics, no requested behavior/threshold; no shell-body changes
5623706117 5623706117-1 COMMENTED review at old head; resolved/outdated N/A Cannot verify H1: offline preservation checks pass, supported-image actual-cloud-init confirmation unavailable
6357050091 6357050091-1 General comment; resolved/outdated N/A Not actionable Pester coverage metrics, no requested behavior/threshold; no Windows production changes

All five comments are bots. The summary's generated "No open issues" wording is not a provider resolution flag and does not close H1. New or edited comments after the cutoff are not covered by this frozen inventory.

Validation and coverage

Check / review unit Revision / artifact Result and actual depth Limitation
Strengths / security / design Current head; completed lens reports and revision addenda Full scoped diff plus lifecycle ownership, trust boundaries, helper/caller contracts Security scanner limitations below
Reliability / performance / readability / correctness Current head; completed lens reports Full scoped diff plus mode transitions, ANC/hotfix consumers, serialization and test semantics No guest lifecycle or production-performance measurement
Previous comments Current head; complete inventory at 04:01:27 UTC Five comments/todos independently adjudicated, one at a time H1 cannot verify; later discussion outside cutoff
Focused encoding/delivery/round-trip Go tests Current head; current-tests.log Passed; agent package 3.462s, hotfix renderer 0.062s Not a guest boot
Exact base/head decoded comparison Immutable base and head; base-rendered/, current-rendered/ PyYAML parsing plus legacy gzip decoding: complete cloud-config objects equal for both platforms, 18 files each Existing custom-cloud CLI fixtures, not every configuration
Go CI Current head; run 39897767818 Success, inspected CI and API head SHA Not independently rerun as a full suite
Root and nested lint Current head; run 39897767878 All three jobs successful, inspected CI and API head SHA Local linter is older; not substituted for CI
CodeQL Analyze(go) Current head; run 39897767883 Success, inspected CI and API head SHA No complete local scanner pipeline
Hotfix Python suite Current head; current-python.log 29 tests, one failing custom-cloud subcase Failure also reproduced at base, base-python.log
Diff whitespace Base to current head git diff --check passed Formatting check only
Final encoded fixture size Current head; current-tests.log Ubuntu public 80,240; Azure Linux 2/3 public 77,344; Azure Linux custom 85,392; limit 87,380 Ubuntu custom 88,352 exceeds limit; separate #9790
Rendering benchmark Earlier head 18c6ca86; five iterations Legacy surrogate 40.0ms/op and 15.66MB/op; new path 35.2ms/op and 13.28MB/op Short historical sample; not production latency, peak memory or a current-head benchmark
Guest compatibility Source tracing, Go/PyYAML parsing, archived cloud-init documentation No supported compatibility failure identified; current ANC accepts empty encoding Historical cloud-init versions/deployed ANC binaries and PIS boots not executed
Linux VHD / GPU / Windows E2E Current-head check inventory Pending at collection No success or failure inferred
Windows VHD / generic Agentbaker E2E Current-head check inventory Neutral Not counted as passes

The in-tree legacy comparator uses the head template with legacy helpers, not immutable base output. The independent base/head comparison above covers that specific shared-template blind spot for its two fixtures. No provisioning-speed, peak-memory or complete historical-runtime guarantee is asserted. Historical cloud-init/deployed ANC certification would need image-domain evidence; no other domain-expert need emerged.

Final remote-head recheck matched the reviewed revision. Final check inventory: 21 successes, one skipped, three queued, twelve in progress, two neutral; no failed conclusion. Evidence: final-checks.json in the session directory.

The parent completed the report's comment-quality and completeness checks: obsolete automation findings removed; the optional documentation suggestion not promoted; existing concern linked rather than duplicated; source and runtime evidence distinguished; all eight assignments accounted for. Self-evaluation was performed inline without an additional reviewer.

Evidence directory: /home/tim/.copilot/session-state/28f698ed-78aa-4f5b-9ac8-52b2697bd727/files/pr9880/.

Publication plan

General PR comment: this report, only after explicit reviewer approval for version v1 and the reviewed revision.
Inline comments: none.
Report-only comment: H1, preserving the existing discussion rather than duplicating it.
Known thread/comment to avoid duplicating: review 5623706117, linked above.
Review action: comment only; no approval/rejection vote.
Status: draft, awaiting reviewer approval. No remote writes have occurred.

@cameronmeissner

Copy link
Copy Markdown
Contributor

attempting to test with NAP check-in tests before merge

Comment thread pkg/agent/baker.go

func getCloudInitFileContent(config *datamodel.NodeBootstrappingConfiguration, content string) (string, error) {
if usePlainCloudInit(config) {
encoded, err := json.Marshal(content)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried about this line, marshalling plain text in json, i am worried that some introduction of text might break this in future.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants