-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] Fix missing package-level vars in GCP policy editor #132068
Conversation
Display package-level variables even if they aren't defined on the existing package policy during an upgrade, honoring default values for all variables if they exist. Fixes elastic#131251
Pinging @elastic/fleet (Team:Fleet) |
if (!packagePolicy.vars || !packagePolicy.vars[varName]) return null; | ||
const value = packagePolicy.vars[varName].value; | ||
const { name: varName, type: varType, default: defaultValue } = varDef; | ||
const value = packagePolicy.vars?.[varName]?.value ?? defaultValue; |
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.
Should we populate packagePolicy.vars?.[varName]?.value
with the default value here instead of displaying the default value, I think if the user do not change the value it will not be saved no? (not tested locally)
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 just pushed up fede140 which should address this. We now create the vars[varName]
object entry on packagePolicy
and set the default value if necessary, and the values/vars persist as expected.
const value = packagePolicy.vars?.[varName]?.value ?? defaultValue; | ||
|
||
// Set up the `vars` object and assign the default value if it doesn't exist | ||
if (!packagePolicy.vars) { |
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.
it seems odd to me to reassign vars in a component render, can we do this in a useEffect
calling onChange
?
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.
Moved this logic to the existing useEffect
and verified things still work in 2e2469e.
Also added tests.
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @kpollich |
Before version 8.3.0 a bug in the Fleet UI configuration conflict resolution screen would prevent a successful update of this package to the new version. The constraint is updated on Kibana >= 8.3 where the related fix landed[1] so we can guarantee a working upgrade path. [1]: elastic/kibana#132068
Before version 8.3.0 a bug in the Fleet UI configuration conflict resolution screen would prevent a successful update of this package to the new version. The constraint is updated on Kibana >= 8.3 where the related fix landed[1] so we can guarantee a working upgrade path. [1]: elastic/kibana#132068
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
…132068) * Fix missing package-level vars in GCP policy editor Display package-level variables even if they aren't defined on the existing package policy during an upgrade, honoring default values for all variables if they exist. Fixes elastic#131251 * Fix not persisting default values for new variables * Fix tests * Address PR feedback + update tests (cherry picked from commit 5fff510) # Conflicts: # x-pack/plugins/fleet/common/services/validate_package_policy.test.ts # x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_define_package_policy.test.tsx
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
…132068) (#136289) * [Fleet] Fix missing package-level vars in GCP policy editor (#132068) * Fix missing package-level vars in GCP policy editor Display package-level variables even if they aren't defined on the existing package policy during an upgrade, honoring default values for all variables if they exist. Fixes #131251 * Fix not persisting default values for new variables * Fix tests * Address PR feedback + update tests (cherry picked from commit 5fff510) # Conflicts: # x-pack/plugins/fleet/common/services/validate_package_policy.test.ts # x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/step_define_package_policy.test.tsx * Remove incorrect test * Remove define package policy tests from 7.17.x Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@endorama - Just finished backporting this (had some dependent PR's) to 7.17. Let me know if any issues arise. Thanks. |
Summary
Display package-level variables even if they aren't defined on the existing package policy during an upgrade, honoring default values for all variables if they exist.
Fixes #131251
Testing
See #131251 (comment) for detailed testing instructions. You'll need a copy of the WIP
gcp-2.0.0
integration attached to that issue, and a local package registry instance serving that integration.Screen Recording
Recording demonstrates proper rendering of package-level variables when upgrading from 1.5.0 -> 2.0.0 for the
gcp
integration. Previously, these package-level variables were not rendered in the UI.Screen.Recording.2022-05-11.at.4.02.17.PM.mov