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

Make logstream watch the pods as they change. #1496

Merged
merged 4 commits into from
Jul 15, 2020

Conversation

vagababov
Copy link
Contributor

  • watch the pods and track what we already watch
  • start watchers for the new pods

For #1488

/assign @markusthoemmes mattmoor

- watch the pods and track what we already watch
- start watchers for the new pods
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 15, 2020
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/test-and-release labels Jul 15, 2020
}
k.kc = kc

// List the pods in the given namespace.
pl, err := kc.Kube.CoreV1().Pods(k.namespace).List(metav1.ListOptions{})
if err != nil {
t.Error("Error listing pods", "error", err)
Copy link
Member

Choose a reason for hiding this comment

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

Did you want to return here, too?

In general, I wonder whether returning an error here would be better than calling t.Error, but I don't feel strongly.

pod.Name, container.Name, scanner.Err())
})
}
pod := pod
Copy link
Member

Choose a reason for hiding this comment

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

This line looks strange. Do we need to copy the pod here, vs making a copy in startForPod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

more or less standard go practice for for loops that spawn goroutines (had to add it actually based on debugging, I thought the passing to function would work too).

test/logstream/kubelogs.go Outdated Show resolved Hide resolved
test/logstream/kubelogs.go Outdated Show resolved Hide resolved
test/logstream/kubelogs.go Outdated Show resolved Hide resolved
test/logstream/kubelogs.go Outdated Show resolved Hide resolved
// equivalent to --all-containers.
for _, container := range pod.Spec.Containers {
// Required for capture below.
pod, container := pod, container
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to capture pod though?

Copy link
Member

Choose a reason for hiding this comment

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

GetLogs(pod.Name, options)

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but it's not a loop-variable 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

escapes in go goroutine?

func (k *kubelogs) watchPods(t test.TLegacy, eg *errgroup.Group) {
wi, err := k.kc.Kube.CoreV1().Pods(k.namespace).Watch(metav1.ListOptions{})
if err != nil {
t.Logf("Logstream knative pod watch failed, logs might be missing: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we surface this error similar to the List error in init?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I debated that... I am not sure failing a test, because of logging failure is a valid concern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I'll go along with what we have now.

@evankanderson
Copy link
Member

/retest

I sent #1497 to fix the workqueue_test flakiness.

Comment on lines 103 to 112
case watch.Added, watch.Modified:
if k.watchedPods.Has(p.Name) {
t.Log("Already watching pod", p.Name)
continue
}
// If pod is ready then start the logs.
if p.Status.Phase == corev1.PodRunning && p.DeletionTimestamp == nil {
for _, cond := range p.Status.Conditions {
if cond.Type == corev1.PodReady && cond.Status == corev1.ConditionTrue {
t.Log("The new knative pod is ready", p.Name)
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 this would flow/read better with a bit more encapsulation and redrawing the line between these functions. Something like:

if watched.Has(p.Name) {
  continue
}
if !isReady(pod) {
  continue
}
watched.Insert(pod.Name)
k.startForPod(pod)

This also lets you make watchedPods a local variable instead of a field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this does not work because we also start pods in init. But I think along the lines you left below — that I can remove the loop in init.

})
}
pod := pod
k.startForPod(&eg, &pod)
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this loop, or can it be subsumed by watchPods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think so.

@vagababov
Copy link
Contributor Author

Fixed the build and updated according to reviews.

@vagababov
Copy link
Contributor Author

/close
/reopen

@vagababov
Copy link
Contributor Author

/retest

@vagababov
Copy link
Contributor Author

Why my new commits don't show?
The last two from here: https://github.com/vagababov/pkg/commits/2020714-logs don't show at all.

@knative-prow-robot
Copy link
Contributor

@vagababov: Closed this PR.

In response to this:

/close
/reopen

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.

@vagababov
Copy link
Contributor Author

/reopen

@knative-prow-robot
Copy link
Contributor

@vagababov: Reopened this PR.

In response to this:

/reopen

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.

@vagababov
Copy link
Contributor Author

/retest

@mattmoor
Copy link
Member

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2020
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mattmoor, vagababov

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 15, 2020
@vagababov
Copy link
Contributor Author

/retest

1 similar comment
@vagababov
Copy link
Contributor Author

/retest

@vagababov
Copy link
Contributor Author

/close

@knative-prow-robot
Copy link
Contributor

@vagababov: Closed this PR.

In response to this:

/close

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.

@vagababov
Copy link
Contributor Author

/reopen

@knative-prow-robot
Copy link
Contributor

@vagababov: Reopened this PR.

In response to this:

/reopen

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.

@knative-prow-robot knative-prow-robot merged commit 4c35539 into knative:master Jul 15, 2020
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. area/test-and-release cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants