Skip to content

Comments

feat: enable use of CEL expressions for CR valueFrom#2868

Open
alexandernorth wants to merge 10 commits intokubernetes:mainfrom
alexandernorth:feature/custom-resource-cel-expressions
Open

feat: enable use of CEL expressions for CR valueFrom#2868
alexandernorth wants to merge 10 commits intokubernetes:mainfrom
alexandernorth:feature/custom-resource-cel-expressions

Conversation

@alexandernorth
Copy link

@alexandernorth alexandernorth commented Feb 6, 2026

What this PR does / why we need it:

Adds CEL (Common Expression Language) support to Custom Resource State metrics for transforming and extracting values from custom resources.

CEL expressions enable more complex calculations, conditional logic, array/object iteration, and dynamic label generation directly in metric configurations, with a low cost overhead. This is more flexible than the existing path-based approach for complex data structures (multi-level, iteration, etc).

Examples:

Static number:

valueFrom:
  celExpr: "1.0"

Iterate over arrays adding dynamic labels:

valueFrom:
  celExpr: "value.map(c, WithLabels(c.status, {'type': c.type}))"

Path-based valueFrom continues to work unchanged for backwards compatibility.

The documentation is also updated to include examples and details on the implementation customresourcestate-metrics.md

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
None.

Which issue(s) this PR fixes: (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged)
I did not find a specific comment, but it does solve a TODO regarding multi-length valueFrom paths: #1958 (comment)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: alexandernorth
Once this PR has been reviewed and has the lgtm label, please assign mrueg for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Feb 6, 2026
@k8s-ci-robot k8s-ci-robot requested a review from mrueg February 6, 2026 16:15
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 6, 2026
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG Instrumentation Feb 6, 2026
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 6, 2026
@alexandernorth alexandernorth changed the title Feature/custom resource cel expressions feat: enable use of CEL expressions for CR valueFrom Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants