Skip to content

fix(declcfg): WriteFS now preserves Others and Deprecations#1979

Merged
openshift-merge-bot[bot] merged 1 commit into
operator-framework:masterfrom
tmshort:fix-OCPBUGS-85347
May 12, 2026
Merged

fix(declcfg): WriteFS now preserves Others and Deprecations#1979
openshift-merge-bot[bot] merged 1 commit into
operator-framework:masterfrom
tmshort:fix-OCPBUGS-85347

Conversation

@tmshort
Copy link
Copy Markdown
Contributor

@tmshort tmshort commented May 11, 2026

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

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

Copilot AI review requested due to automatic review settings May 11, 2026 20:54
@openshift-ci openshift-ci Bot requested review from camilamacedo86 and pedjak May 11, 2026 20:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Others and Deprecations in the per-package DeclarativeConfig written by WriteFS.
  • Write package-less Others to a root-level catalog.<ext> file (consistent with writeToEncoder behavior).
  • Add a WriteFS unit test validating on-disk contents and a LoadFS round-trip for Others/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.

Comment thread alpha/declcfg/write_test.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 86.79245% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.88%. Comparing base (3855305) to head (e132825).
⚠️ Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
alpha/declcfg/write.go 86.79% 3 Missing and 4 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@grokspawn
Copy link
Copy Markdown
Contributor

Can we converge implementation with writeToEncoder?
Existing WriteJSON & WriteYAML methods there use a unified output approach which includes all currently-known schemas, plus a single touchpoint to make future schemas available easily.

@tmshort tmshort force-pushed the fix-OCPBUGS-85347 branch 2 times, most recently from 5e24fa4 to cc6a25b Compare May 11, 2026 21:06
Copilot AI review requested due to automatic review settings May 11, 2026 21:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pName from all schema types (channels/bundles/others/deprecations) and uses it directly in filepath.Join(rootDir, pName). Because LoadFS does not validate Channel.Package/Bundle.Package/etc, a malicious declarative config could set package to values like "../../outside" or an absolute path and cause WriteFS to write outside rootDir (directory traversal). Please validate/sanitize pName before 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))

@tmshort tmshort force-pushed the fix-OCPBUGS-85347 branch from cc6a25b to d0d7a08 Compare May 11, 2026 21:11
Comment thread alpha/declcfg/write.go Outdated
Copilot AI review requested due to automatic review settings May 12, 2026 13:26
@tmshort tmshort force-pushed the fix-OCPBUGS-85347 branch from d0d7a08 to 823717c Compare May 12, 2026 13:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread alpha/declcfg/write.go Outdated
@tmshort tmshort force-pushed the fix-OCPBUGS-85347 branch from 823717c to ef0ced1 Compare May 12, 2026 13:59
Comment thread alpha/declcfg/write.go Outdated
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remodel/remove the comment here. I'm not comfortable with a claude-based rewording of my review comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did have to clarify what you wanted, and I hope I was correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@tmshort tmshort force-pushed the fix-OCPBUGS-85347 branch from ef0ced1 to e132825 Compare May 12, 2026 15:52
Copilot AI review requested due to automatic review settings May 12, 2026 15:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread alpha/declcfg/write.go

func writeToEncoder(cfg DeclarativeConfig, enc encoder) error {
pkgNames := sets.NewString()
func configsByPackage(cfg DeclarativeConfig) (sets.Set[string], map[string]DeclarativeConfig, []Meta) {
Copy link
Copy Markdown
Contributor

@grokspawn grokspawn May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This triple-return really feels like a wanna-be struct.

@grokspawn
Copy link
Copy Markdown
Contributor

/approve

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 12, 2026

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 12, 2026
@joelanford
Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label May 12, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit e7d7929 into operator-framework:master May 12, 2026
17 checks passed
@tmshort tmshort deleted the fix-OCPBUGS-85347 branch May 12, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants