-
Notifications
You must be signed in to change notification settings - Fork 261
feat(opm): merge objects of same unique key in alpha diff
#823
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
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: estroz The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov Report
@@ Coverage Diff @@
## master #823 +/- ##
==========================================
+ Coverage 52.07% 52.50% +0.42%
==========================================
Files 103 104 +1
Lines 9092 9220 +128
==========================================
+ Hits 4735 4841 +106
- Misses 3449 3463 +14
- Partials 908 916 +8
Continue to review full report at Codecov.
|
dcbfd6e to
fcea83f
Compare
|
I'm still concerned that this puts
If this is a specific need of the |
|
All valid concerns. I do actually think, in the long term,
For now this is totally fine with me. |
|
Is the result of this consistent with how |
|
It appears to do some sort of merging or deduplication (I didn't do an exhaustive test). Take a look at this FBC:
When I serve it, it ignores (or merges) the duplicates: |
fcea83f to
f717b79
Compare
Looking at the code, I think you're right! But I think this is a regression. At one point, I'm fairly sure |
alpha diff
|
Now taking the time to look back through the history of the FBC implementation, I didn't find any code that actually prevented duplicates. It looks like the code has always just accepted the last duplicate item (i.e. no merging, just throw away the old thing and keep the new thing when I encounter a duplicate) I still consider this an error though because a declarative API (which FBC is), should disallow such ambiguity. Declaring "I want A to look like X AND I want A to look like Y" just doesn't make sense. PR to fix this is #824. |
03ea0e0 to
128a2a0
Compare
…e key Signed-off-by: Eric Stroczynski <ericstroczynski@gmail.com>
|
/cc @joelanford |
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
128a2a0 to
4124d2e
Compare
joelanford
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.
Sorry for the delay on the review. I left a few comments related to some hopefully minor refactoring.
However, I am still concerned that doing this type of merging runs counter to the declarative nature of FBC.
It looks like we're merging old on its own, merging new on its own, and then diffing the individually merged models. I question why old and new are ever in a state where they need to be merged in the first place. Shouldn't they both already be fully valid FBCs?
…implements as an interface This change as a Merger interface and two concrete types, PreferLast and TwoWay, that merge FBC objects. Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
alpha/declcfg/merge.go
Outdated
| } | ||
| // Merger is an object that will complete merge actions declarative config options | ||
| type Merger interface { | ||
| MergeDC(*DeclarativeConfig) error |
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.
Nit:
| MergeDC(*DeclarativeConfig) error | |
| Merge(*DeclarativeConfig) error |
Its in the declcfg package and its only parameter is a *DelcarativeConfig, so IMO including DC in the function name is redundant.
alpha/action/diff.go
Outdated
| if err != nil { | ||
| return nil, fmt.Errorf("error setting merge type: %v", err) | ||
| } | ||
| if err := a.Merger.MergeDC(oldCfg); err != nil { |
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.
I'm still confused by what it means to merge a single *declcfg.DeclarativeConfig.
Shouldn't we be expecting any given individual FBC to be valid?
I would have expected to see something like:
// Validate the old config
oldModel, err := declcfg.ToModel(oldCfg)
if err != nil {
return nil, err
}
if err := oldModel.Validate(); err != nil {
return nil, err
}
// Validate the new config
newModel, err := declcfg.ToModel(newCfg)
if err != nil {
return nil, err
}
if err := newModel.Validate(); err != nil {
return nil, err
}
// Merge them together
if err := a.Merger.Merge(oldCfg, newCfg); err != nil {
return nil, err
}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.
Sorry @joelanford, I think I missed the earlier comment when you mentioned this concern before. I think the use-case for keeping the single argument to the Merge function is that the oldCfg and the newCfg are generated by Render. Since render isn't handling duplicate objects it would be possible for the FBC created by the groups of OldRefs and NewRefs could be invalid. Would changing from Merge to Normalize make more sense here?
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.
Would changing from Merge to Normalize make more sense here?
Perhaps
oldCfgand thenewCfgare generated by Render.
Makes sense, but what's the case that led to those needing to be normalized? Shouldn't old and new be valid standalone FBCs?
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.
What I want to avoid is having our exported libraries normalize the possibility of an FBC being invalid and us providing code that can turn an FBC from invalid to valid.
If there's something happening in opm alpha diff that gives rise to the need to normalize some intermediate FBC state, I think all of this is fine, but I'd probably make it internal and unexported.
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.
Just adding some info here for historical purposes -
- The merge functionality was public because it is required by
oc-mirror, but we have agreed to move this functionality directly into theoc-mirrorcodebase since the requirement to normalize invalid FBCs is a unique use-case.
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.
Can you clarify? Is the entire merge function moving to oc-mirror or just the single-fbc normalization function?
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.
Just the single-fbc normalization work proposed on this PR was moved to oc-mirror
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
|
@estroz: PR needs rebase. 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/test-infra repository. |
|
opm diff has moved to |
Description of the change:
opm alpha diffnow merges packages, channels, and bundles that have the same unique key with ascending preference.Motivation for the change: Deduplicate data that may cause errors at runtime
Test this change by building
opmthen comparing the output of master and this branch'sopm alpha diffon some test catalogs I built:Reviewer Checklist
/docs