Merge pull request #80847 from verb/debug-kubectl-describe

Print ephemeral containers in kubectl describe
This commit is contained in:
Kubernetes Prow Robot 2019-08-27 22:41:45 -07:00 committed by GitHub
commit 178d2eefee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -710,6 +710,13 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) {
describeContainers("Init Containers", pod.Spec.InitContainers, pod.Status.InitContainerStatuses, EnvValueRetriever(pod), w, "")
}
describeContainers("Containers", pod.Spec.Containers, pod.Status.ContainerStatuses, EnvValueRetriever(pod), w, "")
if len(pod.Spec.EphemeralContainers) > 0 {
var ec []corev1.Container
for i := range pod.Spec.EphemeralContainers {
ec = append(ec, corev1.Container(pod.Spec.EphemeralContainers[i].EphemeralContainerCommon))
}
describeContainers("Ephemeral Containers", ec, pod.Status.EphemeralContainerStatuses, EnvValueRetriever(pod), w, "")
}
if len(pod.Spec.ReadinessGates) > 0 {
w.Write(LEVEL_0, "Readiness Gates:\n Type\tStatus\n")
for _, g := range pod.Spec.ReadinessGates {

View File

@ -95,6 +95,51 @@ func TestDescribePod(t *testing.T) {
}
}
func TestDescribePodEphemeralContainers(t *testing.T) {
fake := fake.NewSimpleClientset(&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
Spec: corev1.PodSpec{
EphemeralContainers: []corev1.EphemeralContainer{
{
EphemeralContainerCommon: corev1.EphemeralContainerCommon{
Name: "debugger",
Image: "busybox",
},
},
},
},
Status: corev1.PodStatus{
EphemeralContainerStatuses: []corev1.ContainerStatus{
{
Name: "debugger",
State: corev1.ContainerState{
Running: &corev1.ContainerStateRunning{
StartedAt: metav1.NewTime(time.Now()),
},
},
Ready: false,
RestartCount: 0,
},
},
},
})
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
d := PodDescriber{c}
out, err := d.Describe("foo", "bar", describe.DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "debugger:") {
t.Errorf("unexpected out: %s", out)
}
if !strings.Contains(out, "busybox") {
t.Errorf("unexpected out: %s", out)
}
}
func TestDescribePodNode(t *testing.T) {
fake := fake.NewSimpleClientset(&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{