fix(declcfg): WriteFS now preserves Others and Deprecations#1979
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes WriteFS in alpha/declcfg so it no longer drops cfg.Others (custom/unrecognized FBC objects) and cfg.Deprecations when writing per-package declarative config files to disk, aligning its behavior with the existing writeToEncoder path.
Changes:
- Include
OthersandDeprecationsin the per-packageDeclarativeConfigwritten byWriteFS. - Write package-less
Othersto a root-levelcatalog.<ext>file (consistent withwriteToEncoderbehavior). - Add a
WriteFSunit test validating on-disk contents and aLoadFSround-trip forOthers/Deprecations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
alpha/declcfg/write.go |
Ensures WriteFS carries through Others/Deprecations and emits package-less Others at the catalog root. |
alpha/declcfg/write_test.go |
Adds coverage to prevent regressions and validates WriteFS output + LoadFS round-trip. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1979 +/- ##
==========================================
+ Coverage 57.71% 57.88% +0.16%
==========================================
Files 139 140 +1
Lines 13373 13448 +75
==========================================
+ Hits 7718 7784 +66
- Misses 4468 4473 +5
- Partials 1187 1191 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Can we converge implementation with writeToEncoder? |
5e24fa4 to
cc6a25b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
alpha/declcfg/write.go:623
- WriteFS now derives
pNamefrom all schema types (channels/bundles/others/deprecations) and uses it directly infilepath.Join(rootDir, pName). Because LoadFS does not validateChannel.Package/Bundle.Package/etc, a malicious declarative config could setpackageto values like "../../outside" or an absolute path and cause WriteFS to write outsiderootDir(directory traversal). Please validate/sanitizepNamebefore creating directories (e.g., enforce DNS1123 label like ConvertToModel does, or reject any name that is empty/"."/".." or contains path separators).
for _, pName := range pkgNames.List() {
if pName == "" {
continue
}
fcfg := DeclarativeConfig{
Packages: packagesByName[pName],
Channels: channelsByPackage[pName],
Bundles: bundlesByPackage[pName],
Others: othersByPackage[pName],
Deprecations: deprecationsByPackage[pName],
}
pkgDir := filepath.Join(rootDir, pName)
if err := os.MkdirAll(pkgDir, 0777); err != nil {
return err
}
filename := filepath.Join(pkgDir, fmt.Sprintf("catalog%s", fileExt))
cc6a25b to
d0d7a08
Compare
d0d7a08 to
823717c
Compare
823717c to
ef0ced1
Compare
| func writeToEncoder(cfg DeclarativeConfig, enc encoder) error { | ||
| pkgNames := sets.NewString() | ||
| // configsByPackage groups a DeclarativeConfig into per-package sub-configs plus a | ||
| // package-less remainder (Others with no Package field). It is the single touchpoint |
There was a problem hiding this comment.
Please remodel/remove the comment here. I'm not comfortable with a claude-based rewording of my review comment.
There was a problem hiding this comment.
I did have to clarify what you wanted, and I hope I was correct.
There was a problem hiding this comment.
I think you absolutely were. Appreciate it.
WriteFS was iterating over Packages, Channels, and Bundles, but never consulted cfg.Others or cfg.Deprecations when building the per-package DeclarativeConfig written to disk. Any custom FBC blobs (e.g. olm.lifecycle metadata used by the Operator Update Planner) and olm.deprecations entries were silently dropped. The implementation is converged with writeToEncoder by extracting a shared configsByPackage helper that groups all five schema types by package name. Both writeToEncoder and WriteFS now call this single function, so adding a new schema type to DeclarativeConfig in the future requires only one edit. Others with an empty Package field are returned as a package-less remainder and written to a root-level catalog file, matching writeToEncoder's behaviour. Fixes: OCPBUGS-85347 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Todd Short <tshort@redhat.com>
ef0ced1 to
e132825
Compare
|
|
||
| func writeToEncoder(cfg DeclarativeConfig, enc encoder) error { | ||
| pkgNames := sets.NewString() | ||
| func configsByPackage(cfg DeclarativeConfig) (sets.Set[string], map[string]DeclarativeConfig, []Meta) { |
There was a problem hiding this comment.
nit: This triple-return really feels like a wanna-be struct.
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: grokspawn The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
e7d7929
into
operator-framework:master
WriteFS was iterating over Packages, Channels, and Bundles, but never consulted cfg.Others or cfg.Deprecations when building the per-package DeclarativeConfig written to disk. Any custom FBC blobs (e.g. olm.lifecycle metadata used by the Operator Update Planner) and olm.deprecations entries were silently dropped.
This matches the existing behaviour of writeToEncoder, which already handles all five schema types correctly. Others with an empty Package field are now written to a root-level catalog file, consistent with how writeToEncoder emits them at the end of its output.
Fixes: OCPBUGS-85347
Description of the change:
Motivation for the change:
Reviewer Checklist
/docs