Repository: knative/pkg
Pull request #2591 (2022-09-12 09:10:57)

Allow logstream to stream logs from user namespace
* When streaming logs from user namespace, disable filtering lines so all lines are printed.

* More information on when this comes handy is available in Serving PR: https://github.com/knative/serving/pull/13293, together with usage example.
It will be very handy also in knative/eventing upgrade tests where multiple pods are started and the Sender pod is removed before the test ends.

<!-- Thanks for sending a pull request! -->

# Changes

<!-- 
Describe your changes here- ideally you can get that description straight from
your descriptive commit message(s)! 

- :gift: Add new feature
- :bug: Fix bug
- :broom: Update or clean up current behavior
- :wastebasket: Remove feature or internal logic
-->

-
-
-

<!--
In addition, categorize the changes you're making using the "/kind" Prow command, example:

/kind <kind>

Supported kinds are: api-change, bug, cleanup, deprecation, removal, documentation, enhancement, performance

-->
/kind <kind>

<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

<!-- Please include the 'why' behind your changes if no issue exists -->

**Release Note**

<!--
:page_facing_up: If this change has user-visible impact, write a release note in the block
below. Include the string "action required" if additional action is required of
users switching to the new release, for example in case of a breaking change.

Write as if you are speaking to users, not other Knative contributors. If this
change has no user-visible impact, no release-note is needed.
-->
```release-note

```

**Docs**

<!--
:book: If this change has user-visible impact, link to an issue or PR in
https://github.com/knative/docs.

See here for guidance on getting permanent links to files: https://help.github.com/en/articles/getting-permanent-links-to-files

Please use the following format for linking documentation:
- [knative/docs]: <issue or pr link>
- [Feature Track]: <link>
- [Usage]: <link>
- [Other doc]: <link>
-->
```docs

```


knative-prow[bot]: @mgencur: The label(s) `kind/<kind>` cannot be applied, because the repository doesn't have them.

<details>

In response to [this](https://github.com/knative/pkg/pull/2591):

>* When streaming logs from user namespace, disable filtering lines so all lines are printed.
>
>More information on when this comes handy is available in Serving PR: https://github.com/knative/serving/pull/13293, together with usage example.
>It will be very handy also in knative/eventing upgrade tests where multiple pods are started and the Sender pod is removed before the test ends.
>
>
>
># Changes
>
>
>
>-
>-
>-
>
>
>/kind <kind>
>
>
>Fixes #
>
>
>
>**Release Note**
>
>
>```release-note
>
>```
>
>**Docs**
>
>
>```docs
>
>```
>


Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>
knative-prow[bot]: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2591#" title="Author self-approved">mgencur</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign upodroid for approval by writing `/assign @upodroid` in a comment. For more information see:[The Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

<details open>
Needs approval from an approver in each of these files:

- **[test/OWNERS](https://github.com/knative/pkg/blob/main/test/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["upodroid"]} -->
knative-prow[bot]: @mgencur: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
unit-tests_pkg_main | 3727dac93b989b31bd88026e0aaf72058c1502cf | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/2591/unit-tests_pkg_main/1569252218350080000) | true | `/test unit-tests_pkg_main`

[Your PR dashboard](https://prow.knative.dev/pr).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-prow[bot]: @mgencur: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
unit-tests_pkg_main | 3727dac93b989b31bd88026e0aaf72058c1502cf | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/2591/unit-tests_pkg_main/1569252218350080000) | true | `/test unit-tests_pkg_main`
build-tests_pkg_main | 3727dac93b989b31bd88026e0aaf72058c1502cf | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/2591/build-tests_pkg_main/1569252218291359744) | true | `/test build-tests_pkg_main`

[Your PR dashboard](https://prow.knative.dev/pr).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-prow[bot]: @mgencur: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
build-tests_pkg_main | 3727dac93b989b31bd88026e0aaf72058c1502cf | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/2591/build-tests_pkg_main/1569252218291359744) | true | `/test build-tests_pkg_main`
unit-tests_pkg_main | c44f3b58cdb6a8b3fe21f272e6ce85f2b37c4ef1 | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/2591/unit-tests_pkg_main/1569259227090784256) | true | `/test unit-tests_pkg_main`

[Your PR dashboard](https://prow.knative.dev/pr).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/pkg/pull/2591?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) Report
> Merging [#2591](https://codecov.io/gh/knative/pkg/pull/2591?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) (c44f3b5) into [main](https://codecov.io/gh/knative/pkg/commit/2a05469a578035e6ee7e22bc56d2074e238954a8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) (2a05469) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##             main    #2591   +/-   ##
=======================================
  Coverage   81.25%   81.25%           
=======================================
  Files         162      162           
  Lines        9801     9801           
=======================================
  Hits         7964     7964           
  Misses       1597     1597           
  Partials      240      240           
```



Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)

mgencur: /retest
mgencur: The test failures look unrelated.
knative-prow[bot]: @mgencur: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
unit-tests_pkg_main | 3d0c01f7a9c53cb56a024a3b0f9b5b95918ce6fa | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/2591/unit-tests_pkg_main/1571781304763027456) | true | `/test unit-tests`

[Your PR dashboard](https://prow.knative.dev/pr).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
mgencur: /retest
knative-prow[bot]: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2591#" title="Author self-approved">mgencur</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign upodroid for approval by writing `/assign @upodroid` in a comment. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

<details open>
Needs approval from an approver in each of these files:

- **[test/OWNERS](https://github.com/knative/pkg/blob/main/test/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["upodroid"]} -->
mgencur: Rebased. Just to be sure this works after some time.

@dprotaso Could you review this please? There's a commit which haven't been reviewed. See [comment](https://github.com/knative/pkg/pull/2591#discussion_r973972854)

Patch:
diff --git a/.github/workflows/tekton-downstream.yaml b/.github/workflows/tekton-downstream.yaml
deleted file mode 100644
index 233016c05..000000000
--- a/.github/workflows/tekton-downstream.yaml
+++ /dev/null
@@ -1,76 +0,0 @@
-# Copyright 2021 The Knative Authors.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-name: Downstream Tekton
-
-on:
-  pull_request:
-    branches: [ 'main' ]
-
-jobs:
-  downstream-tekton:
-    name: Unit Test
-
-    strategy:
-      fail-fast: false # Keep running if one leg fails.
-      matrix:
-        repo: 
-          - tektoncd/pipeline
-          - tektoncd/chains
-          - tektoncd/triggers
-
-    runs-on: ubuntu-latest
-
-    steps:
-    - name: Set up Go 1.18.x
-      uses: actions/setup-go@v3
-      with:
-        go-version: 1.18.x
-
-    - name: Install Dependencies
-      run: |
-        go install github.com/google/go-licenses@latest
-
-    - name: Checkout Upstream
-      uses: actions/checkout@v3
-      with:
-        fetch-depth: 0
-        path: upstream
-
-    - name: Merge upstream
-      if: github.event_name == 'pull_request'
-      shell: bash
-      working-directory: upstream
-      run: |
-         if ! git config user.name > /dev/null; then
-           git config user.name "Knative Action"
-         fi
-         if ! git config user.email > /dev/null; then
-           git config user.email "action@knative.dev"
-         fi
-         git remote add upstream https://github.com/${{ github.repository }}.git
-         git fetch upstream ${{ github.base_ref }}
-         git pull --no-rebase --no-commit upstream ${{ github.base_ref }}
-
-    - name: Checkout Downstream
-      uses: actions/checkout@v3
-      with:
-        repository: ${{ matrix.repo }}
-        path: downstream
-
-    - name: Test Downstream
-      uses: knative/actions/go/downstream-test@main
-      with:
-        upstream-path: upstream
-        downstream-path: downstream
diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES
index b6d942006..4a7006336 100644
--- a/OWNERS_ALIASES
+++ b/OWNERS_ALIASES
@@ -78,12 +78,11 @@ aliases:
   - kvmware
   - lance
   - mchmarny
-  - pmorie
+  - nainaz
   - psschwei
+  - salaboy
   - smoser-ibm
-  - thisisnotapril
   - upodroid
-  - vaikas
   - zroubalik
   knative-release-leads:
   - evankanderson
@@ -194,9 +193,8 @@ aliases:
   - csantanapr
   - itsmurugappan
   - lance
-  - pmorie
-  - thisisnotapril
-  - vaikas
+  - nainaz
+  - salaboy
   technical-oversight-committee:
   - dprotaso
   - dsimansk
diff --git a/go.mod b/go.mod
index 0c0c08719..efddaeeeb 100644
--- a/go.mod
+++ b/go.mod
@@ -50,7 +50,7 @@ require (
 	k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9
 	k8s.io/klog/v2 v2.80.2-0.20221028030830-9ae4992afb54
 	k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2
-	knative.dev/hack v0.0.0-20221115211737-de2ff401a852
+	knative.dev/hack v0.0.0-20221201154717-7233e77996f1
 	sigs.k8s.io/yaml v1.3.0
 )
 
diff --git a/go.sum b/go.sum
index cd80b81cd..1a547d825 100644
--- a/go.sum
+++ b/go.sum
@@ -961,8 +961,8 @@ k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 h1:MQ8BAZPZlWk3S9K4a9NCkI
 k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHUesQOQy2/MZqGgMAFPqGsGQLdbZBU=
 k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 h1:GfD9OzL11kvZN5iArC6oTS7RTj7oJOIfnislxYlqTj8=
 k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
-knative.dev/hack v0.0.0-20221115211737-de2ff401a852 h1:/uB4umKUahDlWbIC96rSETG2BYA0zwQ02SGuM9ZYdOo=
-knative.dev/hack v0.0.0-20221115211737-de2ff401a852/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
+knative.dev/hack v0.0.0-20221201154717-7233e77996f1 h1:bPrqF9fmlZm972UUHN03lCCWBHgZ44F+orLK0Z+apDk=
+knative.dev/hack v0.0.0-20221201154717-7233e77996f1/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
 pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
 pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
 rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
diff --git a/kmeta/names.go b/kmeta/names.go
index eeaa57aef..963b121d2 100644
--- a/kmeta/names.go
+++ b/kmeta/names.go
@@ -19,7 +19,7 @@ package kmeta
 import (
 	"crypto/md5" //nolint:gosec // No strong cryptography needed.
 	"fmt"
-	"strings"
+	"regexp"
 )
 
 // The longest name supported by the K8s is 63.
@@ -30,6 +30,8 @@ const (
 	head    = longest - md5Len // How much to truncate to fit the hash.
 )
 
+var isAlphanumeric = regexp.MustCompile(`^[a-zA-Z0-9]*$`)
+
 // ChildName generates a name for the resource based upon the parent resource and suffix.
 // If the concatenated name is longer than K8s permits the name is hashed and truncated to permit
 // construction of the resource, but still keeps it unique.
@@ -55,12 +57,19 @@ func ChildName(parent, suffix string) string {
 			if d := longest - len(ret); d > 0 {
 				ret += suffix[:d]
 			}
-			// If due to trimming above we're terminating the string with a `-`,
-			// remove it.
-			return strings.TrimRight(ret, "-")
+			return makeValidName(ret)
 		}
 		//nolint:gosec // No strong cryptography needed.
 		n = fmt.Sprintf("%s%x", parent[:head-len(suffix)], md5.Sum([]byte(parent)))
 	}
 	return n + suffix
 }
+
+// If due to trimming above we're terminating the string with a non-alphanumeric
+// character, remove it.
+func makeValidName(n string) string {
+	for i := len(n) - 1; !isAlphanumeric.MatchString(string(n[i])); i-- {
+		n = n[:len(n)-1]
+	}
+	return n
+}
diff --git a/network/handlers/drain.go b/network/handlers/drain.go
index 5eee2ea42..3b2f28a07 100644
--- a/network/handlers/drain.go
+++ b/network/handlers/drain.go
@@ -196,7 +196,7 @@ func (d *Drainer) resetTimer() {
 
 	d.Lock()
 	defer d.Unlock()
-	if d.timer.Stop() {
+	if d.timer != nil && d.timer.Stop() {
 		d.timer.Reset(d.QuietPeriod)
 	}
 }
diff --git a/vendor/knative.dev/hack/infra-library.sh b/vendor/knative.dev/hack/infra-library.sh
index 662adfecc..84a87e2a1 100644
--- a/vendor/knative.dev/hack/infra-library.sh
+++ b/vendor/knative.dev/hack/infra-library.sh
@@ -133,6 +133,12 @@ function create_gke_test_cluster() {
   if [[ "${ENABLE_PREEMPTIBLE_NODES:-}" == "true" ]]; then
     extra_gcloud_flags="${extra_gcloud_flags} --preemptible"
   fi
+  if ! command -v kubetest2 >/dev/null; then
+    tmpbin="$(mktemp -d)"
+    echo "kubetest2 not found, installing in temp path: ${tmpbin}"
+    GOBIN="$tmpbin" go install sigs.k8s.io/kubetest2/...@latest
+    export PATH="${tmpbin}:${PATH}"
+  fi
   run_kntest kubetest2 gke "${_custom_flags[@]}" \
     --test-command="${_test_command[*]}" \
     --extra-gcloud-flags="${extra_gcloud_flags}"
diff --git a/vendor/knative.dev/hack/library.sh b/vendor/knative.dev/hack/library.sh
index 918561ef8..df9d3f9ad 100644
--- a/vendor/knative.dev/hack/library.sh
+++ b/vendor/knative.dev/hack/library.sh
@@ -586,17 +586,6 @@ function start_knative_eventing_extension() {
   wait_until_pods_running "$2" || return 1
 }
 
-# Install the stable release of eventing extension sugar controller in the current cluster.
-# Parameters: $1 - Knative Eventing release version, e.g. 0.16.0
-function start_release_eventing_sugar_controller() {
-  start_knative_eventing_extension "https://storage.googleapis.com/knative-releases/eventing/previous/v$1/eventing-sugar-controller.yaml" "knative-eventing"
-}
-
-# Install the sugar cotroller eventing extension
-function start_latest_eventing_sugar_controller() {
-  start_knative_eventing_extension "${KNATIVE_EVENTING_SUGAR_CONTROLLER_RELEASE}" "knative-eventing"
-}
-
 # Run a go utility without installing it.
 # Parameters: $1 - tool package for go run.
 #             $2..$n - parameters passed to the tool.
@@ -1018,4 +1007,3 @@ readonly KNATIVE_SERVING_RELEASE_CRDS="$(get_latest_knative_yaml_source "serving
 readonly KNATIVE_SERVING_RELEASE_CORE="$(get_latest_knative_yaml_source "serving" "serving-core")"
 readonly KNATIVE_NET_ISTIO_RELEASE="$(get_latest_knative_yaml_source "net-istio" "net-istio")"
 readonly KNATIVE_EVENTING_RELEASE="$(get_latest_knative_yaml_source "eventing" "eventing")"
-readonly KNATIVE_EVENTING_SUGAR_CONTROLLER_RELEASE="$(get_latest_knative_yaml_source "eventing" "eventing-sugar-controller")"
diff --git a/vendor/modules.txt b/vendor/modules.txt
index fb1672704..eec34ee4d 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -1118,7 +1118,7 @@ k8s.io/utils/net
 k8s.io/utils/pointer
 k8s.io/utils/strings/slices
 k8s.io/utils/trace
-# knative.dev/hack v0.0.0-20221115211737-de2ff401a852
+# knative.dev/hack v0.0.0-20221201154717-7233e77996f1
 ## explicit; go 1.18
 knative.dev/hack
 # sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2


Test patch:
diff --git a/kmeta/names_test.go b/kmeta/names_test.go
index ef316cb8c..df757e67b 100644
--- a/kmeta/names_test.go
+++ b/kmeta/names_test.go
@@ -17,10 +17,12 @@ limitations under the license.
 package kmeta
 
 import (
+	"fmt"
 	"strings"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
+	"k8s.io/apimachinery/pkg/util/validation"
 )
 
 func TestChildName(t *testing.T) {
@@ -56,11 +58,20 @@ func TestChildName(t *testing.T) {
 		parent: "aaaa",
 		suffix: strings.Repeat("b---a", 20),
 		want:   "aaaa7a3f7966594e3f0849720eced8212c18b---ab---ab---ab---ab---ab",
-	}}
+	}, {
+		parent: strings.Repeat("a", 17),
+		suffix: "a.-.-.-.-.-.-.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+		want:   "aaaaaaaaaaaaaaaaaa1eb10dc911444f8434af83b7225442da",
+	},
+	}
 
 	for _, test := range tests {
 		t.Run(test.parent+"-"+test.suffix, func(t *testing.T) {
-			if got, want := ChildName(test.parent, test.suffix), test.want; got != want {
+			got, want := ChildName(test.parent, test.suffix), test.want
+			if errs := validation.IsDNS1123Subdomain(got); len(errs) != 0 {
+				t.Errorf(fmt.Sprintf("Invalid DNS1123 Subdomain %63s\n\n Errors: %v", got, errs))
+			}
+			if got != want {
 				t.Errorf("%s-%s: got: %63s want: %63s\ndiff:%s", test.parent, test.suffix, got, want, cmp.Diff(want, got))
 			}
 		})
diff --git a/network/handlers/drain_test.go b/network/handlers/drain_test.go
index 082b8100d..88e4f07e5 100644
--- a/network/handlers/drain_test.go
+++ b/network/handlers/drain_test.go
@@ -546,3 +546,43 @@ func TestReset(t *testing.T) {
 	// Calling reset after a drain should succeed
 	d.Reset()
 }
+
+// https://github.com/knative/pkg/issues/2642
+func TestResetWithActiveRequests(t *testing.T) {
+	d := Drainer{
+		QuietPeriod: 5 * time.Second,
+		Inner:       http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}),
+	}
+
+	trafficStopped := make(chan struct{})
+	trafficStarted := make(chan struct{})
+	drainStarted := make(chan struct{})
+	defer close(trafficStopped)
+
+	go func() {
+		req, _ := http.NewRequest("GET", "knative.dev", nil)
+		rec := httptest.NewRecorder()
+
+		close(trafficStarted)
+		for {
+			select {
+			case <-trafficStopped:
+				return
+			default:
+				d.ServeHTTP(rec, req)
+			}
+		}
+	}()
+
+	go func() {
+		<-trafficStarted
+		close(drainStarted)
+		d.Drain()
+	}()
+
+	<-drainStarted
+	d.Reset()
+
+	// We need requests to be active for a bit
+	time.Sleep(time.Second)
+}
diff --git a/test/logstream/interface.go b/test/logstream/interface.go
index 33bc02332..a1b39aabd 100644
--- a/test/logstream/interface.go
+++ b/test/logstream/interface.go
@@ -18,6 +18,7 @@ package logstream
 
 import (
 	"context"
+	"fmt"
 	"os"
 	"strings"
 	"sync"
@@ -29,9 +30,11 @@ import (
 	logstreamv2 "knative.dev/pkg/test/logstream/v2"
 )
 
-// Canceler is the type of a function returned when a logstream is started to be
-// deferred so that the logstream can be stopped when the test is complete.
-type Canceler = logstreamv2.Canceler
+type (
+	// Canceler is the type of function returned when a logstream is started to be
+	// deferred so that the logstream can be stopped when the test is complete.
+	Canceler = logstreamv2.Canceler
+)
 
 type ti interface {
 	Name() string
@@ -41,35 +44,39 @@ type ti interface {
 }
 
 // Start begins streaming the logs from system components with a `key:` matching
-// `test.ObjectNameForTest(t)` to `t.Log`.  It returns a Canceler, which must
+// `test.ObjectNameForTest(t)` to `t.Log`. It returns a Canceler, which must
 // be called before the test completes.
 func Start(t ti) Canceler {
 	// Do this lazily to make import ordering less important.
 	once.Do(func() {
 		if ns := os.Getenv(system.NamespaceEnvKey); ns != "" {
-			config, err := test.Flags.GetRESTConfig()
-			if err != nil {
-				t.Error("Error loading client config", "error", err)
-				return
-			}
-
-			kc, err := kubernetes.NewForConfig(config)
-			if err != nil {
-				t.Error("Error creating kubernetes client", "error", err)
-				return
-			}
-
+			var err error
 			// handle case when ns contains a csv list
 			namespaces := strings.Split(ns, ",")
-			stream = &shim{logstreamv2.FromNamespaces(context.Background(), kc, namespaces)}
-
+			if sysStream, err = initStream(namespaces); err != nil {
+				t.Error("Error initializing logstream", "error", err)
+			}
 		} else {
-			// Otherwise set up a null stream.
-			stream = &null{}
+			// Otherwise, set up a null stream.
+			sysStream = &null{}
 		}
 	})
 
-	return stream.Start(t)
+	return sysStream.Start(t)
+}
+
+func initStream(namespaces []string) (streamer, error) {
+	config, err := test.Flags.GetRESTConfig()
+	if err != nil {
+		return &null{}, fmt.Errorf("error loading client config: %w", err)
+	}
+
+	kc, err := kubernetes.NewForConfig(config)
+	if err != nil {
+		return &null{}, fmt.Errorf("error creating kubernetes client: %w", err)
+	}
+
+	return &shim{logstreamv2.FromNamespaces(context.Background(), kc, namespaces)}, nil
 }
 
 type streamer interface {
@@ -77,8 +84,8 @@ type streamer interface {
 }
 
 var (
-	stream streamer
-	once   sync.Once
+	sysStream streamer
+	once      sync.Once
 )
 
 type shim struct {
diff --git a/test/logstream/v2/stream.go b/test/logstream/v2/stream.go
index b244fe8b7..1a37a54d2 100644
--- a/test/logstream/v2/stream.go
+++ b/test/logstream/v2/stream.go
@@ -20,6 +20,7 @@ import (
 	"bufio"
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"reflect"
 	"strings"
@@ -34,36 +35,70 @@ import (
 	"knative.dev/pkg/ptr"
 )
 
-func FromNamespaces(ctx context.Context, c kubernetes.Interface, namespaces []string) Source {
-	return &namespaceSource{
-		ctx:        ctx,
-		kc:         c,
-		namespaces: namespaces,
-		keys:       make(map[string]Callback, 1),
+// New creates a new log source. The source namespaces must be configured through
+// log source options.
+func New(ctx context.Context, c kubernetes.Interface, opts ...func(*logSource)) Source {
+	s := &logSource{
+		ctx:         ctx,
+		kc:          c,
+		keys:        make(map[string]Callback, 1),
+		filterLines: true, // Filtering log lines by the watched resource name is enabled by default.
 	}
+	for _, opt := range opts {
+		opt(s)
+	}
+	return s
 }
 
-func FromNamespace(ctx context.Context, c kubernetes.Interface, namespace string) Source {
-	return &namespaceSource{
-		ctx:        ctx,
-		kc:         c,
-		namespaces: []string{namespace},
-		keys:       make(map[string]Callback, 1),
+// WithNamespaces configures namespaces for log stream.
+func WithNamespaces(namespaces ...string) func(*logSource) {
+	return func(s *logSource) {
+		s.namespaces = namespaces
 	}
 }
 
-type namespaceSource struct {
+// WithLineFiltering configures whether log lines will be filtered by
+// the resource name.
+func WithLineFiltering(enabled bool) func(*logSource) {
+	return func(s *logSource) {
+		s.filterLines = enabled
+	}
+}
+
+// WithPodPrefixes specifies which Pods will be included in the
+// log stream through the provided prefixes. If no prefixes are
+// configured then logs from all Pods in the configured namespaces will
+// be streamed.
+func WithPodPrefixes(podPrefixes ...string) func(*logSource) {
+	return func(s *logSource) {
+		s.podPrefixes = podPrefixes
+	}
+}
+
+func FromNamespaces(ctx context.Context, c kubernetes.Interface, namespaces []string, opts ...func(*logSource)) Source {
+	sOpts := []func(*logSource){WithNamespaces(namespaces...)}
+	sOpts = append(sOpts, opts...)
+	return New(ctx, c, sOpts...)
+}
+
+func FromNamespace(ctx context.Context, c kubernetes.Interface, namespace string, opts ...func(*logSource)) Source {
+	return FromNamespaces(ctx, c, []string{namespace}, opts...)
+}
+
+type logSource struct {
 	namespaces []string
 	kc         kubernetes.Interface
 	ctx        context.Context
 
-	m        sync.RWMutex
-	once     sync.Once
-	keys     map[string]Callback
-	watchErr error
+	m           sync.RWMutex
+	once        sync.Once
+	keys        map[string]Callback
+	filterLines bool
+	podPrefixes []string
+	watchErr    error
 }
 
-func (s *namespaceSource) StartStream(name string, l Callback) (Canceler, error) {
+func (s *logSource) StartStream(name string, l Callback) (Canceler, error) {
 	s.once.Do(func() { s.watchErr = s.watchPods() })
 	if s.watchErr != nil {
 		return nil, fmt.Errorf("failed to watch pods in one of the namespace(s) %q: %w", s.namespaces, s.watchErr)
@@ -82,7 +117,10 @@ func (s *namespaceSource) StartStream(name string, l Callback) (Canceler, error)
 	}, nil
 }
 
-func (s *namespaceSource) watchPods() error {
+func (s *logSource) watchPods() error {
+	if len(s.namespaces) == 0 {
+		return errors.New("namespaces for logstream not configured")
+	}
 	for _, ns := range s.namespaces {
 		wi, err := s.kc.CoreV1().Pods(ns).Watch(s.ctx, metav1.ListOptions{})
 		if err != nil {
@@ -113,7 +151,7 @@ func (s *namespaceSource) watchPods() error {
 					case watch.Deleted:
 						watchedPods.Delete(p.Name)
 					case watch.Added, watch.Modified:
-						if !watchedPods.Has(p.Name) && isPodReady(p) {
+						if !watchedPods.Has(p.Name) && isPodReady(p) && s.matchesPodPrefix(p.Name) {
 							watchedPods.Insert(p.Name)
 							s.startForPod(p)
 						}
@@ -127,7 +165,20 @@ func (s *namespaceSource) watchPods() error {
 	return nil
 }
 
-func (s *namespaceSource) startForPod(pod *corev1.Pod) {
+func (s *logSource) matchesPodPrefix(name string) bool {
+	if len(s.podPrefixes) == 0 {
+		// Pod prefixes are not configured => always match.
+		return true
+	}
+	for _, p := range s.podPrefixes {
+		if strings.Contains(name, p) {
+			return true
+		}
+	}
+	return false
+}
+
+func (s *logSource) startForPod(pod *corev1.Pod) {
 	// Grab data from all containers in the pods.  We need this in case
 	// an envoy sidecar is injected for mesh installs.  This should be
 	// equivalent to --all-containers.
@@ -136,7 +187,7 @@ func (s *namespaceSource) startForPod(pod *corev1.Pod) {
 		psn, pn, cn := pod.Namespace, pod.Name, container.Name
 
 		handleLine := s.handleLine
-		if wellKnownContainers.Has(cn) {
+		if wellKnownContainers.Has(cn) || !s.filterLines {
 			// Specialcase logs from chaosduck, queueproxy etc.
 			// - ChaosDuck logs enable easy
 			//   monitoring of killed pods throughout all tests.
@@ -196,7 +247,7 @@ const (
 // are captured without filtering.
 var wellKnownContainers = sets.NewString(ChaosDuck, QueueProxy)
 
-func (s *namespaceSource) handleLine(l []byte, pod string, _ string) {
+func (s *logSource) handleLine(l []byte, pod string, _ string) {
 	// This holds the standard structure of our logs.
 	var line struct {
 		Level      string    `json:"severity"`
@@ -258,7 +309,7 @@ func (s *namespaceSource) handleLine(l []byte, pod string, _ string) {
 
 // handleGenericLine prints the given logline to all active tests as it cannot be parsed
 // and/or doesn't contain any correlation data (like the chaosduck for example).
-func (s *namespaceSource) handleGenericLine(l []byte, pod string, cn string) {
+func (s *logSource) handleGenericLine(l []byte, pod string, cn string) {
 	s.m.RLock()
 	defer s.m.RUnlock()
 
diff --git a/test/logstream/v2/stream_test.go b/test/logstream/v2/stream_test.go
index 63fdee858..f87777a40 100644
--- a/test/logstream/v2/stream_test.go
+++ b/test/logstream/v2/stream_test.go
@@ -219,7 +219,7 @@ func TestNamespaceStream(t *testing.T) {
 	}
 
 	ctx, cancel := context.WithCancel(context.Background())
-	stream := logstream.FromNamespaces(ctx, f, []string{knativePod.Namespace, userPod.Namespace})
+	stream := logstream.New(ctx, f, logstream.WithNamespaces(knativePod.Namespace, userPod.Namespace))
 	streamC, err := stream.StartStream(testKey, logFunc)
 	if err != nil {
 		t.Fatal("Failed to start the stream: ", err)