Skip to content

Valid container name info needed in kubectl logs/exec output #1768

@astraw99

Description

@astraw99

What would you like to be added?

Add container name info in kubectl logs xxx and kubectl exec xxx output, when there are multiple containers in a pod. Currently, there is no valid container name info in the output.
Current:

kubectl logs test-pod -c abc
error: container abc is not valid for pod test-pod

kubectl exec -it test-pod -c abc -- sh
Error from server (BadRequest): container abc is not valid for pod test-pod

Expected:

kubectl logs test-pod -c abc
error: container abc is not valid for pod test-pod out of: main-0, main-1, main-2, init-0 (init), init-1 (init)

kubectl exec -it test-pod -c abc -- sh
Error from server (BadRequest): container abc is not valid for pod test-pod out of: main-0, main-1, main-2, init-0 (init), init-1 (init)

Why is this needed?

When a pod with multiple containers, there is no valid container name info in the kubectl logs xxx and kubectl exec xxx output, need to add containers name info to choose easily.
Test yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  initContainers:
    - name: init-0
      image: busybox
      command:
        - echo
        - msg from init-0
    - name: init-1
      image: busybox
      command:
        - echo
        - msg from init-1
  containers:
    - name: main-0
      image: busybox
      command:
        - /bin/sh
        - -c
        - sleep 3600
    - name: main-1
      image: busybox
      command:
        - /bin/sh
        - -c
        - sleep 3600
    - name: main-2
      image: busybox
      command:
        - /bin/sh
        - -c
        - sleep 3600

kubectl apply -f test-pod.yaml, then:

  • kubectl logs test-pod -c abc
  • kubectl exec -it test-pod -c abc -- sh

will reproduce this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.sig/cliCategorizes an issue or PR as relevant to SIG CLI.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    Status

    Needs Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions