feat(cli): add --config support to snapshot command#918
Merged
Conversation
Extends AICRConfig with `spec.snapshot.*` so `aicr snapshot --config aicr-config.yaml` works without bare CLI flags. CLI flags continue to win over the matching config field; selectors and tolerations preserve the nil-vs-explicit-empty semantics already used by spec.validate.agent (omit to inherit defaults; `[]` to opt out of tolerate-all). The CUJ demo (demos/cuj1-gke-config.md) now drives snapshot, recipe, bundle, and validate from a single AICRConfig. Fixes #913
Contributor
The hardcoded `aicr-<run-id>` cluster name and `eidosx` project leak internal-environment specifics that do not generalize.
Contributor
Coverage Report ✅
Coverage BadgeMerging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. |
This comment was marked as resolved.
This comment was marked as resolved.
lalitadithya
previously approved these changes
May 15, 2026
Per CodeRabbit review on #918. Five Validate_*Snapshot* tests merge into TestValidate_Snapshot; the ten single-case TestSnapshotResolve_* tests fold into ShapeEdges, InvalidInput, DefensiveCloneOfCollections, and TolerationsNilVsExplicitlyEmpty tables. AllFieldsPopulated, ZeroTimeoutPreserved, and PrivilegedPointer stay as-is — bespoke assertions or already table-driven.
lalitadithya
approved these changes
May 15, 2026
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
Extends
AICRConfigwithspec.snapshot.*soaicr snapshot --config aicr-config.yamlworks without bare CLI flags, mirroring the existing config support onrecipe,bundle, andvalidate.Motivation / Context
pkg/cli/snapshot.godid not read--config, so config-driven CUJ demos (e.g.demos/cuj1-gke-config.md) still had to pass--namespace,--node-selector, and--tolerationas bare CLI flags for the snapshot step while the rest of the pipeline was config-driven. This broke the "one file drives the whole flow" property.Fixes: #913
Related: N/A
Type of Change
Component(s) Affected
cmd/aicr,pkg/cli)pkg/errors,pkg/k8s) —pkg/configdocs/,examples/)Implementation Notes
SnapshotSpecinpkg/config/config.gowithoutput,agent,executionsub-sections, mirroring the shape ofValidateSpec. The agent block reuses the same nil-vs-explicitly-empty semantics fornodeSelectorandtolerations(omit → inherit;[]→ clear the tolerate-all default).(*SnapshotSpec).Resolve()converts wire-string form to a typedSnapshotResolvedonce at the boundary; CLI overrides layer on top via the existingstringFlagOrConfig/boolFlagOrConfig/stringSliceFlagOrConfig/durationFlagOrConfig/intFlagOrConfighelpers — same pattern asrecipe,bundle, andvalidate.parseSnapshotCmdOptions(cmd, cfg)(mirroringparseBundleCmdOptions) so tests can capture the merged result without touching the deploy path.tolerations, the resolver falls back tosnapshotter.DefaultTolerations()(tolerate all) — matching the legacyaicr snapshotdefault. This is verified byTestSnapshotCmd_FlagsAloneDefaultsTolerateAll.Privilegedis a*boolinSnapshotExecutionSpecso an operator running in PSS-restricted namespaces can setprivileged: falsewithout the CLI flag's default-true silently re-enabling it.demos/cuj1-gke-config.mdupdated to useaicr snapshot --config aicr-config.yaml(no more bare flags); removed the implicit issue-tracking note.Testing
Coverage delta on affected packages:
pkg/cli: 63.7% → 66.5% (+2.8%)pkg/config: 93.7% → 93.8% (+0.1%)New tests:
pkg/config/resolve_test.go—SnapshotResolve_*: nil receiver, empty spec, all fields, zero/invalid/negative timeout, invalid tolerations, defensive map/slice clone, nil-vs-explicitly-empty,Privilegedpointer semantics, negativemaxNodesPerEntry.pkg/config/config_test.go—Validate_SnapshotOnly,Validate_InvalidSnapshot{Timeout,Format,Tolerations},Validate_NegativeSnapshotMaxNodesPerEntry, plus the updatednone oftest now coversspec.snapshot.pkg/config/loader_test.go—TestLoad_RejectsUnknownSnapshotFieldguards the strict-decode path.pkg/cli/snapshot_config_test.go(new) —--configflag wiring,FlagsAloneStillWork,FlagsAloneDefaultsTolerateAll,AllConfigSectionsResolve,ConfigOnly_NoCLIFlags,FlagOverridesEverySection,ConfigEmptyTolerationsOptOut,InvalidConfig_*(bad timeout/format/unknown field/bad resources),RequireGPURuntimeClass_StillMutuallyExclusive,ConfigPrivilegedFalseHonored,NoConfigPrivilegedDefaultsTrue,ToAgentConfigtranslation pin.Risk Assessment
spec.snapshotsection. No existing CLI flags removed or renamed. Strict-decode rejection unaffected since the new fields are added to the schema in the same change.Rollout notes: Backwards-compatible. Existing
aicr snapshotinvocations without--configcontinue to work unchanged.Checklist
make testwith-race)make lint)git commit -S)