8000 fix(application-create): prevent crash when switching from YAML to form with valuesObject by Ruby-rc · Pull Request #22368 · argoproj/argo-cd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(application-create): prevent crash when switching from YAML to form with valuesObject #22368

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ruby-rc
Copy link
@Ruby-rc Ruby-rc commented Mar 17, 2025

Fix #22367

What this PR does

Fixes a crash that occurs when switching from YAML to form mode during application creation, in cases where valuesObject is defined in the YAML.

How it was fixed

Added handling for the valuesObject field in the form mode to prevent the crash.

image

Why this change is necessary

The valuesObject field structure is consistent with the configuration options. It is only displayed on the frontend and is not meant to be overridden, which is now properly handled.

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.
  • 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.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Copy link
bunnyshell bot commented Mar 17, 2025

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@Ruby-rc Ruby-rc force-pushed the fix/helm-value-edit branch 2 times, most recently from 8cb660d to 6971b5a Compare March 19, 2025 04:23
@Ruby-rc Ruby-rc marked this pull request as ready for review March 19, 2025 06:07
@Ruby-rc Ruby-rc requested a review from a team as a code owner March 19, 2025 06:07
Copy link
Member
@nitishfy nitishfy left a comment

Choose a reason for hiding this comment

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

Thanks, this is on my list. I'll start reviewing this PR shortly.

@nitishfy nitishfy self-assigned this Mar 19, 2025
Comment on lines 145 to 174
function mergeAndFormatHelmValues(valuesObject: any, values: string) {
if (!valuesObject && !values) {
return '';
}
//Order of precedence: valuesObject > values
const mergedValueObject = merge(jsYaml.load(values || ''), valuesObject || {});
return jsYaml.dump(mergedValueObject);
}

function flattenObject(obj: any, parentPath = '', result = {} as any) {
forEach(obj, (value, key) => {
const fullPath = parentPath ? (isArray(obj) ? `${parentPath}[${key}]` : `${parentPath}.${key}`) : key;
if (isObject(value) || isArray(value)) {
flattenObject(value, fullPath, result);
} else {
result[fullPath] = value;
}
});
return result;
}

function unflattenedObject(obj: any) {
const result = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
set(result, key, obj[key]);
}
}
return result;
}
Copy link
Member

Choose a reason for hiding this comment

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

Could we have some unit tests for these utility functions? I think we're trying to mimic Helm's values file merging behavior. If we find later that our merge algorithms differ from Helm's, it would be good to have unit tests to help safely change our algorithm to match Helm's.

Copy link
Author

Choose a reason for hiding this comment

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

I completely agree!

Give me some time to review the original Helm's values file merging behavior and add test cases for these functions.

Copy link
Author

Choose a reason for hiding this comment

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

Hello! @crenshaw-dev @nitishfy

I've reviewed the backend implementation of Helm values handling, particularly focusing on SetValuesString and ValuesYAML methods in https://github.com/argoproj/argo-cd/blob/master/pkg/apis/application/v1alpha1/values.go#L15

In my view, the current backend implementation follows a clear pattern:

  1. ValuesObject takes precedence over Values (as documented in CRD)
  2. When setting values through SetValuesString:
    • Converts YAML to JSON and stores in ValuesObject
    • Clears the Values field to avoid conflicts
  3. When retrieving values through ValuesYAML:
    • Returns ValuesObject if present (converted back to YAML)
    • Falls back to Values if ValuesObject is nil

However, our current UI form doesn't reflect this implementation, which creates two UX issues:

  1. Values edited in YAML view may appear differently in form view due to the internal conversion
  2. Users have no visibility into which field (values or valuesObject) is actually being used

I propose two potential solutions:

  1. Enhanced UI with Source Visibility (Recommended):

    • Add visual indication of the active values source
    • Provide explicit control over which field to modify
    • Example mockup:
      image
  2. Simplified Single-Field Approach:

    • Always use values field for both display and editing in UI form
    • Remove the dual-field complexity from UI

I recommend the first approach because:

  • It provides transparency into the backend behavior
  • Maintains consistency with the CRD design
  • Gives users explicit control over their configuration

Hope to receive your thoughts on this discussion.

Copy link
Author

Choose a reason for hiding this comment

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

I have updated the description of this PR.
This PR now only fix the issue of preventing a crash when switching from YAML to form mode with valuesObject during application creation.

It does not include any changes to value or parameters, as I believe the UI should only be responsible for displaying configuration, not handling the logic of data merging.

@Ruby-rc Ruby-rc marked this pull request as draft March 26, 2025 16:48
Ruby-rc added 2 commits June 5, 2025 11:28
Signed-off-by: ruichao.hu <ruichao.hu@daocloud.io>
Signed-off-by: ruichao.hu <ruichao.hu@daocloud.io>
@Ruby-rc Ruby-rc force-pushed the fix/helm-value-edit branch from 6971b5a to 99bcaf6 Compare June 5, 2025 03:28
@Ruby-rc Ruby-rc changed the title fix(applications): improve Helm values merging and formatting fix(application-create): prevent crash when switching from YAML to form with valuesObject Jun 5, 2025
@Ruby-rc Ruby-rc marked this pull request as ready for review June 5, 2025 03:38
@Ruby-rc Ruby-rc requested review from crenshaw-dev and nitishfy June 5, 2025 03:38
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.

Page crashes when setting the 'valuesObject' value in the UI YML
3 participants
0