Skip to content

feat: add support for label generation for ephemeral volumes in pod#2891

Open
eminaktas wants to merge 1 commit intokubernetes:mainfrom
eminaktas:feat/add-ephemeral-pvc-info
Open

feat: add support for label generation for ephemeral volumes in pod#2891
eminaktas wants to merge 1 commit intokubernetes:mainfrom
eminaktas:feat/add-ephemeral-pvc-info

Conversation

@eminaktas
Copy link
Copy Markdown

@eminaktas eminaktas commented Mar 10, 2026

Add support for generating the persistentvolumeclaim label for ephemeral volumes in pod volume metrics.

Kubernetes creates PVCs for ephemeral volumes using the naming convention -. This change aligns kube-state-metrics with the upstream implementation to ensure the generated label matches the actual PVC name created by Kubernetes.

Upstream references:

Ephemeral controller PVC creation:
https://github.com/kubernetes/kubernetes/blob/21b427c29960dac4e362d6a9f92817d0b01d78ec/pkg/controller/volume/ephemeral/controller.go#L261

PVC naming helper:
https://github.com/kubernetes/component-helpers/blob/b20f683efd864cebf95ec4a62f4c271cc69b9571/storage/ephemeral/ephemeral.go#L41-L43

Fixes #2490

What this PR does / why we need it: Add support for exposing ephemeral PVCs in kube_pod_spec_volumes_persistentvolumeclaims_info.

How does this change affect the cardinality of KSM: increases

Which issue(s) this PR fixes: Fixes #2490

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 10, 2026
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 10, 2026
@k8s-ci-robot
Copy link
Copy Markdown
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
Copy link
Copy Markdown
Contributor

Welcome @eminaktas!

It looks like this is your first PR to kubernetes/kube-state-metrics 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-state-metrics has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 10, 2026
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG Instrumentation Mar 10, 2026
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 10, 2026
Comment thread internal/store/pod.go
@github-project-automation github-project-automation bot moved this from Needs Triage to In Progress in SIG Instrumentation Mar 11, 2026
@bhope
Copy link
Copy Markdown
Member

bhope commented Mar 11, 2026

Thanks for your contributions! Other than the inline comment, you'd also need to update the docs here: docs/metrics/workload/pod-metrics.md

@eminaktas eminaktas force-pushed the feat/add-ephemeral-pvc-info branch 2 times, most recently from fe39dfb to affb934 Compare March 12, 2026 09:44
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 12, 2026
@bhope
Copy link
Copy Markdown
Member

bhope commented Mar 13, 2026

Thinking about this a bit more, today these metrics are dropped for pods with ephemeral storage. So this change would mean those metrics will now start flowing in, so there would be a slight increase in metric volume (not necessarily cardinality). We should call that out in cardinality section of the PR description.

@eminaktas eminaktas closed this Mar 13, 2026
@eminaktas eminaktas force-pushed the feat/add-ephemeral-pvc-info branch from affb934 to 722f5d2 Compare March 13, 2026 07:58
@github-project-automation github-project-automation bot moved this from In Progress to Closed in SIG Instrumentation Mar 13, 2026
@eminaktas eminaktas reopened this Mar 13, 2026
@github-project-automation github-project-automation bot moved this from Closed to In Progress in SIG Instrumentation Mar 13, 2026
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 15, 2026
@eminaktas eminaktas force-pushed the feat/add-ephemeral-pvc-info branch from 722f5d2 to 1179498 Compare March 16, 2026 07:42
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 16, 2026
@eminaktas eminaktas force-pushed the feat/add-ephemeral-pvc-info branch from 1179498 to 71477d1 Compare March 23, 2026 09:35
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 23, 2026
@eminaktas
Copy link
Copy Markdown
Author

Hi @nmn3m @mrueg @dgrisonnet — could you please take a look at this PR when you get a chance? Thanks!

@bhope
Copy link
Copy Markdown
Member

bhope commented Mar 30, 2026

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 30, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bhope, eminaktas
Once this PR has been reviewed and has the lgtm label, please assign catherinef-dev 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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for reporting PVC names for Pod ephemeral volumes through the existing kube_pod_spec_volumes_persistentvolumeclaims_* metrics, aligning exported labels with Kubernetes’ deterministic PVC naming for ephemeral volumes.

Changes:

  • Extend kube_pod_spec_volumes_persistentvolumeclaims_info (and _readonly) to emit series for spec.volumes[].ephemeral.
  • Update unit/integration tests to expect the new help text and the additional ephemeral-volume series.
  • Update Pod metrics documentation to reflect the expanded metric scope.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
internal/store/pod.go Emits persistentvolumeclaim=<pod>-<volume> labels for ephemeral volumes in the PVC volume metrics.
internal/store/pod_test.go Adds test coverage asserting metrics include an ephemeral volume and derived PVC name.
pkg/app/server_test.go Updates expected HELP text for the affected metrics in the full scrape cycle test.
docs/metrics/workload/pod-metrics.md Updates metric descriptions to mention ephemeral volumes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/store/pod.go
Comment thread internal/store/pod.go
@eminaktas eminaktas force-pushed the feat/add-ephemeral-pvc-info branch from 71477d1 to 5b84233 Compare April 13, 2026 10:08
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 13, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2026
@eminaktas eminaktas force-pushed the feat/add-ephemeral-pvc-info branch from 5b84233 to f59ae4f Compare April 13, 2026 10:09
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2026
@eminaktas eminaktas requested a review from bhope April 14, 2026 10:14
Copy link
Copy Markdown
Member

@bhope bhope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Let's add the documentation in the metric help string for 0 value to avoid user misinterpretation.

Signed-off-by: Emin Aktas <eminaktas34@gmail.com>
@eminaktas eminaktas force-pushed the feat/add-ephemeral-pvc-info branch from f59ae4f to f8d87a8 Compare April 17, 2026 12:52
@eminaktas
Copy link
Copy Markdown
Author

Overall looks good. Let's add the documentation in the metric help string for 0 value to avoid user misinterpretation.

TY. Updated doc for the metric helper.

Comment thread internal/store/pod.go
} else if v.Ephemeral != nil {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"volume", "persistentvolumeclaim"},
LabelValues: []string{ephemeral.VolumeClaimName(p, &v)},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just realized, this may panic at metrics writer (before tests) as it would expect two labels.

Suggested change
LabelValues: []string{ephemeral.VolumeClaimName(p, &v)},
LabelValues: []string{v.Name, ephemeral.VolumeClaimName(p, &v)},

Comment thread internal/store/pod.go
} else if v.Ephemeral != nil {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"volume", "persistentvolumeclaim"},
LabelValues: []string{ephemeral.VolumeClaimName(p, &v)},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Suggested change
LabelValues: []string{ephemeral.VolumeClaimName(p, &v)},
LabelValues: []string{v.Name, ephemeral.VolumeClaimName(p, &v)},

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/store/pod.go
} else if v.Ephemeral != nil {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"volume", "persistentvolumeclaim"},
LabelValues: []string{ephemeral.VolumeClaimName(p, &v)},
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue for the *_readonly metric: LabelKeys contains ("volume", "persistentvolumeclaim") but LabelValues only supplies one string for ephemeral volumes, which will panic when encoding metrics. Include both label values in the correct order.

Suggested change
LabelValues: []string{ephemeral.VolumeClaimName(p, &v)},
LabelValues: []string{v.Name, ephemeral.VolumeClaimName(p, &v)},

Copilot uses AI. Check for mistakes.
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Export pod ephemeral PVCs metrics

4 participants