Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl logs with label selector supports specifying a container name #44282

Merged
merged 1 commit into from
Jun 17, 2017

Conversation

derekwaynecarr
Copy link
Member

What this PR does / why we need it:
Allows kubectl logs to take both a label selector and container name. This allows me to fetch logs from pods by selector whose pods have multiple containers with a common name. This is a common action when debugging components like the service-catalog that ship more than one container in their pod. With this change, the following command lets me get logs for service-catalog.

$ kubectl logs -l app=sc-catalog-apiserver --namespace=service-catalog --container=apiserver

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 10, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@derekwaynecarr derekwaynecarr added this to the v1.7 milestone Apr 10, 2017
@k8s-github-robot k8s-github-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note-label-needed labels Apr 10, 2017
@derekwaynecarr derekwaynecarr added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 10, 2017
@k8s-github-robot k8s-github-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 10, 2017
@derekwaynecarr
Copy link
Member Author

FYI @smarterclayton @pmorie @sjenning @jpeeler -- this makes getting logs via CLI for service catalog much simpler since we do not need to know the pod name.

@sjenning
Copy link
Contributor

Gotta love the "the code supported this all along, but for some reason we bailed on it; let's not do that." PRs 😄

So... I guess the assumption is that all pods that match the label selector have the named container? i.e. the selector only matches pods from a single replicaset's pod template most likely?

Otherwise I guess the command just chunks an error for each pod that doesn't have the specified container?

@derekwaynecarr
Copy link
Member Author

@sjenning -- the error message when the container is not found is as follows:

$ kubectl logs -l app=sc-catalog-apiserver --namespace=service-catalog --container=apiserver4
Error from server (BadRequest): container apiserver4 is not valid for pod sc-catalog-apiserver-4025205670-8xgb9

@sjenning
Copy link
Contributor

@derekwaynecarr and i guess you get one of those errors per pod that matches the selector but doesn't have the container.

either way, the code handles it as well as it can i think.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 10, 2017
@0xmichalis
Copy link
Contributor

@kubernetes/sig-cli-pr-reviews fyi

@deads2k
Copy link
Contributor

deads2k commented Apr 12, 2017

Gotta love the "the code supported this all along, but for some reason we bailed on it; let's not do that." PRs

Eh, it really doesn't. Given a label selector which covers non-congruent pods, if you specify a container, should we search all pods to find the first one that has the container you're looking for (likely what you want), or do you want to take the first matching pod and fail if it doesn't have the container even if the second one does (what it actually does).

@deads2k
Copy link
Contributor

deads2k commented Apr 12, 2017

FYI @smarterclayton @pmorie @sjenning @jpeeler -- this makes getting logs via CLI for service catalog much simpler since we do not need to know the pod name.

kubectl logs deployment/service-catalog is probably what you're looking for.

@soltysh
Copy link
Contributor

soltysh commented Apr 12, 2017

kubectl logs deployment/service-catalog is probably what you're looking for.

There's one caveat of doing that - this will only pick the first pod in a deployment.

@smarterclayton
Copy link
Contributor

smarterclayton commented Apr 24, 2017 via email

@deads2k
Copy link
Contributor

deads2k commented Apr 24, 2017

  1. view a set of pods with a specific container's logs (-l foo=bar -c
    something)

Not having the container in the list is only a problem when you get no
output at all.

I don't object to updating to handle the case, but it's not just a matter of removing the validation check. The behavior needs to be defined or we'll have "bug" fixes in both directions.

@derekwaynecarr
Copy link
Member Author

how do you want to update the behavior versus that which is implied here? i guess we need a sorted pod selection order?

@deads2k
Copy link
Contributor

deads2k commented Apr 25, 2017

how do you want to update the behavior versus that which is implied here? i guess we need a sorted pod selection order?

Stable sorting and documenting "try first" to at least get consistent behavior running the same command multiple times against the same set of resources.

As a user, I'd kind of expect to having you look through to find the pod I meant, but if @kubernetes/sig-cli-api-reviews and @kubernetes/rh-ux are ok with failing instead of looking I'm ok with it.

@wojtek-t
Copy link
Member

@k8s-bot pull-kubernetes-unit test this

@wojtek-t
Copy link
Member

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: derekwaynecarr, sjenning, wojtek-t

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 31, 2017
@grodrigues3
Copy link
Contributor

Seems like a small enough bugfix that reference an issue in the PR body is not required. Readding the approved label

@grodrigues3 grodrigues3 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 6, 2017
@marun marun added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Jun 8, 2017
@pwittrock
Copy link
Member

@k8s-bot pull-kubernetes-e2e-kops-aws test this

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jun 12, 2017

@derekwaynecarr: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
Jenkins unit/integration 9c956c2 link @k8s-bot unit test this

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@spiffxp
Copy link
Member

spiffxp commented Jun 16, 2017

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 38751, 44282, 46382, 47603, 47606)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.