mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #126706 from carlory/kubectl-describe-image-volume
show image volume when kubectl describe a pod with image volume
This commit is contained in:
commit
ab26ad0950
@ -1000,6 +1000,8 @@ func describeVolumes(volumes []corev1.Volume, w PrefixWriter, space string) {
|
|||||||
printProjectedVolumeSource(volume.VolumeSource.Projected, w)
|
printProjectedVolumeSource(volume.VolumeSource.Projected, w)
|
||||||
case volume.VolumeSource.CSI != nil:
|
case volume.VolumeSource.CSI != nil:
|
||||||
printCSIVolumeSource(volume.VolumeSource.CSI, w)
|
printCSIVolumeSource(volume.VolumeSource.CSI, w)
|
||||||
|
case volume.VolumeSource.Image != nil:
|
||||||
|
printImageVolumeSource(volume.VolumeSource.Image, w)
|
||||||
default:
|
default:
|
||||||
w.Write(LEVEL_1, "<unknown>\n")
|
w.Write(LEVEL_1, "<unknown>\n")
|
||||||
}
|
}
|
||||||
@ -1481,6 +1483,13 @@ func printCSIPersistentVolumeAttributesMultilineIndent(w PrefixWriter, initialIn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printImageVolumeSource(image *corev1.ImageVolumeSource, w PrefixWriter) {
|
||||||
|
w.Write(LEVEL_2, "Type:\tImage (a container image or OCI artifact)\n"+
|
||||||
|
" Reference:\t%v\n"+
|
||||||
|
" PullPolicy:\t%v\n",
|
||||||
|
image.Reference, image.PullPolicy)
|
||||||
|
}
|
||||||
|
|
||||||
type PersistentVolumeDescriber struct {
|
type PersistentVolumeDescriber struct {
|
||||||
clientset.Interface
|
clientset.Interface
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,53 @@ func TestDescribePodTolerations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDescribePodVolumes(t *testing.T) {
|
||||||
|
pod := &corev1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Volumes: []corev1.Volume{
|
||||||
|
{
|
||||||
|
Name: "image",
|
||||||
|
VolumeSource: corev1.VolumeSource{Image: &corev1.ImageVolumeSource{Reference: "image", PullPolicy: corev1.PullIfNotPresent}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := dedent.Dedent(`
|
||||||
|
Name: bar
|
||||||
|
Namespace: foo
|
||||||
|
Node: <none>
|
||||||
|
Labels: <none>
|
||||||
|
Annotations: <none>
|
||||||
|
Status:
|
||||||
|
IP:
|
||||||
|
IPs: <none>
|
||||||
|
Containers: <none>
|
||||||
|
Volumes:
|
||||||
|
image:
|
||||||
|
Type: Image (a container image or OCI artifact)
|
||||||
|
Reference: image
|
||||||
|
PullPolicy: IfNotPresent
|
||||||
|
QoS Class: BestEffort
|
||||||
|
Node-Selectors: <none>
|
||||||
|
Tolerations: <none>
|
||||||
|
Events: <none>
|
||||||
|
`)[1:]
|
||||||
|
|
||||||
|
fakeClient := fake.NewSimpleClientset(pod)
|
||||||
|
c := &describeClient{T: t, Namespace: "foo", Interface: fakeClient}
|
||||||
|
d := PodDescriber{c}
|
||||||
|
out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, out)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDescribeTopologySpreadConstraints(t *testing.T) {
|
func TestDescribeTopologySpreadConstraints(t *testing.T) {
|
||||||
fake := fake.NewSimpleClientset(&corev1.Pod{
|
fake := fake.NewSimpleClientset(&corev1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Loading…
Reference in New Issue
Block a user