Skip to content

Conversation

@r4f4
Copy link
Contributor

@r4f4 r4f4 commented Feb 26, 2025

Description

  • Introduce a generic json/yaml parser functions
  • Refactor and dedup code in oci-manifest.go
  • Fixed unit tests to match error and/or return value
  • Add more unit tests

Github / Jira issue:

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code Improvements (Refactoring, Performance, CI upgrades, etc)
  • Internal repo assets (diagrams / docs on github repo)
  • This change requires a documentation update on openshift docs

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Expected Outcome

Please describe the outcome expected from the tests.

@r4f4 r4f4 force-pushed the oci-manifest-refactor branch 2 times, most recently from a6b854f to d699a4f Compare February 27, 2025 09:25
Copy link
Contributor

@sherine-k sherine-k left a comment

Choose a reason for hiding this comment

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

thanks @r4f4
This helps a lot!
Few nits , but nothing critical.
Finally, sharing with you one last refactoring task we had in mind:
Move GetOperatorConfig and GetReleaseSchema out of this package and into operator and release packages instead.
In fact, these are used only by these domains. But they force us to mock these methods in almost all the unit tests where manifest package is needed.

@@ -0,0 +1,63 @@
//nolint:ireturn // generic T should be fine to return here
package common
Copy link
Contributor

Choose a reason for hiding this comment

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

Great idea adding these methods

Comment on lines -259 to -262
func setInternalLog(log clog.PluggableLoggerInterface) {
if internalLog == nil {
internalLog = log
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

log.Debug("completed test %v ", res)
res, err := manifest.GetImageManifest(common.TestFolder + "image-manifest.json")
assert.NoError(t, err)
assert.Equal(t, expectedOCI, res)
Copy link
Contributor

Choose a reason for hiding this comment

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

Many thanks! ❤️

@openshift-ci
Copy link

openshift-ci bot commented Feb 27, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: r4f4, sherine-k

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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 Feb 27, 2025
@r4f4 r4f4 force-pushed the oci-manifest-refactor branch from d699a4f to e9ffe9e Compare February 27, 2025 17:08
@lmzuccarelli
Copy link
Contributor

/retitle no-jira: v2/manifest/oci-manifest: refactor and dedup the code

@openshift-ci openshift-ci bot changed the title v2/manifest/oci-manifest: refactor and dedup the code no-jira: v2/manifest/oci-manifest: refactor and dedup the code Mar 6, 2025
@openshift-ci-robot
Copy link

@r4f4: This pull request explicitly references no jira issue.

In response to this:

Description

  • Introduce a generic json/yaml parser functions
  • Refactor and dedup code in oci-manifest.go
  • Fixed unit tests to match error and/or return value
  • Add more unit tests

Github / Jira issue:

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code Improvements (Refactoring, Performance, CI upgrades, etc)
  • Internal repo assets (diagrams / docs on github repo)
  • This change requires a documentation update on openshift docs

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Expected Outcome

Please describe the outcome expected from the tests.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 6, 2025
@lmzuccarelli
Copy link
Contributor

Verified locally using custom CICD for any v2 regression

M2D
D2M
M2M
Delete generate
Delete

@lmzuccarelli
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 6, 2025
@aguidirh
Copy link
Contributor

aguidirh commented Mar 6, 2025

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 6, 2025
Copy link
Contributor

@aguidirh aguidirh left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @r4f4, it will help a lot to maintain the code in the long term.

I really like the new package, it will reduce a lot the duplications.

I added only a nit comment. LGTM as well.

return obj, fmt.Errorf("error during CatalogSource generation using template: error reading targetCatalogSourceTemplate file %s: %v", templateFile, err)
}
err = yaml.Unmarshal(bytesRead, &obj)
obj, err = common.ParseYamlFile[ofv1alpha1.CatalogSource](templateFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, this will help a lot avoiding the duplication of Unmarshal/Marshal

@@ -0,0 +1,59 @@
package common
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this package @r4f4.

Nit: since the package only contains parsers, what about renaming it to something like parser (or something else in case of conflict) ?

In this way we follow the package names guidelines (https://go.dev/blog/package-names)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

r4f4 added 4 commits March 6, 2025 20:54
Reading a file and parsing the data as json/yaml into a variable of type
`T` is a very common task. By having a generic function for them, we
make sure the error messages are consistent across the code base.
I have also added more unit tests.
@r4f4 r4f4 force-pushed the oci-manifest-refactor branch from e9ffe9e to 23951eb Compare March 6, 2025 19:54
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 6, 2025
@openshift-ci
Copy link

openshift-ci bot commented Mar 6, 2025

@r4f4: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@aguidirh
Copy link
Contributor

aguidirh commented Mar 7, 2025

Thanks a lot @r4f4, this refactoring is going to help a lot.

@aguidirh
Copy link
Contributor

aguidirh commented Mar 7, 2025

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 7, 2025
@aguidirh
Copy link
Contributor

aguidirh commented Mar 7, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 7, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 2293058 into openshift:main Mar 7, 2025
7 checks passed
@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

Distgit: oc-mirror-plugin
This PR has been included in build oc-mirror-plugin-container-v4.19.0-202503071410.p0.g2293058.assembly.stream.el9.
All builds following this will include this PR.

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. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants