feat(clean): Remove OS state by default#76
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.
|
Note: Lint failures are pre-existing on master. |
| err := cleanSystemState() | ||
| if err != nil { | ||
| c.Log.Fatalf(1, "Unable to remove OS state (re-run with -init-state-only to skip): %s", err) | ||
| } |
There was a problem hiding this comment.
The way this is implemented now will break backwards compatibility with any setup that has an updated ec2-macos-init installation, but doesn't not the respectively updated ec2-macos-utils or even has a missing installation of ec2-macos-utils. This will cause breakages because the flag is an opt-out of the new behavior and not opt-in so the new call to ec2-macos-utils will be the new default behavior for any existing callers without updating their workflows.
I'd suggest we instead start with this being more gracefully handled and not error out if there are any issues calling ec2-macos-utils in favor of emitting warning logs. If you wanted, you could also have some finer error handling that's able to differentiate between ec2-macos-utils not being installed, not having the command, and having the command error out. That will allow us to gracefully handle the backwards compatibility cases while still erroring out if the tool call fails with its own error.
There was a problem hiding this comment.
Done in b63e025. Missing utils and too-old utils (no system cleanup-state, probed via --help) both warn and continue; only a real command error fails. Can make the warn cases hard-fail later once customers have updated.
…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.
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 |
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.