-
Notifications
You must be signed in to change notification settings - Fork 39.7k
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
Allow getting logs directly from deployment, job and statefulset #40927
Conversation
@kubernetes/sig-apps-pr-reviews |
e24eae1
to
5e7638a
Compare
Do tests exist for these? |
@pwittrock I haven't seen any, I'll add one. |
That would be wonderful. Thank you. |
return nil, fmt.Errorf("invalid label selector: %v", err) | ||
} | ||
sortBy := func(pods []*v1.Pod) sort.Interface { return controller.ByLogging(pods) } | ||
pod, numPods, err := GetFirstPod(clientset.Core(), t.Namespace, selector, 20*time.Second, sortBy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this only work for the first pod ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, consistent with the others. See #19873 for proposed extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we check if replicas > 0 ? AFAIK this function will wait for 20s for a Pod to appear, but I think we should return faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's consistent with the others, why would we change the behavior here?
@soltysh I think the help message of the command needs an update |
return nil, err | ||
} | ||
if numPods > 1 { | ||
fmt.Fprintf(os.Stderr, "Found %v pods, using pod/%v\n", numPods, pod.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistently with others.
I've added more objects per @smarterclayton request, that is StatefulSet, Job and CronJob. I've also added them to |
5e7638a
to
4acbf1a
Compare
@@ -330,6 +390,16 @@ func (f *ring1Factory) AttachablePodForObject(object runtime.Object) (*api.Pod, | |||
sortBy := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) } | |||
pod, _, err := GetFirstPod(clientset.Core(), t.Namespace, selector, 1*time.Minute, sortBy) | |||
return pod, err | |||
|
|||
case *extensions.ReplicaSet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an open PR for attach, mind leaving that aside?
#40365
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing.
4acbf1a
to
e24b2c0
Compare
@Kargakis I've removed the attach part |
pkg/kubectl/cmd/logs.go
Outdated
kubectl logs job/hello | ||
|
||
# Return snapshot logs from from container hello-1 of a job named hello | ||
kubectl logs job/hello -c hello-1`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide an example with a different resource since you already have one with jobs above
The relase note needs an update |
Apart from a couple of comments and the clientset interface update, lgtm |
e24b2c0
to
74d71d2
Compare
@Kargakis nits fixed, release note updated |
Rebased. |
Re-applying lgtm label, since this was just mechanical rebase. |
56510de
to
5472a5e
Compare
[APPROVALNOTIFIER] This PR is APPROVED The following people have approved this PR: deads2k, k8s-merge-robot, madhusudancs, soltysh Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@k8s-bot unit test this |
@k8s-bot gce etcd3 e2e test this |
Automatic merge from submit-queue (batch tested with PRs 42053, 41282, 42056, 41663, 40927) |
@soltysh What's the motivation for this PR? How users should use it? AFAIU the semantic is that we will show logs from a random pod within Deployment. How is it useful? To be hones I find it pretty confusing. |
@fgrzadkowski this is more of a convenience when you have a simple deployment/job/stateful set. We've had similar logic in place for RC/RS already, this was only adding the same for other objects. |
I see. Though I find it very confusing. So we you saying that this is intended for Deployments/RS/RC with only one instance where it's clear what this mean? Do you know what was the motivation for label selectors? |
Not sure I understand which label selectors you're talking about, here. The ones used in this impl are only to get the pods owned by the controller and then pick the first pod. |
The way pods are picked up is not random but we may want to document it. |
To be honest I find that logic even more confusing. I was referring to the following option in
Maybe it'd useful to at least let the user choose which pod they are interested in? |
See #44282 for the relevant discussion. |
Special notes for your reviewer:
@smarterclayton you asked for it in OpenShift