Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output which pods are in use by a pvc when kubectl describe pvc is run #65837

Merged

Conversation

clandry94
Copy link

@clandry94 clandry94 commented Jul 5, 2018

What this PR does / why we need it:
This PR implements a feature request to display the pods mounted to a PVC when kubectl describe pvc is ran. We need it since the only way to see which pods are bound to a PVC is by checking the volume mounts of each individual pod in the namespace.

Example Output:

$ kubectl get pods,pvc
NAME     READY  STATUS    RESTARTS   AGE
test-pod   1/1       Running       0                2h

NAME      STATUS    VOLUME                                   CAPACITY  ACCESS MODES   STORAGECLASS        AGE
test-pvc  Bound     pvc-718681dd-70cc-11e7-aa14-42010af00029   100Gi      RWO            us-east1-b          345d
$ kubectl describe pvc
Name:          elasticsearch-data-elasticsearch-data-us-east1-b-0
Namespace:     partners-production
StorageClass:  us-east1-b
Status:        Bound
Volume:      pvc-718681dd-70cc-11e7-aa14-42010af00029
Labels:       <none>
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      1Gi
Access Modes:  RWO
Events:        <none>
Mounted By:     test-pod

Pods using the PVC are shown with the Mounted By field

Which issue(s) this PR fixes:
Closes #65233

Special notes for your reviewer:

Release note:

Running `kubectl describe pvc` now shows which pods are mounted to the pvc being described with the `Mounted By` field

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 5, 2018
@clandry94
Copy link
Author

/sig storage
/sig cli

@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/cli Categorizes an issue or PR as relevant to SIG CLI. labels Jul 5, 2018
@clandry94 clandry94 changed the title output which pods are using the pvc in use when kubectl describe is run output which pods are a pvc in use when kubectl describe pvc is run Jul 5, 2018
@idealhack
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 5, 2018
@clandry94
Copy link
Author

/test pull-kubernetes-integration

@clandry94
Copy link
Author

/test pull-kubernetes-e2e-kops-aws

@clandry94
Copy link
Author

/assign @mengqiy

@idealhack
Copy link
Member

@kubernetes/sig-storage-pr-reviews

}

func getMountPods(c coreclient.PodInterface, pvcName string) ([]api.Pod, error) {
nsPods, err := c.List(metav1.ListOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should set a limit as part of ListOptions in order to chunk potentially large responses? Don't feel strongly on this though cc @soltysh

Copy link
Author

@clandry94 clandry94 Jul 6, 2018

Choose a reason for hiding this comment

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

I don't see any other usages of limiting ListOptions for other describe operations, so I figure that it hasn't been an issue yet. I have no opinion on the matter though. If you think we should set a limit, I will.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't expect that list to be that long, besides kubectl describe can and should be verbose. It's in the kubectl get where we try to save space with more... and similar.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/approve

Please squash your changes and we'll push it forward.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 6, 2018
sort pods in kubectl describe pvc with user-defined alignment
@clandry94
Copy link
Author

squashed 👍

@juanvallejo
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 6, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clandry94, juanvallejo, soltysh

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

The pull request process is described here

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-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@juanvallejo
Copy link
Contributor

/test pull-kubernetes-e2e-gce

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 65838, 65837). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 54db227 into kubernetes:master Jul 6, 2018
@dsalamancaMS
Copy link

Amazing! thanks @clandry94 for making this happen!

@clandry94 clandry94 changed the title output which pods are a pvc in use when kubectl describe pvc is run output which pods are in use by a pvc when kubectl describe pvc is run Jul 6, 2018
@clandry94 clandry94 deleted the pvc_describe_claimed_by branch August 2, 2018 16:18
@ps10
Copy link

ps10 commented Nov 25, 2019

Hi @clandry94,
Is there a similar solution implemented in Kubernetes Python API.
I have tried using read_namespaced_persistent_volume_claim, which returns the PVC Object. However, this does not contain the Pod that is mounting this PVC.

Specifically, does the PersistentVolumeClaim object now have the field which is queried for "Mounted By", or the solution implemented here goes through all the Pods searching for the particular PVC, and displays the Pod Name.

Any pointers on this would of great help.

Regards

@danielma156
Copy link

Would it be possible to have getMountPods() exposed to the Golang API? Was looking for this exact method to use but just had to copy and paste it over to my own code. Seems odd to not expose it to the wider API, and just restrict it to kubectl describe. So similar to @ps10's request, expose the "Mounted By" to the PersistentVolumeClaimStatus perhaps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display which Pods have the PVC in use.
10 participants