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

kube: Add support for podman pod logs. #11427

Merged
merged 1 commit into from
Sep 7, 2021

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Sep 3, 2021

Following PR adds support for kubectl like pod logs to podman.
Usage podman pod logs <podIDorName> gives a stream of logs for all
the containers within the pod with containername as a field.

Just like kubectl also supports podman pod logs -c <ctrIDorName> <podIDorName>
to limit the log stream to any of the specificied container which belongs to pod.

@flouthoc
Copy link
Collaborator Author

flouthoc commented Sep 3, 2021

/assign @baude since he created original issue.

@flouthoc flouthoc force-pushed the kube-pod-logs branch 3 times, most recently from 06d4389 to d6ecd06 Compare September 3, 2021 09:27
flags.BoolVar(&logsOptions.Details, "details", false, "Show extra details provided to the logs")
flags.BoolVarP(&logsOptions.Follow, "follow", "f", false, "Follow log output. The default is false")

containerNameFlag := "containername"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to call it container and also to make it accept container ids.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Luap99 Renamed flag to container thanks :) and it already accepts ID or Name

cmd/podman/pods/logs.go Outdated Show resolved Hide resolved
cmd/podman/pods/logs.go Outdated Show resolved Hide resolved
pkg/domain/infra/abi/pods.go Outdated Show resolved Hide resolved
cmd/podman/pods/logs.go Outdated Show resolved Hide resolved
@flouthoc flouthoc force-pushed the kube-pod-logs branch 3 times, most recently from 23cd16d to a39e0d9 Compare September 3, 2021 17:15
docs/source/markdown/podman-pod-logs.1.md Outdated Show resolved Hide resolved
docs/source/markdown/podman-pod-logs.1.md Outdated Show resolved Hide resolved

#### **--container**, **-c**

By default `podman pod logs` retrives logs for all the containers available within the pod differentiate by field `container`. However there are use-cases where user would want to limit the log stream only to a particular container of a pod for such cases `-c` can be used like `podman pod logs -c ctrNameorID podname`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't I just use podman logs CID?, would podman pod logs give me different data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It majorly for mainlining interface parity between kubectl pod logs and podman pod logs , since kubectl would not print logs if there are multiple containers in a pod it rather asks users to provide container using a -c flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

docs/source/markdown/podman-pod-logs.1.md Outdated Show resolved Hide resolved
docs/source/markdown/podman-pod-logs.1.md Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 4, 2021
cmd/podman/pods/logs.go Outdated Show resolved Hide resolved
cmd/podman/pods/logs.go Outdated Show resolved Hide resolved
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 5, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Following PR adds support for `kubectl` like `pod logs` to podman.
Usage `podman pod logs <podIDorName` gives a stream of logs for all
the containers within the pod with **containername** as a field.

Just like **`kubectl`** also supports `podman pod logs -c ctrIDorName podIDorName`
to limit the log stream to any of the specificied container which belongs to pod.

Signed-off-by: Aditya Rajan <[email protected]>
@mheon
Copy link
Member

mheon commented Sep 7, 2021

LGTM

@rhatdan
Copy link
Member

rhatdan commented Sep 7, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 7, 2021
@openshift-merge-robot openshift-merge-robot merged commit 30d0cc3 into containers:main Sep 7, 2021
logs.WaitWithDefaultTimeout()
Expect(logs).Should(Exit(0))
Expect(logs.OutputToString()).To(ContainSubstring("hello world"))
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for commenting so late. I had it on my to-review list but didn't manage before.

I want to ask for more tests in a follow-up PR. There's a couple of things in the tests that I think need improvement:

  • We need more tests and exercise all flags of podman pod logs (e.g., --follow). The coverage at the moment is low, so the risk of regressions is high.
  • What are the exact semantics of --follow? Shall we follow over the entire lifecycle of the pod (currently we do that) or shall we follow all containers except the infra one? The difference is that --follow will not return unless the pod is stopped. IMHO we should NOT follow the infra container.
  • We need to improve testing the output. Currently, we are only checking for substrings but I don't think that's sufficient to catch future regressions. We need to look closer and match exact output. Since we can get the IDs of containers, we should be able to construct an exact string match, not a substring one.
  • Last but not least, we have two log drivers (k8s-file and journald) and I think we should tests both as we do in the container logs tests. I suggest moving the tests away from play_kube and into a new file pod_logs_test.go.

Again sorry for not reviewing earlier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vrothberg Yes i think we should address all these point in few more test cases, I'll add different systems tests addressing these points.

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants