test: add ShellSpec coverage for init-aks-custom-cloud*.sh
Context
The init-aks-custom-cloud*.sh scripts run at node boot in custom-cloud environments and rewrite the system package repository URLs to point at the internal RepoDepot mirror (since those nodes cannot reach the public internet). A misconfiguration here — e.g. a leftover public URL that does not get rewritten — can cause package operations to hang during provisioning. There was previously no automated test exercising these scripts, so a regression in the repo-URL rewrite could slip through.
This PR adds that missing test coverage.
What this PR does
No script logic is changed. This PR only adds ShellSpec unit-test coverage and makes the scripts/functions testable. The runtime behavior of all four scripts is preserved —
main()invokes the same functions in the same order with the same arguments as before.
1. Makes all 4 init-aks-custom-cloud*.sh scripts testable (no behavior change)
init-aks-custom-cloud.sh(Ubuntu/Flatcar/ACL)init-aks-custom-cloud-mariner.sh(Mariner/AzureLinux)init-aks-custom-cloud-operation-requests.sh(Ubuntu/Flatcar/ACL)init-aks-custom-cloud-operation-requests-mariner.sh(Mariner/AzureLinux)
Refactor pattern (matches existing repo convention, e.g. mariner-package-update.sh):
- Lift hardcoded paths (apt sources, yum.repos.d, ssl certs, chrony, wireserver) into
: "${VAR:=default}"env-overridable constants. Defaults are identical to the previous hardcoded values, so production behavior is unchanged. - Add
${__SOURCED__:+return}guard so ShellSpec'sIncludecan source the script without runningmainat source time. - Wrap existing inline logic into named functions (
detect_distro,fetch_and_install_ca_certs,init_*_repo_depot,write_chrony_config, etc.) — the same commands, just grouped into callable units.
2. Adds ShellSpec tests (20 examples across 4 spec files)
Drives each script with a mocked REPO_DEPOT_ENDPOINT and asserts:
- All rewritten repo files point at the mocked depot.
- No leftover
packages.microsoft.comURLs remain. - No third-party (e.g.
developer.download.nvidia.com) URLs leak in. - Existing
/etc/apt/sources.list[.d]entries are backed up, not left in place. init_repo_depotstrips the trailing/ubuntuand dispatches the Mariner / AzureLinux / Ubuntu paths correctly.
Verification
- All 20 new ShellSpec examples pass locally (pinned to the CI shellspec version 0.28.1).
make validate-shell(shellcheck gate) passes.- No snapshot/testdata changes — the refactor preserves embedded-script behavior.
🕵️ AgentBaker Linux Gate Detective — PR gate failure analysis
- Failed run: build 167683195 (pipeline def
119535,refs/pull/8692/merge) - Failed job: Stage
e2e→Run AgentBaker E2E(exit 1) - Failed tests (6 top-level):
Test_AzureLinuxV3_NetworkIsolated_Package_Install(default + scriptless_nbc)Test_AzureLinuxV3_NetworkIsolatedCluster_NonAnonymousACR(default + scriptless_nbc)Test_Ubuntu2204_NetworkIsolatedCluster_NonAnonymousACR/scriptless_nbcTest_Ubuntu2204_ArtifactStreaming_NetworkIsolatedCluster/scriptless_nbcTest_ACL_NetworkIsolatedCluster_NonAnonymousACRTest_ACL_SecureTLSBootstrapping_BootstrapToken_Fallback/scriptless_nbc
RCA (3-level)
- Surface: CSE fails on every NetworkIsolated scenario with the cluster's private apiserver FQDN unresolvable.
- Corroboration (≥2 sources):
test-log.json:nslookupagainst169.254.10.10returnsNXDOMAINforabe2e-azure-networkisolated-v3-kq4wzvpl.hcp.westus3.azmk8s.io(CSEVALIDATION_ERR=52, repeated for ~5 min).- Pipeline
Run AgentBaker E2Eissue list: only genericScript failed with exit code: 1+ a debug-pod readiness warning — no PR-source code error. - All 5 NetworkIsolated failures hit the same shared cluster
abe2e-azure-networkisolated-v3-kq4wzvplalready named in the wiki signature.
- Challenge / strongest alternative: Could PR #8692 (ShellSpec coverage for
init-aks-custom-cloud*.sh) be responsible? No — those scripts are not on the CSE NetworkIsolated apiserver-nslookup path, and the wiki shows the identical NXDOMAIN against the same westus3 cluster on three unrelated PRs (#8600, #8659, #8642). Deterministic shared-fixture / private-DNS issue, not PR-caused.
Classification
- Signature (reuse, existing):
networkisolated-apiserver-fqdn-nxdomain— Test-infra / NetworkIsolated shared-cluster private-DNS reachability. - Build-vs-test class: test-infra flake (shared fixture); deterministic on this cluster, not on the PR.
- Secondary signature (1/6 tests):
localdns-exporter-systemd-failed-stateonTest_ACL_SecureTLSBootstrapping_BootstrapToken_Fallback/scriptless_nbc([email protected]:9353-10.220.112.4:57128.serviceunexpectedly entered failed state). Tracked separately in the wiki. - Confidence: High.
Recommendation / owner
- Owner: AgentBaker E2E test-infra — verify private DNS zone / private-link for the hcp FQDN on cluster
abe2e-azure-networkisolated-v3-kq4wzvpl(westus3) and that169.254.10.10resolver is wired correctly. - Action for PR author: No code change required from #8692. Once the shared-cluster DNS is healthy, re-run the gate. The wiki row for
networkisolated-apiserver-fqdn-nxdomainwill be updated centrally to include build167683195.
Posted by Clawpilot AgentBaker Linux Gate Detective Watcher. No raw private logs are included.