Fix blank Update Group create page when a ManagedOSVersion has no ownerReferences - #284
Fix blank Update Group create page when a ManagedOSVersion has no ownerReferences#284marcelofukumoto wants to merge 1 commit into
Conversation
managedOSVersionOptions called .find() on version.metadata.ownerReferences without checking it is set. A ManagedOSVersion created outside a channel (for example the custom-images workflow) has no ownerReferences, so the call ran on undefined and threw, leaving the Update Group create form blank. Optional-chain the access so such versions are skipped instead of throwing. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
Why this change is safeQuick write-up on the concern about versions that have no What the change doesThe whole change is adding one // before
version.metadata?.ownerReferences.find(...)
// after
version.metadata?.ownerReferences?.find(...)This line runs when we build the OS version dropdown. We go through every channel and pick the versions that belong to it. A version "belongs" to a channel through its The problem: if a version has no Adding the Is the empty case OK?Yes. A version with no owner = a version that no channel created (someone made it by hand with YAML, or its channel was deleted). Our dropdown groups versions by channel. If a version has no channel, there is simply no group to put it in, so we skip it. That is the correct behavior for a "group by channel" list. We are not inventing this idea either — the list view already expects owner-less versions and just shows Important: before the fix the page did not "hide" this version — it crashed and showed nothing at all. After the fix, everything else shows up fine and only the owner-less version is skipped. So this is strictly better than before. Will it break something else?No.
One thing this does NOT do (on purpose)This fix does not make owner-less versions selectable. They still won't show in the dropdown, because there is no channel to group them under. That was already the case before (and the page just crashed instead), so this is not a regression — it's the same behavior, minus the crash. If we ever want hand-made versions to be selectable, that's a separate, bigger change: add an "Ungrouped / Other" group for versions that don't match any channel. Worth a follow-up if the product wants it, but not needed for this fix. Bottom lineSafe to merge. It removes a crash and keeps everything else exactly the same. |
Summary
Fixes #283
The Update Group create page renders blank when a ManagedOSVersion in the namespace has no
metadata.ownerReferences.Occurred changes and/or fixed issues
managedOSVersionOptionsinpkg/elemental/edit/elemental.cattle.io.managedosimage.vuecalled.find()onversion.metadata?.ownerReferences. The optional chain stops atmetadata, so when a version has noownerReferencesthe call runs onundefinedand throws, aborting the computed and leaving the form blank. One such version breaks the page for all Update Group creation in the namespace.The access is now
version.metadata?.ownerReferences?.find(...). Versions without owner references are skipped (they belong to no channel) instead of throwing.Technical notes summary
A ManagedOSVersion without
ownerReferencesis valid: the operator only stamps owner references on versions it syncs from a channel, so versions created by hand (the custom-images workflow) have none. The rest of the extension already treatsownerReferencesas optional (elemental-config.js,machineinventory.js); this line was the exception.Areas or cases that should be tested
ManagedOSVersionChanneland a standalone ManagedOSVersion withoutownerReferences: the form renders and noTypeErrorappears in the console.Areas which could experience regressions
Screenshot/Video
Update Group create page in a namespace that has a
ManagedOSVersionChanneland aManagedOSVersionwithoutownerReferences.Before — blank form; console shows
TypeError: Cannot read properties of undefined (reading 'find'):After — form renders; the ownerReference-less version is simply not listed as an option:
Checklist
Admin,Standard UserandUser Base