-
Notifications
You must be signed in to change notification settings - Fork 43
Extract .spec from cluster record format for snapshot input #3043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Latest suggestions up to 44cbce8
Previous suggestions✅ Suggestions up to commit ae837ea
✅ Suggestions up to commit 94f6f9c
|
|||||||||||||||||||||||||||||||||||||||
* Modify readSnapshotSource to automatically extract the .spec field when the input is a Kubernetes cluster record, matching the behavior for policy.yaml files. This allows direct use of kubectl output without manual jq extraction. * The change maintains backward compatibility with direct SnapshotSpec input and works with both JSON and YAML formats. resolves: EC-1534
Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
* and fix some formatting in unit test resolves: EC-1534
simonbaird
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice patch.
| return *wrapper.Spec, nil | ||
| } | ||
|
|
||
| // Fallback: unmarshal directly into SnapshotSpec for backward compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick about this comment: Saying "backward compatibility" implies that we're changing the preferred method of accessing the snapshot spec, which isn't really accurate. I'd reword it slightly, e.g.:
| // Fallback: unmarshal directly into SnapshotSpec for backward compatibility | |
| // If we didn't find a snapshot under the .spec top level key then | |
| // assume we're looking at the bare snapshot data |
| var file app.SnapshotSpec | ||
| err := yaml.Unmarshal(input, &file) | ||
| if err != nil { | ||
| // Define a temporary struct to capture the wrapped spec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Define a temporary struct to capture the wrapped spec | |
| // Define a temporary struct to capture the wrapped spec so we | |
| // so can read snapshot data correctly from a cluster record |
It's pretty clear what's going on here I guess, but maybe some extra commentary would be nice.
User description
Modify readSnapshotSource to automatically extract the .spec field when the input is a Kubernetes cluster record, matching the behavior for policy.yaml files. This allows direct use of kubectl output without manual jq extraction.
The change maintains backward compatibility with direct SnapshotSpec input and works with both JSON and YAML formats.
resolves: EC-1534
PR Type
Enhancement
Description
Auto-extract
.specfield from Kubernetes cluster recordsEnables direct use of kubectl output without manual jq extraction
Maintains backward compatibility with direct SnapshotSpec input
Supports both JSON and YAML formats seamlessly
Diagram Walkthrough
File Walkthrough
input.go
Add .spec extraction logic to readSnapshotSourceinternal/applicationsnapshot/input.go
.specfield from cluster recordformat
.speckey presence.specwrapper existsinput_test.go
Add comprehensive tests for .spec extractioninternal/applicationsnapshot/input_test.go
.specwrapper in JSON.specwrapper in YAMLSnapshotSpec input