Skip to content
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

fix: keep array entries not found in live state #14602

Conversation

blakepettersson
Copy link
Member

There's an issue with intersectMap not appending items for array properties where the live array is smaller than the desired array.

Hopefully fixes #9678.

Note on DCO:

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.

Please see Contribution FAQs if you have questions about your pull-request.

@crenshaw-dev
Copy link
Member

This is probably a step in the right direction. It does fail to account for merge keys, though (e.g. in an env array, items should be merged on the name key).

@codecov
Copy link

codecov bot commented Jul 22, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (129cf53) 50.01% compared to head (0b2c96a) 50.00%.
Report is 10 commits behind head on master.

❗ Current head 0b2c96a differs from pull request most recent head fb3d3ba. Consider uploading reports for the commit fb3d3ba to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14602      +/-   ##
==========================================
- Coverage   50.01%   50.00%   -0.02%     
==========================================
  Files         266      262       -4     
  Lines       45971    45059     -912     
==========================================
- Hits        22992    22530     -462     
+ Misses      20731    20321     -410     
+ Partials     2248     2208      -40     
Files Coverage Δ
controller/sync.go 63.43% <93.24%> (+7.51%) ⬆️

... and 54 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

blakepettersson and others added 9 commits September 27, 2023 20:42
There's an issue with `intersectMap` not appending items for array
properties where the live array is smaller than the desired array.

Hopefully fixes argoproj#9678.

Signed-off-by: Blake Pettersson <[email protected]>
The following change between the live and target manifests and all
changes should be present in the normalized result except the changes
to `spec.replicas` and `spec.template.spec.containers[0].image` which
are part of the ignore stanza.

`metadata.labels` - added `appProcess: web` label
`spec.replicas` - changed to 2
`spec.template.metadata.labels` -  added `appProcess: web` label
`spec.templatespec.containers[0].image` - Changed the image tag
`spec.templatespec.containers[0].resources` - Changed from empty object to adding `requests.cpu: 400m`
`spec.templatespec.containers[0]` - Added `env: [{"name": "EV", "value": "here"}]

Signed-off-by: Blake Pettersson <[email protected]>
This makes the test case in 1cb1d86 pass, but this, on the other hand,
makes the test case "will remove fields from target if not present in
live" fail. Will need to dig in more to see if those two test cases can
be reconciled.

Signed-off-by: Blake Pettersson <[email protected]>
Previous test shows adding new values to the Deployment. This additional
test reverses the target/live and tests removing said values.

Renaming testdata to reflect the new usages

Signed-off-by: Blake Pettersson <[email protected]>
This ensures that ignored fields which are not present in live do not
get added to the generated patch.

Signed-off-by: Blake Pettersson <[email protected]>
This merges array entries by their merge key if present. This is
currently hardcoded to `name`, but could potentially be extended to
allow for other merge keys if deemed necessary. This is still rough
around the edges and likely to have edge cases where this won't work as
intended and/or is not performant.

Signed-off-by: Blake Pettersson <[email protected]>
Fixes e2e issue where `ports` (and any other array within an array) was a map instead of an array. Added a TODO as well.

Signed-off-by: Blake Pettersson <[email protected]>
Signed-off-by: Blake Pettersson <[email protected]>
@blakepettersson blakepettersson force-pushed the fix/keep-array-entries-not-found-in-live-state branch from 2c5f39e to fb3d3ba Compare September 27, 2023 20:25
@zswanson
Copy link

@blakepettersson anything you need help with to move this to the finish line?

@crenshaw-dev
Copy link
Member

The new logic looks nicely done, and I appreciate all the unit tests. But I think we might have to address the underlying issue and see if we can implement strategic merge patching instead of plain json patching in ignoreDifferences.

@blakepettersson
Copy link
Member Author

@zswanson time - it's something which sadly has been sorely lacking for me lately. When digging into this locally there are edge-cases upon edge-cases which I bump into, and this is sadly not as trivial as it seems in this PR (and it's already far from trivial).

The deeper I go into the rabbit hole, the more I think that this needs a rethink, and I agree with @crenshaw-dev that another approach is needed.

@crenshaw-dev when you say strategic merge patching, is that the same thing as Server-Side Diff (hence potentially addressed with #13663)?

@crenshaw-dev
Copy link
Member

@blakepettersson not exactly related to server-side diff. It's been a while since I've looked into this code in depth, but iirc we're generating patches using a generic JSON patch library. To handle k8s resources, we really need to use k8s libraries to generate "strategic merge patches," i.e. patches that respect resources' merge keys.

@crenshaw-dev
Copy link
Member

That response is vague, and it's because I don't remember this code well enough to remember exactly how strategic merge patching would be used to solve the problem. :-P

@saumeya
Copy link
Contributor

saumeya commented Feb 6, 2024

Hi @blakepettersson @crenshaw-dev any help needed to move this fix to completion? We also need a fix for this issue.

@blakepettersson
Copy link
Member Author

Hi @saumeya @zswanson et al - due to life circumstances I haven't had the time to look at this for the past couple of months. I just changed jobs, and there's a reasonable chance that I can revisit this PR in a not too long time frame from now. Before iterating on this PR further though, I would like to see if the actual issue could be better addressed by instead making use of Server-Side Apply / Server-Side Diff.

@blakepettersson
Copy link
Member Author

Closing this PR since I don't think this is a viable way to go, see comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sync is not working with ignoreDifferences and RespectIgnoreDifferences=true
4 participants