-
Notifications
You must be signed in to change notification settings - Fork 101
no-jira: v2/manifest/oci-manifest: refactor and dedup the code #1098
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
no-jira: v2/manifest/oci-manifest: refactor and dedup the code #1098
Conversation
a6b854f to
d699a4f
Compare
sherine-k
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.
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.
v2/internal/pkg/common/parse.go
Outdated
| @@ -0,0 +1,63 @@ | |||
| //nolint:ireturn // generic T should be fine to return here | |||
| package common | |||
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.
Great idea adding these methods
| func setInternalLog(log clog.PluggableLoggerInterface) { | ||
| if internalLog == nil { | ||
| internalLog = log | ||
| } |
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.
💯
| log.Debug("completed test %v ", res) | ||
| res, err := manifest.GetImageManifest(common.TestFolder + "image-manifest.json") | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, expectedOCI, res) |
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.
Many thanks! ❤️
|
[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 |
d699a4f to
e9ffe9e
Compare
|
/retitle no-jira: v2/manifest/oci-manifest: refactor and dedup the code |
|
@r4f4: This pull request explicitly references no jira issue. In response to this:
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. |
|
Verified locally using custom CICD for any v2 regression M2D |
|
/lgtm |
|
/hold |
aguidirh
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.
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) |
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.
Thanks, this will help a lot avoiding the duplication of Unmarshal/Marshal
v2/internal/pkg/common/parse_test.go
Outdated
| @@ -0,0 +1,59 @@ | |||
| package common | |||
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.
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)
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.
Done.
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.
e9ffe9e to
23951eb
Compare
|
@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. |
|
Thanks a lot @r4f4, this refactoring is going to help a lot. |
|
/unhold |
|
/lgtm |
|
[ART PR BUILD NOTIFIER] Distgit: oc-mirror-plugin |
Description
json/yamlparser functionsGithub / Jira issue:
Type of change
Please delete options that are not relevant.
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.