Fix: Handle undefined metrics in HPA detail view #16169
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #16171
Occurred changes and/or fixed issues
When viewing an HPA (Horizontal Pod Autoscaler) with custom metrics (Pods, External, or Object types), the dashboard throws a TypeError and displays nothing. Users must resort to using
kubectl describe hpato see the metrics.Root Cause:
The
mappedMetricscomputed property in the HPA detail view attempts to access nested properties (metricValue.metric.nameandmetric.resource.name) without null/undefined checks. When the API returns a metric with atypefield but missing the corresponding nested property, accessing.namethrows:TypeError: Cannot read properties of undefined (reading 'name')
Changes Made:
metricValue?.metric?.nameat line 55 (custom metrics)metric.resource?.nameat line 57 (resource metrics)Technical notes summary
The fix uses optional chaining (
?.) to safely access nested properties, following the existing pattern already used at line 72 in the same file (metricValue?.metric?.name ?? null). This is a minimal, defensive coding approach that:Areas or cases that should be tested
Manual testing:
Automated testing:
Areas which could experience regressions
/shell/detail/autoscaling.horizontalpodautoscaler/index.vue)Screenshot/Video
Not applicable - this is a JavaScript error fix with no UI changes. The UI behavior remains the same for valid metrics and now gracefully handles invalid data.
Checklist
Admin,Standard UserandUser Base