mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #80847 from verb/debug-kubectl-describe
Print ephemeral containers in kubectl describe
This commit is contained in:
		@@ -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("Init Containers", pod.Spec.InitContainers, pod.Status.InitContainerStatuses, EnvValueRetriever(pod), w, "")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		describeContainers("Containers", pod.Spec.Containers, pod.Status.ContainerStatuses, 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 {
 | 
							if len(pod.Spec.ReadinessGates) > 0 {
 | 
				
			||||||
			w.Write(LEVEL_0, "Readiness Gates:\n  Type\tStatus\n")
 | 
								w.Write(LEVEL_0, "Readiness Gates:\n  Type\tStatus\n")
 | 
				
			||||||
			for _, g := range pod.Spec.ReadinessGates {
 | 
								for _, g := range pod.Spec.ReadinessGates {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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) {
 | 
					func TestDescribePodNode(t *testing.T) {
 | 
				
			||||||
	fake := fake.NewSimpleClientset(&corev1.Pod{
 | 
						fake := fake.NewSimpleClientset(&corev1.Pod{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user