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
mine
jfremy-openai 2025-06-28 07:54:26 -07:00 committed by GitHub
parent eccbef946c
commit f957fd6739
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -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)