Merge pull request #137591 from pacoxu/kubeadm-etcd-version

kubectl: only print default cotnainer if there are multi containers
This commit is contained in:
Kubernetes Prow Robot 2026-03-12 15:31:44 +05:30 committed by GitHub
commit 9cfdbc0d6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -78,7 +78,7 @@ func FindOrDefaultContainerByName(pod *v1.Pod, name string, quiet bool, warn io.
// fallback to pick the first container to maintain existing behavior
container := &pod.Spec.Containers[0]
if !quiet {
if !quiet && (len(pod.Spec.Containers) > 1 || len(pod.Spec.InitContainers) > 0 || len(pod.Spec.EphemeralContainers) > 0) {
fmt.Fprintf(warn, "Defaulted container %q out of: %s\n", container.Name, AllContainerNames(pod)) // nolint:errcheck
}
klog.V(4).Infof("Using the first container in a pod: %s", container.Name)