feat(clean): Remove OS state by default - #76
Open
aaljewarane wants to merge 2 commits into
Open
Conversation
… now also removes well-known OS state by invoking 'ec2-macos-utils system cleanup-state' as a subprocess, with its output passed through to the calling shell. This removes state such as the macOS cached network interface configuration (NetworkInterfaces.plist) that breaks or delays networking on instances launched from a derived image (AMI). Pass -init-state-only to limit cleanup to ec2-macos-init's own state. Instance history removal no longer aborts the run: absent history is treated as nothing to remove, and a removal failure is logged, OS state cleanup still runs, and clean exits non-zero so a partially cleaned system is never reported as success. ec2-macos-utils is resolved from its install path (/usr/local/bin/ec2-macos-utils) first, falling back to PATH, since sudo's default PATH does not include /usr/local/bin for the documented 'sudo ec2-macos-init clean' usage.
Author
|
Note: Lint failures are pre-existing on master. |
mattcataws
requested changes
Jul 23, 2026
…state cleanup is opt-out default behavior, so systems without ec2-macos-utils, or with a version predating 'system cleanup-state', would break existing clean workflows on init update. Differentiate the cases: warn and continue when utils is absent or too old (probed via --help), and fail only when the command exists but errors. The lenient cases may become errors in a future release.
Author
Validation on EC2 Mac hardwareValidated
New init built from this branch ( Backwards-compat / three-case handling
Original functionality + flag
Sample (case B, old utils): Sample (case D, real error): Note: to avoid reboots, cases after the first real removal used a placeholder at the plist path; the Further notes: Escape hatch is still -init-state-only if someone needs to bypass. |
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.
Summary
ec2-macos-init cleannow also invokesec2-macos-utils system cleanup-stateby default, with subprocess STDIO passed through to the calling shell. A new-init-state-onlyflag limits cleanup to init's own state.This fixes the recurring issue where AMIs built after
cleanstill carried macOS's cached network interface configuration (NetworkInterfaces.plist), delaying or breaking networking on instances launched from those images.Behavior:
-init-state-only; a half-cleaned image is the bug being fixed./usr/local/bin/ec2-macos-utils) first, falling back to PATH, since sudo's default PATH excludes /usr/local/bin for the documentedsudo ec2-macos-init cleanusage.Dependency
Requires aws/ec2-macos-utils#41 to merge and release first.
Testing
go vetclean; existing tests pass.-init-state-onlyopt-out, non-zero exit when utils is missing, history-failure ordering (OS cleanup still runs, then non-zero exit), install-path-preferred resolution, and PATH fallback.