From f957fd6739c7500140adae3ea5794d1503622e97 Mon Sep 17 00:00:00 2001 From: jfremy-openai Date: Sat, 28 Jun 2025 07:54:26 -0700 Subject: [PATCH] fetchContainers(allContainers=false) returns sidecars and ephemeral (#3415) Issue: when calling exec / attach on a pod with sidecar containers or ephemeral containers, those are not presented as potential targets to exec / attach / transfer. Proposed solution: the method fetchContainers is only called with allContainers=false to find containers we can exec / attach / transfer. Both ephemeral containers and sidecar init containers could be used in this case however with the current behavior they're not shown. I'm proposing to change the behavior of the method to return any sidecar container and ephemeral container when called with allContainers=false since there is no other caller using that parameter set to false, so we won't break other call sites --- internal/view/pod.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/view/pod.go b/internal/view/pod.go index d22cd1bc..bf4bc982 100644 --- a/internal/view/pod.go +++ b/internal/view/pod.go @@ -516,12 +516,12 @@ func fetchContainers(meta *metav1.ObjectMeta, spec *v1.PodSpec, allContainers bo nn = append(nn, spec.Containers[i].Name) } } - if !allContainers { - return nn - } for i := range spec.InitContainers { - nn = append(nn, spec.InitContainers[i].Name) + isSidecar := spec.InitContainers[i].RestartPolicy != nil && *spec.InitContainers[i].RestartPolicy == v1.ContainerRestartPolicyAlways + if allContainers || isSidecar { + nn = append(nn, spec.InitContainers[i].Name) + } } for i := range spec.EphemeralContainers { nn = append(nn, spec.EphemeralContainers[i].Name)