mirror of
https://github.com/kubernetes/sample-controller.git
synced 2026-05-01 00:00:03 +08:00
099461269d
Automatic merge from submit-queue (batch tested with PRs 67071, 66906, 66722, 67276, 67039). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. #50102 Task 1: Move apimachinery/pkg/watch.Until into client-go/tools/watch.UntilWithoutRetry **What this PR does / why we need it**: This is a split off from https://github.com/kubernetes/kubernetes/pull/50102 to go in smaller pieces. Moves `apimachinery/pkg/watch.Until` into `client-go/tools/watch.UntilWithoutRetry` and adds context so it is cancelable. **Release note**: ```release-note NONE ``` **Dev release note**: ```dev-release-note `apimachinery/pkg/watch.Until` has been moved to `client-go/tools/watch.UntilWithoutRetry`. While switching please consider using the new `client-go/tools/watch.UntilWithSync` or `client-go/tools/watch.Until`. ``` /cc @smarterclayton @kubernetes/sig-api-machinery-pr-reviews /milestone v1.12 /priority important-soon /kind bug (bug after the main PR which is this split from) Kubernetes-commit: b6f0aed056ab94fef0b6f54e1ca1d66a5fc228b3
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes 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 discovery
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"github.com/golang/glog"
|
|
"github.com/gregjones/httpcache"
|
|
"github.com/gregjones/httpcache/diskcache"
|
|
"github.com/peterbourgon/diskv"
|
|
)
|
|
|
|
type cacheRoundTripper struct {
|
|
rt *httpcache.Transport
|
|
}
|
|
|
|
// newCacheRoundTripper creates a roundtripper that reads the ETag on
|
|
// response headers and send the If-None-Match header on subsequent
|
|
// corresponding requests.
|
|
func newCacheRoundTripper(cacheDir string, rt http.RoundTripper) http.RoundTripper {
|
|
d := diskv.New(diskv.Options{
|
|
BasePath: cacheDir,
|
|
TempDir: filepath.Join(cacheDir, ".diskv-temp"),
|
|
})
|
|
t := httpcache.NewTransport(diskcache.NewWithDiskv(d))
|
|
t.Transport = rt
|
|
|
|
return &cacheRoundTripper{rt: t}
|
|
}
|
|
|
|
func (rt *cacheRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
return rt.rt.RoundTrip(req)
|
|
}
|
|
|
|
func (rt *cacheRoundTripper) CancelRequest(req *http.Request) {
|
|
type canceler interface {
|
|
CancelRequest(*http.Request)
|
|
}
|
|
if cr, ok := rt.rt.Transport.(canceler); ok {
|
|
cr.CancelRequest(req)
|
|
} else {
|
|
glog.Errorf("CancelRequest not implemented by %T", rt.rt.Transport)
|
|
}
|
|
}
|
|
|
|
func (rt *cacheRoundTripper) WrappedRoundTripper() http.RoundTripper { return rt.rt.Transport }
|