Skip to content

Allocation metrics attach pod UIDs from other namespaces #4041

Description

@brianr2600

OpenCost v1.121.1 keys its pod UID and phase maps by pod name, omitting namespace. For identically named pods in different namespaces, the last pod returned by GetAllPods() supplies both entries. Allocation metrics retain their namespace labels but receive the same UID, breaking joins on (namespace, pod, uid).

As of September 11, 2026, The defect remains in develop at a1b6790e

podStatus[pod.Name] = pod.Status.Phase
podUIDs[pod.Name] = string(pod.UID)

Direct exporter output confirmed the mismatch in container_cpu_allocation and container_memory_allocation_bytes. The emitted UID switched repeatedly while Kubernetes reported stable, distinct UIDs for the two pods.

Source shows the same lookup supplies UID labels for container_gpu_allocation and pod_pvc_allocation. The phase map controls containerSeen and metric cleanup, so an identically named pod in another namespace can also affect retention.

Reproduce

  1. Run database-0 in namespaces team-a and team-b, with nonzero CPU and RAM requests. Confirm both are Running and record their Kubernetes UIDs.
  2. Inspect their CPU/RAM allocation series directly at OpenCost's /metrics endpoint.
  3. Compare each series' (namespace, pod, uid) labels with Kubernetes. Both pods receive the UID of the last same-named pod enumerated by the exporter. Node placement does not affect the lookup.

Example with placeholder UIDs when team-b is enumerated last:

Pod Kubernetes UID Exported UID
team-a/database-0 uid-a uid-b
team-b/database-0 uid-b uid-b

Fix

Key UID and phase by (namespace, pod). Allocation labels must use that pod's UID; lifecycle bookkeeping must use its phase. Missing metadata must not fall back to an identically named pod in another namespace.

#4040 implements the fix and tests namespace isolation with distinct UIDs/phases, reversed enumeration order, and missing metadata.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions