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 removing array type values in machine pool configs #10741

Merged
merged 6 commits into from
Apr 18, 2024

Conversation

momesgin
Copy link
Member

@momesgin momesgin commented Apr 2, 2024

Summary

Fixes #10693

In rke2.vue, before saving the new changes made to the machine pools configuration we run syncMachineConfigWithLatest function, it gets the latest(last saved) config from the BE, then uses Lodash merge function to update it with the current changes made by the user. The problem is that if the user removes an item from an array type config value(e.g. network in vSphere), it will never work due to the default behaviour of Lodash merge function. Example:

const lastSavedConfigFromBE = { a: ["test"] };
const currentConfigByUser = { a: [] };

merge(lastSavedConfigFromBE, currentConfigByUser) // { a: ["test"] }

A new helper function customMerge is created to address the issue by correctly replacing the old array values with the new values during the merge process.

Areas or cases that should be tested

This change is not limited to vSphere's machine pool config, any array type values for any provider's machine pool config will be affected. I haven't found any examples so far, but I believe the removing issue exists for any provider's array type value in their machine pool config, and this PR should fix them too.

Areas which could experience regressions

Same as above.

Screenshot/Video

Screen.Recording.2024-04-02.at.1.26.27.PM.mov

Checklist

  • The PR is linked to an issue and the linked issue has a Milestone, or no issue is needed
  • The PR has a Milestone
  • The PR template has been filled out
  • The PR has been self reviewed
  • The PR has a reviewer assigned
  • The PR has automated tests or clear instructions for manual tests and the linked issue has appropriate QA labels, or tests are not needed
  • The PR has reviewed with UX and tested in light and dark mode, or there are no UX changes

@momesgin momesgin added this to the v2.9.0 milestone Apr 2, 2024
@momesgin momesgin self-assigned this Apr 2, 2024
codyrancher
codyrancher previously approved these changes Apr 3, 2024
Copy link
Contributor

@codyrancher codyrancher left a comment

Choose a reason for hiding this comment

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

I have a feeling that we're going to want to change the functionality of syncMachineConfigWithLatest and just replace the metadata instead of merging.

With that said, let's see how this works in practice.

*
* This helper function addresses the issue by always replacing the old array with the new array during the merge process.
*/
export function customMerge(obj1 = {}, obj2 = {}): Object {
Copy link
Member

@richard-cox richard-cox Apr 8, 2024

Choose a reason for hiding this comment

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

I'm not sure of the possible usages outside of shell/edit/provisioning.cattle.io.cluster, can this live there and be titled something like poolConfigMerge?

Otherwise it probably needs to be generic and go into utils/object

shell/utils/custom-merge.ts Outdated Show resolved Hide resolved
Copy link
Member

@richard-cox richard-cox left a comment

Choose a reason for hiding this comment

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

I haven't validated by vsphere creds yet, but general edit of non-vsphere looks good. If you've validated the issue is resolved then lets get this in.

@momesgin
Copy link
Member Author

I haven't validated by vsphere creds yet, but general edit of non-vsphere looks good. If you've validated the issue is resolved then lets get this in.

I just tested it and it works as expected

@momesgin momesgin merged commit 4af6e26 into rancher:master Apr 18, 2024
25 checks passed
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.

vSphere - Network, Tags and Parameters can be added but not removed
3 participants