diff --git a/go.mod b/go.mod index 174e96ed518..18c36d08920 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( k8s.io/code-generator v0.23.9 k8s.io/klog v1.0.0 k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf - knative.dev/pkg v0.0.0-20220805012121-7b8b06028e4f + knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15 sigs.k8s.io/yaml v1.3.0 ) diff --git a/go.sum b/go.sum index ea834dce740..71461be2780 100644 --- a/go.sum +++ b/go.sum @@ -2037,8 +2037,8 @@ k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc= k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -knative.dev/pkg v0.0.0-20220805012121-7b8b06028e4f h1:kW4K5SsjZ7qMzM8TCqHdDmpv0xKN4Jje4BXhDcByFUI= -knative.dev/pkg v0.0.0-20220805012121-7b8b06028e4f/go.mod h1:nBMKMJvyoaJdkpUrjwLVs/DwaP6d73R3UkXK6lblJyE= +knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15 h1:GNmzHVaUo3zoi/wtIN71LPQaWy6DdoYzmb+GIq2s4fw= +knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15/go.mod h1:YLjXbkQLlGHok+u0FLfMbBHFzY9WGu3GHhnrptoAy8I= mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48= mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4= diff --git a/hack/update-deps.sh b/hack/update-deps.sh index 5cfc3c4263e..de6a2cee6c6 100755 --- a/hack/update-deps.sh +++ b/hack/update-deps.sh @@ -22,7 +22,7 @@ source $(git rev-parse --show-toplevel)/vendor/github.com/tektoncd/plumbing/scri cd ${REPO_ROOT_DIR} -VERSION="release-1.6" +VERSION="release-1.7" # The list of dependencies that we track at HEAD and periodically # float forward in this repository. diff --git a/vendor/knative.dev/pkg/network/handlers/drain.go b/vendor/knative.dev/pkg/network/handlers/drain.go index d6ef19f4eac..5eee2ea42e3 100644 --- a/vendor/knative.dev/pkg/network/handlers/drain.go +++ b/vendor/knative.dev/pkg/network/handlers/drain.go @@ -70,12 +70,15 @@ type Drainer struct { // 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 timer + // used to synchronize callers of Drain + drainCh chan struct{} + + // used to synchronize Drain and Reset + resetCh chan struct{} + // HealthCheckUAPrefixes are the additional user agent prefixes that trigger the // drainer's health check HealthCheckUAPrefixes []string @@ -106,7 +109,7 @@ func (d *Drainer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - d.reset() + d.resetTimer() d.Inner.ServeHTTP(w, r) } @@ -115,19 +118,36 @@ func (d *Drainer) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (d *Drainer) Drain() { // Note: until the first caller exits, the others // will wait blocked as well. - d.once.Do(func() { - t := func() timer { - d.Lock() - defer d.Unlock() - if d.QuietPeriod <= 0 { - d.QuietPeriod = network.DefaultDrainTimeout + ch := func() chan struct{} { + d.Lock() + defer d.Unlock() + if d.drainCh != nil { + return d.drainCh + } + + if d.QuietPeriod <= 0 { + d.QuietPeriod = network.DefaultDrainTimeout + } + + timer := newTimer(d.QuietPeriod) + drainCh := make(chan struct{}) + resetCh := make(chan struct{}) + + go func() { + select { + case <-resetCh: + case <-timer.tickChan(): } - d.timer = newTimer(d.QuietPeriod) - return d.timer + close(drainCh) }() - <-t.tickChan() - }) + d.drainCh = drainCh + d.resetCh = resetCh + d.timer = timer + return drainCh + }() + + <-ch } // isHealthcheckRequest validates if the request has a user agent that is for healthcheck @@ -145,8 +165,27 @@ func (d *Drainer) isHealthCheckRequest(r *http.Request) bool { return false } -// reset resets the drain timer to the full amount of time. -func (d *Drainer) reset() { +// Reset interrupts Drain and clears the drainers internal state +// Thus further calls to Drain will block and wait for the entire QuietPeriod +func (d *Drainer) Reset() { + d.Lock() + defer d.Unlock() + + if d.timer != nil { + d.timer.Stop() + d.timer = nil + } + + if d.resetCh != nil { + close(d.resetCh) + d.resetCh = nil + } + if d.drainCh != nil { + d.drainCh = nil + } +} + +func (d *Drainer) resetTimer() { if func() bool { d.RLock() defer d.RUnlock() diff --git a/vendor/modules.txt b/vendor/modules.txt index 2244364d190..01538452290 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1176,7 +1176,7 @@ k8s.io/utils/internal/third_party/forked/golang/net k8s.io/utils/net k8s.io/utils/pointer k8s.io/utils/trace -# knative.dev/pkg v0.0.0-20220805012121-7b8b06028e4f +# knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15 ## explicit; go 1.18 knative.dev/pkg/apis knative.dev/pkg/apis/duck