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

"Podman pod logs --latest" doesn't work. #15556

Closed
fhwsuper opened this issue Aug 31, 2022 · 11 comments · Fixed by #15846
Closed

"Podman pod logs --latest" doesn't work. #15556

fhwsuper opened this issue Aug 31, 2022 · 11 comments · Fixed by #15846
Assignees
Labels
Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@fhwsuper
Copy link

Ubuntu Linux 20.04, Podman 4.2.0
This issue also can be found in Podman 4.1.0, & Podman 3.4.4

./podman pod logs -l
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/containers/podman/v4/cmd/podman/pods.logs(0x240ad20?, {0xc0002aa450, 0x0, 0x1?})
/home/fanhuawei/podman/podman-4.2.0/cmd/podman/pods/logs.go:124 +0x3d9
github.com/spf13/cobra.(*Command).execute(0x240ad20, {0xc00009e070, 0x1, 0x1})
/home/fanhuawei/podman/podman-4.2.0/vendor/github.com/spf13/cobra/command.go:872 +0x694
github.com/spf13/cobra.(*Command).ExecuteC(0x2412520)
/home/fanhuawei/podman/podman-4.2.0/vendor/github.com/spf13/cobra/command.go:990 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
/home/fanhuawei/podman/podman-4.2.0/vendor/github.com/spf13/cobra/command.go:918
github.com/spf13/cobra.(*Command).ExecuteContext(...)
/home/fanhuawei/podman/podman-4.2.0/vendor/github.com/spf13/cobra/command.go:911
main.Execute()
/home/fanhuawei/podman/podman-4.2.0/cmd/podman/root.go:99 +0xc5
main.main()
/home/fanhuawei/podman/podman-4.2.0/cmd/podman/main.go:40 +0x7c

@vrothberg
Copy link
Member

Thanks for reaching out! I can reproduce as well.

@vrothberg vrothberg added kind/bug Categorizes issue or PR as related to a bug. Good First Issue This issue would be a good issue for a first time contributor to undertake. labels Aug 31, 2022
@fhwsuper
Copy link
Author

fhwsuper commented Sep 1, 2022

This is a workaround.

  1. change second argument "nameOrID "to an array.
  2. Only get pod[0].ID() from func getPodsByContext() and then invoke when options.Latest = false
    I suppose other fileds of Pod struct have some problems when invoke getPodsByContext() with options.Latest = true.

Second method: you could consider move nameOrID into struct PodLogsOptions, like pod inspect -l, pod top -l.

func (ic *ContainerEngine) PodLogs(ctx context.Context, nameOrID []string, options entities.PodLogsOptions) error {
// // Implementation accepts slice
// //podName := []string{nameOrID}

var pod []*libpod.Pod
var err error

if options.Latest {
	pod, err = getPodsByContext(false, options.Latest, nameOrID, ic.Libpod)
	if err != nil {
		return err
	}

	options.Latest = false
	podID := []string{pod[0].ID()}
        pod, err = getPodsByContext(false, options.Latest, podID, ic.Libpod)
	if err != nil {
		return err
	}

.......

@jakecorrenti
Copy link
Member

I can give this one a shot while I work on the conmon-rs stuff

@vrothberg
Copy link
Member

I can give this one a shot while I work on the conmon-rs stuff

Awesome! Thanks a lot, @jakecorrenti

@boaz0
Copy link
Collaborator

boaz0 commented Sep 11, 2022

Hi @jakecorrenti I think I found the problem. Can I work on it? Or you are in a middle of finishing it.
Let me know. Thanks.
If you need help let me know, I don't mind giving you a hint.

@jakecorrenti
Copy link
Member

Hi @jakecorrenti I think I found the problem. Can I work on it? Or you are in a middle of finishing it.

Let me know. Thanks.

If you need help let me know, I don't mind giving you a hint.

Hey, I'm still working on it. Had my first week back at school last week so just had to find my groove. I plan on trying to finish today. I'll let you know if I want to pass it off!

@rhatdan
Copy link
Member

rhatdan commented Sep 12, 2022

Excellent.

@jakecorrenti
Copy link
Member

Just want to confirm that the expected output here (based on the documentation of podman pod logs -l) is going to be the same as podman logs -l?

@rhatdan
Copy link
Member

rhatdan commented Sep 15, 2022

Not sure what the question is, podman pod logs -l should show the logs of the last created pod, same as if you specified
podman pod logs PODID

@jakecorrenti
Copy link
Member

jakecorrenti commented Sep 15, 2022

Ok, that was what my gut feeling was telling me. The help page for podman pod logs -h says -l, --latest Act on the latest container podman is aware of so it was some odd coincidence that it was printing the exact same log podman container logs -l was. Thank you for the clarification.

@rhatdan
Copy link
Member

rhatdan commented Sep 15, 2022

Yes, The use case where this would differ would be if the Pod is older then the latest container and if the Pod contained more then one container.

If latest pod contained only latest container, then they would be the same.

@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 13, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. 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 a pull request may close this issue.

5 participants