diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe.go b/staging/src/k8s.io/kubectl/pkg/describe/describe.go index fc76f232475..7a04910f200 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe.go @@ -1000,6 +1000,8 @@ func describeVolumes(volumes []corev1.Volume, w PrefixWriter, space string) { printProjectedVolumeSource(volume.VolumeSource.Projected, w) case volume.VolumeSource.CSI != nil: printCSIVolumeSource(volume.VolumeSource.CSI, w) + case volume.VolumeSource.Image != nil: + printImageVolumeSource(volume.VolumeSource.Image, w) default: w.Write(LEVEL_1, "\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 { clientset.Interface } diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go index 8898cb688c9..be0fd853b36 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go @@ -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: + Labels: + Annotations: + Status: + IP: + IPs: + Containers: + Volumes: + image: + Type: Image (a container image or OCI artifact) + Reference: image + PullPolicy: IfNotPresent + QoS Class: BestEffort + Node-Selectors: + Tolerations: + Events: + `)[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) { fake := fake.NewSimpleClientset(&corev1.Pod{ ObjectMeta: metav1.ObjectMeta{