#7736·headlamp

HPA metrics incorrectly paired by array index and unhandled runtime crash on unpopulated status

Author: harshitnub077Created Sep 22, 2026Updated Sep 22, 2026
Labelskind/bug

Describe the bug

In HorizontalPodAutoscaler (frontend/src/lib/k8s/hpa.ts), metric values in status.currentMetrics are associated with targets in spec.metrics strictly by positional array index (this.status?.currentMetrics?.[iter]).

In Kubernetes autoscaling/v2, status.currentMetrics does not guarantee matching order or length with spec.metrics. When an HPA defines multiple metrics (such as CPU utilization and memory averageValue, or custom/external metrics), or when one metric provider is temporarily unready, the current values get mismatched (e.g. memory values displayed against CPU targets) or display undefined%.

Additionally:

  • In frontend/src/components/horizontalPodAutoscaler/List.tsx and Details.tsx, item.status.currentReplicas is accessed directly without optional chaining. For newly created HPAs where the controller has not yet written a status block, this causes an unhandled runtime exception (Cannot read properties of undefined).
  • In List.tsx, item.spec.minReplicas is optional in the Kubernetes spec (defaults to 1), but currently renders blank when omitted.

Expected outcome:

  • Metrics should be resolved by matching type and metric identifier (resource.name, pods.metric.name, object.metric.name, external.metric.name, containerResource.container + containerResource.name).
  • Unready/newly created HPAs should display fallbacks (-, <unknown>) without throwing runtime errors.
  • minReplicas should fall back to 1 when omitted.

To Reproduce

Steps to reproduce the bug:

  1. Create an HPA with multiple metrics in spec.metrics (e.g. CPU utilization and Memory averageValue).
  2. Open Headlamp and navigate to Horizontal Pod Autoscalers.
  3. Observe that if the controller orders currentMetrics differently (e.g. memory first, then CPU), the values are cross-paired in the UI.
  4. Create a fresh HPA without immediate controller status and navigate to its details page; observe an unhandled runtime error reading properties of undefined.

Environment (please provide info about your environment):

  • Installation type: In-Cluster / Desktop
  • Headlamp Version: main (v0.28.0+)
  • Other: Kubernetes 1.28+ with autoscaling/v2

Are you able to fix this issue?

Yes (I will propose a PR)

Additional Context

Code references:

  • frontend/src/lib/k8s/hpa.ts:214
  • frontend/src/components/horizontalPodAutoscaler/List.tsx:93,105
  • frontend/src/components/horizontalPodAutoscaler/Details.tsx:62,71,77

Source: kubernetes-sigs/headlamp