Repository: knative/pkg
Pull request #1517 (2020-07-17 23:17:49)

Implement a new shared "Drainer" handler.
This implements a new `http.Handler` called `Drainer`, which is intended to wrap some inner `http.Handler` business logic with a new outer handler that can respond to Kubelet probes (successfully until told to "Drain()").

This takes over the webhook's relatively new probe handling and lame duck logic with one key difference.  Previously the webhook waited for a fixed period after SIGTERM before exitting, but the new logic waits for this same grace period AFTER THE LAST REQUEST.  So if the handler keeps getting (non-probe) requests, the timer will continually reset, and once it stops receiving requests for the configured grace period, "Drain()" will return and the webhook will exit.

The goal of this work is to try to better cope with what we believe to be high tail latencies of the API server seeing that a webhook replica is shutting down.

Related: https://github.com/knative/pkg/issues/1509

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1517#" title="Author self-approved">mattmoor</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[network/OWNERS](https://github.com/knative/pkg/blob/master/network/OWNERS)~~ [mattmoor]
- ~~[webhook/OWNERS](https://github.com/knative/pkg/blob/master/webhook/OWNERS)~~ [mattmoor]

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":[]} -->
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-pkg-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[network/handlers/drain.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1517/pull-knative-pkg-go-coverage/1284266255112474624/artifacts/line-cov.html#file1) | Do not exist | 96.0% | 
[webhook/webhook.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1517/pull-knative-pkg-go-coverage/1284266255112474624/artifacts/line-cov.html#file2) | 87.0% | 85.9% | -1.0

knative-prow-robot: @mattmoor: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-pkg-unit-tests | c76b2f1a99ec3ba76b8a4ebcca38f9d1355cd4f0 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_pkg/1517/pull-knative-pkg-unit-tests/1284266255116668928) | `/test pull-knative-pkg-unit-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_pkg/1517). [Your PR dashboard](https://gubernator.knative.dev/pr/mattmoor).

<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-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-pkg-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[network/handlers/drain.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1517/pull-knative-pkg-go-coverage/1284273427238096896/artifacts/line-cov.html#file1) | Do not exist | 96.0% | 
[webhook/webhook.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1517/pull-knative-pkg-go-coverage/1284273427238096896/artifacts/line-cov.html#file2) | 87.0% | 85.9% | -1.0

knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-pkg-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[network/handlers/drain.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1517/pull-knative-pkg-go-coverage/1284327785858338818/artifacts/line-cov.html#file1) | Do not exist | 96.4% | 
[webhook/webhook.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1517/pull-knative-pkg-go-coverage/1284327785858338818/artifacts/line-cov.html#file2) | 87.0% | 85.9% | -1.0

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1517#" title="Author self-approved">mattmoor</a>*, *<a href="https://github.com/knative/pkg/pull/1517#pullrequestreview-451027567" title="Approved">vagababov</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[network/OWNERS](https://github.com/knative/pkg/blob/master/network/OWNERS)~~ [mattmoor,vagababov]
- ~~[webhook/OWNERS](https://github.com/knative/pkg/blob/master/webhook/OWNERS)~~ [mattmoor]

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":[]} -->

Patch:
diff --git a/leaderelection/context.go b/leaderelection/context.go
index ba9b6dc0d..eaae67a77 100644
--- a/leaderelection/context.go
+++ b/leaderelection/context.go
@@ -19,6 +19,7 @@ package leaderelection
 import (
 	"context"
 	"fmt"
+	"hash/fnv"
 	"strings"
 	"sync"
 
@@ -81,11 +82,11 @@ type Elector interface {
 
 // BuildElector builds a leaderelection.LeaderElector for the named LeaderAware
 // reconciler using a builder added to the context via WithStandardLeaderElectorBuilder.
-func BuildElector(ctx context.Context, la reconciler.LeaderAware, queueName string, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
+func BuildElector(ctx context.Context, la reconciler.LeaderAware, name string, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
 	if val := ctx.Value(builderKey{}); val != nil {
 		switch builder := val.(type) {
 		case *standardBuilder:
-			return builder.buildElector(ctx, la, queueName, enq)
+			return builder.buildElector(ctx, la, name, enq)
 		case *statefulSetBuilder:
 			return builder.buildElector(ctx, la, enq)
 		}
@@ -106,7 +107,7 @@ type standardBuilder struct {
 }
 
 func (b *standardBuilder) buildElector(ctx context.Context, la reconciler.LeaderAware,
-	queueName string, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
+	name string, enq func(reconciler.Bucket, types.NamespacedName)) (Elector, error) {
 	logger := logging.FromContext(ctx)
 
 	id, err := UniqueID()
@@ -114,9 +115,16 @@ func (b *standardBuilder) buildElector(ctx context.Context, la reconciler.Leader
 		return nil, err
 	}
 
-	bkts := newStandardBuckets(queueName, b.lec)
-	electors := make([]Elector, 0, b.lec.Buckets)
-	for _, bkt := range bkts {
+	buckets := make([]Elector, 0, b.lec.Buckets)
+	for i := uint32(0); i < b.lec.Buckets; i++ {
+		bkt := &bucket{
+			// The resource name is the lowercase:
+			//   {component}.{workqueue}.{index}-of-{total}
+			name:  strings.ToLower(fmt.Sprintf("%s.%s.%02d-of-%02d", b.lec.Component, name, i, b.lec.Buckets)),
+			index: i,
+			total: b.lec.Buckets,
+		}
+
 		rl, err := resourcelock.New(KnativeResourceLock,
 			system.Namespace(), // use namespace we are running in
 			bkt.Name(),
@@ -160,27 +168,9 @@ func (b *standardBuilder) buildElector(ctx context.Context, la reconciler.Leader
 		// if lec.WatchDog != nil {
 		// 	lec.WatchDog.SetLeaderElection(le)
 		// }
-		electors = append(electors, &runUntilCancelled{Elector: le})
-	}
-	return &runAll{les: electors}, nil
-}
-
-func newStandardBuckets(queueName string, cc ComponentConfig) []reconciler.Bucket {
-	names := make(sets.String, cc.Buckets)
-	for i := uint32(0); i < cc.Buckets; i++ {
-		names.Insert(standardBucketName(i, queueName, cc))
+		buckets = append(buckets, &runUntilCancelled{Elector: le})
 	}
-	bs := hash.NewBucketSet(names)
-
-	bkts := make([]reconciler.Bucket, 0, cc.Buckets)
-	for name := range names {
-		bkts = append(bkts, hash.NewBucket(name, bs))
-	}
-	return bkts
-}
-
-func standardBucketName(ordinal uint32, queueName string, cc ComponentConfig) string {
-	return strings.ToLower(fmt.Sprintf("%s.%s.%02d-of-%02d", cc.Component, queueName, ordinal, cc.Buckets))
+	return &runAll{les: buckets}, nil
 }
 
 type statefulSetBuilder struct {
@@ -279,3 +269,26 @@ func (ruc *runUntilCancelled) Run(ctx context.Context) {
 		}
 	}
 }
+
+type bucket struct {
+	name string
+
+	// We are bucket {index} of {total}
+	index uint32
+	total uint32
+}
+
+var _ reconciler.Bucket = (*bucket)(nil)
+
+// Name implements reconciler.Bucket
+func (b *bucket) Name() string {
+	return b.name
+}
+
+// Has implements reconciler.Bucket
+func (b *bucket) Has(nn types.NamespacedName) bool {
+	h := fnv.New32a()
+	h.Write([]byte(nn.Namespace + "." + nn.Name))
+	ii := h.Sum32() % b.total
+	return b.index == ii
+}
diff --git a/network/error_handler.go b/network/error_handler.go
index 486518b96..8518c0401 100644
--- a/network/error_handler.go
+++ b/network/error_handler.go
@@ -25,6 +25,8 @@ import (
 
 // ErrorHandler sets up a handler suitable for use with the ErrorHandler field on
 // httputil's reverse proxy.
+// TODO(mattmoor): Move the implementation into handlers/error.go once downstream consumers
+// have adopted the alias.
 func ErrorHandler(logger *zap.SugaredLogger) func(http.ResponseWriter, *http.Request, error) {
 	return func(w http.ResponseWriter, req *http.Request, err error) {
 		ss := readSockStat(logger)
diff --git a/network/handlers/doc.go b/network/handlers/doc.go
new file mode 100644
index 000000000..3b5f97504
--- /dev/null
+++ b/network/handlers/doc.go
@@ -0,0 +1,18 @@
+/*
+Copyright 2020 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.
+*/
+
+// Package handlers holds useful HTTP handler implementations.
+package handlers
diff --git a/network/handlers/drain.go b/network/handlers/drain.go
new file mode 100644
index 000000000..7bdeffb9d
--- /dev/null
+++ b/network/handlers/drain.go
@@ -0,0 +1,110 @@
+/*
+Copyright 2020 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.
+*/
+
+package handlers
+
+import (
+	"net/http"
+	"sync"
+	"time"
+
+	"knative.dev/pkg/network"
+)
+
+// Drainer wraps an inner http.Handler to support responding to kubelet
+// probes with a "200 OK" until the handler is told to Drain.
+// When the Drainer is told to Drain, it will immediately start to fail
+// probes with a "500 shutting down", and the call will block until no
+// requests have been received for QuietPeriod (defaults to
+// network.DefaultDrainTimeout).
+type Drainer struct {
+	// Mutex guards the initialization and resets of the timer
+	sync.RWMutex
+
+	// Inner is the http.Handler to which we delegate actual requests.
+	Inner http.Handler
+
+	// QuietPeriod is the duration that must elapse without any requests
+	// after Drain is called before it may return.
+	QuietPeriod time.Duration
+
+	// once is used to initialize timer
+	once sync.Once
+
+	// timer is used to orchestrate the drain.
+	timer *time.Timer
+}
+
+// Ensure Drainer implements http.Handler
+var _ http.Handler = (*Drainer)(nil)
+
+// ServeHTTP implements http.Handler
+func (d *Drainer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	if network.IsKubeletProbe(r) { // Respond to probes regardless of path.
+		if d.draining() {
+			http.Error(w, "shutting down", http.StatusServiceUnavailable)
+		} else {
+			w.WriteHeader(http.StatusOK)
+		}
+		return
+	}
+
+	d.reset()
+	d.Inner.ServeHTTP(w, r)
+}
+
+// Drain blocks until QuietPeriod has elapsed since the last request,
+// starting when this is invoked.
+func (d *Drainer) Drain() {
+	d.once.Do(func() {
+		t := func() *time.Timer {
+			d.Lock()
+			defer d.Unlock()
+			if d.QuietPeriod <= 0 {
+				d.QuietPeriod = network.DefaultDrainTimeout
+			}
+			d.timer = time.NewTimer(d.QuietPeriod)
+			return d.timer
+		}()
+
+		<-t.C
+	})
+}
+
+// reset resets the drain timer to the full amount of time.
+func (d *Drainer) reset() {
+	if func() bool {
+		d.RLock()
+		defer d.RUnlock()
+		return d.timer == nil
+	}() {
+		return
+	}
+
+	d.Lock()
+	defer d.Unlock()
+	if d.timer.Stop() {
+		d.timer.Reset(d.QuietPeriod)
+	}
+}
+
+// draining returns whether we are draining the handler.
+func (d *Drainer) draining() bool {
+	d.RLock()
+	defer d.RUnlock()
+
+	return d.timer != nil
+}
diff --git a/network/handlers/error.go b/network/handlers/error.go
new file mode 100644
index 000000000..a6bd3bd03
--- /dev/null
+++ b/network/handlers/error.go
@@ -0,0 +1,23 @@
+/*
+Copyright 2020 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.
+*/
+
+package handlers
+
+import "knative.dev/pkg/network"
+
+// Error sets up a handler suitable for use with the ErrorHandler field on
+// httputil's reverse proxy, which logs /proc/net/sockstat data.
+var Error = network.ErrorHandler
diff --git a/webhook/webhook.go b/webhook/webhook.go
index 6052d717a..8d628c5e3 100644
--- a/webhook/webhook.go
+++ b/webhook/webhook.go
@@ -27,6 +27,7 @@ import (
 	// Injection stuff
 	kubeclient "knative.dev/pkg/client/injection/kube/client"
 	kubeinformerfactory "knative.dev/pkg/injection/clients/namespacedkube/informers/factory"
+	"knative.dev/pkg/network/handlers"
 
 	"go.uber.org/zap"
 	"golang.org/x/sync/errgroup"
@@ -83,8 +84,6 @@ type Webhook struct {
 	// synced is function that is called when the informers have been synced.
 	synced context.CancelFunc
 
-	// stopCh is closed when we should start failing readiness probes.
-	stopCh chan struct{}
 	// grace period is how long to wait after failing readiness probes
 	// before shutting down.
 	gracePeriod time.Duration
@@ -137,7 +136,6 @@ func New(
 		secretlister: secretInformer.Lister(),
 		Logger:       logger,
 		synced:       cancel,
-		stopCh:       make(chan struct{}),
 		gracePeriod:  network.DefaultDrainTimeout,
 	}
 
@@ -176,8 +174,13 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
 	logger := wh.Logger
 	ctx := logging.WithLogger(context.Background(), logger)
 
+	drainer := &handlers.Drainer{
+		Inner:       wh,
+		QuietPeriod: wh.gracePeriod,
+	}
+
 	server := &http.Server{
-		Handler: wh,
+		Handler: drainer,
 		Addr:    fmt.Sprintf(":%d", wh.Options.Port),
 		TLSConfig: &tls.Config{
 			GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
@@ -215,19 +218,12 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
 	select {
 	case <-stop:
 		eg.Go(func() error {
-			// Start failing readiness probes immediately.
-			logger.Info("Starting to fail readiness probes...")
-			close(wh.stopCh)
-
 			// As we start to shutdown, disable keep-alives to avoid clients hanging onto connections.
 			server.SetKeepAlivesEnabled(false)
 
-			// Wait for a grace period for the above to take effect and this Pod's
-			// endpoint to be removed from the webhook service's Endpoints.
-			// For this to be effective, it must be greater than the probe's
-			// periodSeconds times failureThreshold by a margin suitable to
-			// propagate the new Endpoints data across the cluster.
-			time.Sleep(wh.gracePeriod)
+			// Start failing readiness probes immediately.
+			logger.Info("Starting to fail readiness probes...")
+			drainer.Drain()
 
 			return server.Shutdown(context.Background())
 		})
@@ -241,17 +237,6 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
 }
 
 func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	// Respond to probes regardless of path.
-	if network.IsKubeletProbe(r) {
-		select {
-		case <-wh.stopCh:
-			http.Error(w, "shutting down", http.StatusInternalServerError)
-		default:
-			w.WriteHeader(http.StatusOK)
-		}
-		return
-	}
-
 	// Verify the content type is accurate.
 	contentType := r.Header.Get("Content-Type")
 	if contentType != "application/json" {


Test patch:
diff --git a/network/handlers/drain_test.go b/network/handlers/drain_test.go
new file mode 100644
index 000000000..769ed0902
--- /dev/null
+++ b/network/handlers/drain_test.go
@@ -0,0 +1,160 @@
+/*
+Copyright 2020 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.
+*/
+
+package handlers
+
+import (
+	"context"
+	"net/http"
+	"net/http/httptest"
+	"testing"
+	"time"
+
+	"knative.dev/pkg/network"
+)
+
+func TestDrainMechanics(t *testing.T) {
+	var (
+		w     http.ResponseWriter
+		req   = &http.Request{}
+		probe = &http.Request{
+			Header: http.Header{
+				"User-Agent": []string{network.KubeProbeUAPrefix},
+			},
+		}
+	)
+
+	inner := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
+
+	drainer := &Drainer{
+		Inner:       inner,
+		QuietPeriod: 100 * time.Millisecond,
+	}
+
+	// Works before Drain is called.
+	drainer.ServeHTTP(w, req)
+	drainer.ServeHTTP(w, req)
+	drainer.ServeHTTP(w, req)
+
+	// Check for 200 OK
+	resp := httptest.NewRecorder()
+	drainer.ServeHTTP(resp, probe)
+	if got, want := resp.Code, http.StatusOK; got != want {
+		t.Errorf("probe status = %d, wanted %d", got, want)
+	}
+
+	// Start to drain, and cancel the context when it returns.
+	ctx, cancel := context.WithCancel(context.Background())
+	go func() {
+		drainer.Drain()
+		cancel()
+	}()
+
+	select {
+	case <-time.After(40 * time.Millisecond):
+		// Drain is blocking.
+	case <-ctx.Done():
+		t.Error("Drain terminated prematurely.")
+	}
+	// Now send a request to reset things.
+	drainer.ServeHTTP(w, req)
+
+	// Check for 400 shutting down
+	resp = httptest.NewRecorder()
+	drainer.ServeHTTP(resp, probe)
+	if got, want := resp.Code, http.StatusServiceUnavailable; got != want {
+		t.Errorf("probe status = %d, wanted %d", got, want)
+	}
+
+	select {
+	case <-time.After(40 * time.Millisecond):
+		// Drain is blocking.
+	case <-ctx.Done():
+		t.Error("Drain terminated prematurely.")
+	}
+	// Now send a request to reset things.
+	drainer.ServeHTTP(w, req)
+
+	select {
+	case <-time.After(40 * time.Millisecond):
+		// Drain is blocking.
+	case <-ctx.Done():
+		t.Error("Drain terminated prematurely.")
+	}
+	// Now send a request to reset things.
+	drainer.ServeHTTP(w, req)
+
+	select {
+	case <-time.After(40 * time.Millisecond):
+		// Drain is blocking.
+	case <-ctx.Done():
+		t.Error("Drain terminated prematurely.")
+	}
+	// Probing does not reset the clock.
+	// Check for 500 shutting down
+	resp = httptest.NewRecorder()
+	drainer.ServeHTTP(resp, probe)
+	if got, want := resp.Code, http.StatusServiceUnavailable; got != want {
+		t.Errorf("probe status = %d, wanted %d", got, want)
+	}
+
+	// Big finish, test that multiple invocations of Drain all block.
+	ctx1, cancel1 := context.WithCancel(context.Background())
+	go func() {
+		drainer.Drain()
+		cancel1()
+	}()
+	ctx2, cancel2 := context.WithCancel(context.Background())
+	go func() {
+		drainer.Drain()
+		cancel2()
+	}()
+	ctx3, cancel3 := context.WithCancel(context.Background())
+	go func() {
+		drainer.Drain()
+		cancel3()
+	}()
+
+	select {
+	case <-time.After(70 * time.Millisecond):
+		t.Error("Timed out waiting for Drain to return.")
+
+	case <-ctx.Done():
+	case <-ctx1.Done():
+	case <-ctx2.Done():
+	case <-ctx3.Done():
+		// Once the first context is cancelled, check that all of them are cancelled.
+	}
+
+	// Check that a 4th and final one after things complete finishes instantly.
+	ctx4, cancel4 := context.WithCancel(context.Background())
+	go func() {
+		drainer.Drain()
+		cancel4()
+	}()
+
+	// Give the rest a short window to complete.
+	time.Sleep(time.Millisecond)
+
+	for idx, ictx := range []context.Context{ctx, ctx1, ctx2, ctx3, ctx4} {
+		select {
+		case <-ictx.Done():
+			// Should be done.
+		default:
+			t.Errorf("Drain[%d] did not complete.", idx)
+		}
+	}
+}
diff --git a/webhook/webhook_test.go b/webhook/webhook_test.go
index b91d9cbd9..d0cf124e0 100644
--- a/webhook/webhook_test.go
+++ b/webhook/webhook_test.go
@@ -20,8 +20,6 @@ import (
 	"context"
 	"fmt"
 	"net"
-	"net/http"
-	"net/http/httptest"
 	"testing"
 	"time"
 
@@ -94,51 +92,3 @@ func TestRegistrationStopChanFire(t *testing.T) {
 		t.Errorf("Unexpected success to dial to port %d", opts.Port)
 	}
 }
-
-func TestWebhookKubeletProbe(t *testing.T) {
-	opts := newDefaultOptions()
-	ctx, webhook, cancel := newNonRunningTestWebhook(t, opts)
-	defer cancel()
-
-	recorder := bombRecorder{ResponseRecorder: httptest.NewRecorder()}
-	probeReq := httptest.NewRequest("GET", "/", nil)
-	probeReq.Header.Set("User-Agent", "kube-probe/1.16")
-
-	webhook.ServeHTTP(&recorder, probeReq)
-
-	if got, want := recorder.Code, http.StatusOK; got != want {
-		t.Fatalf("Probe got HTTP status %d - expected %d", got, want)
-	}
-
-	if got, want := recorder.writeCount, 1; got != want {
-		t.Errorf("HTTP status was written %d times - expected only one write", got)
-	}
-
-	// Stop the webhook - which means probes should fail
-	//
-	// The steps below aren't obvious and requires you to
-	// know the implementation details
-	cancel()
-	webhook.Run(ctx.Done())
-
-	recorder = bombRecorder{ResponseRecorder: httptest.NewRecorder()}
-	webhook.ServeHTTP(&recorder, probeReq)
-
-	if got, want := recorder.Code, http.StatusInternalServerError; got != want {
-		t.Fatalf("Probe got HTTP status %d - expected %d", got, want)
-	}
-
-	if got, want := recorder.writeCount, 1; got != want {
-		t.Errorf("HTTP status was written %d times - expected only one write", got)
-	}
-}
-
-type bombRecorder struct {
-	*httptest.ResponseRecorder
-	writeCount int
-}
-
-func (rw *bombRecorder) WriteHeader(code int) {
-	rw.writeCount += 1
-	rw.ResponseRecorder.WriteHeader(code)
-}