mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Alter wording to describe pods using a pvc
This commit is contained in:
parent
ededd08ba1
commit
bcff03f7d2
@ -1525,17 +1525,17 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri
|
|||||||
|
|
||||||
pc := d.CoreV1().Pods(namespace)
|
pc := d.CoreV1().Pods(namespace)
|
||||||
|
|
||||||
mountPods, err := getMountPods(pc, pvc.Name)
|
pods, err := getPodsForPVC(pc, pvc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
events, _ := d.CoreV1().Events(namespace).Search(scheme.Scheme, pvc)
|
events, _ := d.CoreV1().Events(namespace).Search(scheme.Scheme, pvc)
|
||||||
|
|
||||||
return describePersistentVolumeClaim(pvc, events, mountPods)
|
return describePersistentVolumeClaim(pvc, events, pods)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMountPods(c corev1client.PodInterface, pvcName string) ([]corev1.Pod, error) {
|
func getPodsForPVC(c corev1client.PodInterface, pvcName string) ([]corev1.Pod, error) {
|
||||||
nsPods, err := c.List(context.TODO(), metav1.ListOptions{})
|
nsPods, err := c.List(context.TODO(), metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []corev1.Pod{}, err
|
return []corev1.Pod{}, err
|
||||||
@ -1544,10 +1544,8 @@ func getMountPods(c corev1client.PodInterface, pvcName string) ([]corev1.Pod, er
|
|||||||
var pods []corev1.Pod
|
var pods []corev1.Pod
|
||||||
|
|
||||||
for _, pod := range nsPods.Items {
|
for _, pod := range nsPods.Items {
|
||||||
pvcs := getPvcs(pod.Spec.Volumes)
|
for _, volume := range pod.Spec.Volumes {
|
||||||
|
if volume.VolumeSource.PersistentVolumeClaim != nil && volume.VolumeSource.PersistentVolumeClaim.ClaimName == pvcName {
|
||||||
for _, pvc := range pvcs {
|
|
||||||
if pvc.PersistentVolumeClaim.ClaimName == pvcName {
|
|
||||||
pods = append(pods, pod)
|
pods = append(pods, pod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1556,23 +1554,11 @@ func getMountPods(c corev1client.PodInterface, pvcName string) ([]corev1.Pod, er
|
|||||||
return pods, nil
|
return pods, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPvcs(volumes []corev1.Volume) []corev1.Volume {
|
func describePersistentVolumeClaim(pvc *corev1.PersistentVolumeClaim, events *corev1.EventList, pods []corev1.Pod) (string, error) {
|
||||||
var pvcs []corev1.Volume
|
|
||||||
|
|
||||||
for _, volume := range volumes {
|
|
||||||
if volume.VolumeSource.PersistentVolumeClaim != nil {
|
|
||||||
pvcs = append(pvcs, volume)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pvcs
|
|
||||||
}
|
|
||||||
|
|
||||||
func describePersistentVolumeClaim(pvc *corev1.PersistentVolumeClaim, events *corev1.EventList, mountPods []corev1.Pod) (string, error) {
|
|
||||||
return tabbedString(func(out io.Writer) error {
|
return tabbedString(func(out io.Writer) error {
|
||||||
w := NewPrefixWriter(out)
|
w := NewPrefixWriter(out)
|
||||||
printPersistentVolumeClaim(w, pvc, true)
|
printPersistentVolumeClaim(w, pvc, true)
|
||||||
printPodsMultiline(w, "Mounted By", mountPods)
|
printPodsMultiline(w, "Used By", pods)
|
||||||
|
|
||||||
if len(pvc.Status.Conditions) > 0 {
|
if len(pvc.Status.Conditions) > 0 {
|
||||||
w.Write(LEVEL_0, "Conditions:\n")
|
w.Write(LEVEL_0, "Conditions:\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user