From 5c01a03456f3460b330eb079d8ef2d73d4c24a19 Mon Sep 17 00:00:00 2001 From: Andrea Tosatto Date: Fri, 22 Jan 2021 14:57:14 +0100 Subject: [PATCH 1/7] client-go: export NewDebuggingRoundTripper function and DebugLevel `debuggingRoundTripper` is a useful throbleshooting tool to debug of Kubernetes API requests and their timing. Unfortunately, as of today, it can only be used via the `DebugWrappers` function, which automatically adjust the amount of debug information exposed by the roundTripper based on the configured `klog` verbosity. While `DebugWrappers` definitely fits the purpose for clients using `klog`, this is currently hard to be used for controllers using `controller-runtime`, which uses `github.com/go-logr/logr` for logging. In this PR we change the visibility of `newDebuggingRoundTripper` and `debugLevel` in order to be directly accessible from users of the `k8s.io/client-go/transport` package. In particular, the changes proposed in this PR allow users of `controller-runtime` to use the `debuggingRoundTripper` to intercept Kubernetes API requests as follows ```go import ( ctrl "sigs.k8s.io/controller-runtime" ) func init() { ctrl.SetLogger(zap.New()) } func main() { // wrap the http transport used by the Kubernetes client restConfig, err := ctrl.GetConfig() checkError(setupLog, err, "unable to get kubernetes client config") restConfig.Wrap(func(rt http.RoundTripper) http.RoundTripper { return transport.NewDebuggingRoundTripper(rt, transport.DebugJustURL) }) ... } ``` Kubernetes-commit: 8de53ce96cb58d56fd00e91d8bcf7761ab498b83 --- transport/round_trippers.go | 53 +++++++++------- transport/round_trippers_test.go | 102 +++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 22 deletions(-) diff --git a/transport/round_trippers.go b/transport/round_trippers.go index 56df8ead..def28aee 100644 --- a/transport/round_trippers.go +++ b/transport/round_trippers.go @@ -68,13 +68,13 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip func DebugWrappers(rt http.RoundTripper) http.RoundTripper { switch { case bool(klog.V(9).Enabled()): - rt = newDebuggingRoundTripper(rt, debugCurlCommand, debugURLTiming, debugResponseHeaders) + rt = NewDebuggingRoundTripper(rt, DebugCurlCommand, DebugURLTiming, DebugResponseHeaders) case bool(klog.V(8).Enabled()): - rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus, debugResponseHeaders) + rt = NewDebuggingRoundTripper(rt, DebugJustURL, DebugRequestHeaders, DebugResponseStatus, DebugResponseHeaders) case bool(klog.V(7).Enabled()): - rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus) + rt = NewDebuggingRoundTripper(rt, DebugJustURL, DebugRequestHeaders, DebugResponseStatus) case bool(klog.V(6).Enabled()): - rt = newDebuggingRoundTripper(rt, debugURLTiming) + rt = NewDebuggingRoundTripper(rt, DebugURLTiming) } return rt @@ -353,25 +353,35 @@ func (r *requestInfo) toCurl() string { // through it based on what is configured type debuggingRoundTripper struct { delegatedRoundTripper http.RoundTripper - - levels map[debugLevel]bool + levels map[DebugLevel]bool } -type debugLevel int +// DebugLevel is used to enable debugging of certain +// HTTP requests and responses fields via the debuggingRoundTripper. +type DebugLevel int const ( - debugJustURL debugLevel = iota - debugURLTiming - debugCurlCommand - debugRequestHeaders - debugResponseStatus - debugResponseHeaders + // DebugJustURL will add to the debug output HTTP requests method and url. + DebugJustURL DebugLevel = iota + // DebugURLTiming will add to the debug output the duration of HTTP requests. + DebugURLTiming + // DebugCurlCommand will add to the debug output the curl command equivalent to the + // HTTP request. + DebugCurlCommand + // DebugRequestHeaders will add to the debug output the HTTP requests headers. + DebugRequestHeaders + // DebugResponseStatus will add to the debug output the HTTP response status. + DebugResponseStatus + // DebugResponseHeaders will add to the debug output the HTTP response headers. + DebugResponseHeaders ) -func newDebuggingRoundTripper(rt http.RoundTripper, levels ...debugLevel) *debuggingRoundTripper { +// NewDebuggingRoundTripper allows to display in the logs output debug information +// on the API requests performed by the client. +func NewDebuggingRoundTripper(rt http.RoundTripper, levels ...DebugLevel) *debuggingRoundTripper { drt := &debuggingRoundTripper{ delegatedRoundTripper: rt, - levels: make(map[debugLevel]bool, len(levels)), + levels: make(map[DebugLevel]bool, len(levels)), } for _, v := range levels { drt.levels[v] = true @@ -418,14 +428,13 @@ func maskValue(key string, value string) string { func (rt *debuggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { reqInfo := newRequestInfo(req) - if rt.levels[debugJustURL] { + if rt.levels[DebugJustURL] { klog.Infof("%s %s", reqInfo.RequestVerb, reqInfo.RequestURL) } - if rt.levels[debugCurlCommand] { + if rt.levels[DebugCurlCommand] { klog.Infof("%s", reqInfo.toCurl()) - } - if rt.levels[debugRequestHeaders] { + if rt.levels[DebugRequestHeaders] { klog.Info("Request Headers:") for key, values := range reqInfo.RequestHeaders { for _, value := range values { @@ -441,13 +450,13 @@ func (rt *debuggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, e reqInfo.complete(response, err) - if rt.levels[debugURLTiming] { + if rt.levels[DebugURLTiming] { klog.Infof("%s %s %s in %d milliseconds", reqInfo.RequestVerb, reqInfo.RequestURL, reqInfo.ResponseStatus, reqInfo.Duration.Nanoseconds()/int64(time.Millisecond)) } - if rt.levels[debugResponseStatus] { + if rt.levels[DebugResponseStatus] { klog.Infof("Response Status: %s in %d milliseconds", reqInfo.ResponseStatus, reqInfo.Duration.Nanoseconds()/int64(time.Millisecond)) } - if rt.levels[debugResponseHeaders] { + if rt.levels[DebugResponseHeaders] { klog.Info("Response Headers:") for key, values := range reqInfo.ResponseHeaders { for _, value := range values { diff --git a/transport/round_trippers_test.go b/transport/round_trippers_test.go index ac8de240..94d4630f 100644 --- a/transport/round_trippers_test.go +++ b/transport/round_trippers_test.go @@ -17,6 +17,9 @@ limitations under the License. package transport import ( + "bytes" + "fmt" + "k8s.io/klog/v2" "net/http" "net/url" "reflect" @@ -412,3 +415,102 @@ func TestHeaderEscapeRoundTrip(t *testing.T) { }) } } + +func TestDebuggingRoundTripper(t *testing.T) { + t.Parallel() + + rawUrl := "https://127.0.0.1:12345/api/v1/pods?limit=500" + req := &http.Request{ + Method: http.MethodGet, + Header: map[string][]string{ + "Authorization": []string{"bearer secretauthtoken"}, + "X-Test-Request": []string{"test"}, + }, + } + res := &http.Response{ + Status: "OK", + StatusCode: http.StatusOK, + Header: map[string][]string{ + "X-Test-Response": []string{"test"}, + }, + } + tcs := []struct { + levels []DebugLevel + expectedOutputLines []string + }{ + { + levels: []DebugLevel{DebugJustURL}, + expectedOutputLines: []string{fmt.Sprintf("%s %s", req.Method, rawUrl)}, + }, + { + levels: []DebugLevel{DebugRequestHeaders}, + expectedOutputLines: func() []string { + lines := []string{fmt.Sprintf("Request Headers:\n")} + for key, values := range req.Header { + for _, value := range values { + if key == "Authorization" { + value = "bearer " + } + lines = append(lines, fmt.Sprintf(" %s: %s\n", key, value)) + } + } + return lines + }(), + }, + { + levels: []DebugLevel{DebugResponseHeaders}, + expectedOutputLines: func() []string { + lines := []string{fmt.Sprintf("Response Headers:\n")} + for key, values := range res.Header { + for _, value := range values { + lines = append(lines, fmt.Sprintf(" %s: %s\n", key, value)) + } + } + return lines + }(), + }, + { + levels: []DebugLevel{DebugURLTiming}, + expectedOutputLines: []string{fmt.Sprintf("%s %s %s", req.Method, rawUrl, res.Status)}, + }, + { + levels: []DebugLevel{DebugResponseStatus}, + expectedOutputLines: []string{fmt.Sprintf("Response Status: %s", res.Status)}, + }, + { + levels: []DebugLevel{DebugCurlCommand}, + expectedOutputLines: []string{fmt.Sprintf("curl -k -v -X")}, + }, + } + + for _, tc := range tcs { + // hijack the klog output + tmpWriteBuffer := bytes.NewBuffer(nil) + klog.SetOutput(tmpWriteBuffer) + klog.LogToStderr(false) + + // parse rawUrl + parsedUrl, err := url.Parse(rawUrl) + if err != nil { + t.Fatalf("url.Parse(%q) returned error: %v", rawUrl, err) + } + req.URL = parsedUrl + + // execute the round tripper + rt := &testRoundTripper{ + Response: res, + } + NewDebuggingRoundTripper(rt, tc.levels...).RoundTrip(req) + + // call Flush to ensure the text isn't still buffered + klog.Flush() + + // check if klog's output contains the expected lines + actual := tmpWriteBuffer.String() + for _, expected := range tc.expectedOutputLines { + if !strings.Contains(actual, expected) { + t.Errorf("%q does not contain expected output %q", actual, expected) + } + } + } +} From 2bce1731ebd3460e8a75dabc28fbf76c63b16887 Mon Sep 17 00:00:00 2001 From: Andrea Tosatto Date: Tue, 26 Jan 2021 22:04:52 +0000 Subject: [PATCH 2/7] Run gofmt against staging/src/k8s.io/client-go/transport/round_trippers.go Kubernetes-commit: 9cb5580ac6584cc787a2b2061c6c61656d065392 --- transport/round_trippers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transport/round_trippers.go b/transport/round_trippers.go index def28aee..25e26f60 100644 --- a/transport/round_trippers.go +++ b/transport/round_trippers.go @@ -353,7 +353,7 @@ func (r *requestInfo) toCurl() string { // through it based on what is configured type debuggingRoundTripper struct { delegatedRoundTripper http.RoundTripper - levels map[DebugLevel]bool + levels map[DebugLevel]bool } // DebugLevel is used to enable debugging of certain @@ -381,7 +381,7 @@ const ( func NewDebuggingRoundTripper(rt http.RoundTripper, levels ...DebugLevel) *debuggingRoundTripper { drt := &debuggingRoundTripper{ delegatedRoundTripper: rt, - levels: make(map[DebugLevel]bool, len(levels)), + levels: make(map[DebugLevel]bool, len(levels)), } for _, v := range levels { drt.levels[v] = true From 8d3dc9e9ef794ff14d16cfbaf8b84e3c74121ff3 Mon Sep 17 00:00:00 2001 From: Andrea Tosatto Date: Tue, 26 Jan 2021 23:14:56 +0000 Subject: [PATCH 3/7] Run gofmt against staging/src/k8s.io/client-go/transport/round_trippers_test.go Kubernetes-commit: e87349f3caa810b96ed86fac7aec6bd0e73dacb1 --- transport/round_trippers_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/transport/round_trippers_test.go b/transport/round_trippers_test.go index 94d4630f..c55ac0f8 100644 --- a/transport/round_trippers_test.go +++ b/transport/round_trippers_test.go @@ -421,15 +421,15 @@ func TestDebuggingRoundTripper(t *testing.T) { rawUrl := "https://127.0.0.1:12345/api/v1/pods?limit=500" req := &http.Request{ - Method: http.MethodGet, + Method: http.MethodGet, Header: map[string][]string{ - "Authorization": []string{"bearer secretauthtoken"}, + "Authorization": []string{"bearer secretauthtoken"}, "X-Test-Request": []string{"test"}, }, } res := &http.Response{ - Status: "OK", - StatusCode: http.StatusOK, + Status: "OK", + StatusCode: http.StatusOK, Header: map[string][]string{ "X-Test-Response": []string{"test"}, }, @@ -439,7 +439,7 @@ func TestDebuggingRoundTripper(t *testing.T) { expectedOutputLines []string }{ { - levels: []DebugLevel{DebugJustURL}, + levels: []DebugLevel{DebugJustURL}, expectedOutputLines: []string{fmt.Sprintf("%s %s", req.Method, rawUrl)}, }, { @@ -470,15 +470,15 @@ func TestDebuggingRoundTripper(t *testing.T) { }(), }, { - levels: []DebugLevel{DebugURLTiming}, + levels: []DebugLevel{DebugURLTiming}, expectedOutputLines: []string{fmt.Sprintf("%s %s %s", req.Method, rawUrl, res.Status)}, }, { - levels: []DebugLevel{DebugResponseStatus}, + levels: []DebugLevel{DebugResponseStatus}, expectedOutputLines: []string{fmt.Sprintf("Response Status: %s", res.Status)}, }, { - levels: []DebugLevel{DebugCurlCommand}, + levels: []DebugLevel{DebugCurlCommand}, expectedOutputLines: []string{fmt.Sprintf("curl -k -v -X")}, }, } From 84db31c178eb1b38f6b09c1257579d5c117bf62b Mon Sep 17 00:00:00 2001 From: Andrea Tosatto Date: Tue, 26 Jan 2021 23:29:32 +0000 Subject: [PATCH 4/7] Address golint warnings Kubernetes-commit: 675cefa1d15cadc5d1772d0ced16a3e843488347 --- go.mod | 14 ++++++++------ go.sum | 32 +++++++++++++------------------- transport/round_trippers.go | 2 +- transport/round_trippers_test.go | 14 +++++++------- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 36de8d5c..7c9d4c77 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/Azure/go-autorest/autorest/adal v0.9.5 github.com/davecgh/go-spew v1.1.1 github.com/evanphx/json-patch v4.9.0+incompatible - github.com/gogo/protobuf v1.3.2 + github.com/gogo/protobuf v1.3.1 github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e github.com/golang/protobuf v1.4.3 github.com/google/go-cmp v0.5.2 @@ -26,14 +26,16 @@ require ( golang.org/x/net v0.0.0-20201110031124-69a78807bb2b golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e - k8s.io/api v0.0.0-20210202201024-9f65ac4826aa - k8s.io/apimachinery v0.0.0-20210202200849-9e39a13d2cab - k8s.io/klog/v2 v2.5.0 + k8s.io/api v0.0.0 + k8s.io/apimachinery v0.0.0 + k8s.io/klog v1.0.0 + k8s.io/klog/v2 v2.4.0 k8s.io/utils v0.0.0-20201110183641-67b214c5f920 sigs.k8s.io/yaml v1.2.0 ) replace ( - k8s.io/api => k8s.io/api v0.0.0-20210202201024-9f65ac4826aa - k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210202200849-9e39a13d2cab + k8s.io/api => ../api + k8s.io/apimachinery => ../apimachinery + k8s.io/client-go => ../client-go ) diff --git a/go.sum b/go.sum index 21e325f8..bd5d4aac 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QLSV/BsnenAOcDXdX4cMv4wP0B/5QbPg= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= @@ -68,9 +70,10 @@ github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2H github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= -github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc= -github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= +github.com/go-logr/logr v0.2.0 h1:QvGt2nLcHH0WK9orKa+ppBPAxREcH364nPUedEpK0TY= +github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= @@ -78,8 +81,8 @@ github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL9 github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 h1:5ZkaAPbicIKTF2I64qf5Fh8Aa83Q/dnOafMYV0OMwjA= @@ -133,7 +136,6 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gnostic v0.4.1 h1:DLJCy1n/vrD4HPjOvYcT8aYQXpPIzoRZONaYwyycI+I= github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -149,7 +151,7 @@ github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= @@ -161,8 +163,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= -github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -197,8 +197,6 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -241,7 +239,6 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -264,7 +261,6 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -280,7 +276,6 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -320,6 +315,7 @@ golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s= golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -350,8 +346,6 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -433,12 +427,12 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/api v0.0.0-20210202201024-9f65ac4826aa/go.mod h1:3jofhj44aajVJZcPa3+rvEFZRe4nr1NNQgw5HtNky0M= -k8s.io/apimachinery v0.0.0-20210202200849-9e39a13d2cab/go.mod h1:usCLrfBNFPxV+npBFCgIy08RBKPAhZQyIzwcvPV2eh8= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= +k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= +k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= -k8s.io/klog/v2 v2.5.0 h1:8mOnjf1RmUPW6KRqQCfYSZq/K20Unmp3IhuZUhxl8KI= -k8s.io/klog/v2 v2.5.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec= +k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= +k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd h1:sOHNzJIkytDF6qadMNKhhDRpc6ODik8lVC6nOur7B2c= k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM= k8s.io/utils v0.0.0-20201110183641-67b214c5f920 h1:CbnUZsM497iRC5QMVkHwyl8s2tB3g7yaSHkYPkpgelw= diff --git a/transport/round_trippers.go b/transport/round_trippers.go index 25e26f60..554ff399 100644 --- a/transport/round_trippers.go +++ b/transport/round_trippers.go @@ -378,7 +378,7 @@ const ( // NewDebuggingRoundTripper allows to display in the logs output debug information // on the API requests performed by the client. -func NewDebuggingRoundTripper(rt http.RoundTripper, levels ...DebugLevel) *debuggingRoundTripper { +func NewDebuggingRoundTripper(rt http.RoundTripper, levels ...DebugLevel) http.RoundTripper { drt := &debuggingRoundTripper{ delegatedRoundTripper: rt, levels: make(map[DebugLevel]bool, len(levels)), diff --git a/transport/round_trippers_test.go b/transport/round_trippers_test.go index c55ac0f8..81571226 100644 --- a/transport/round_trippers_test.go +++ b/transport/round_trippers_test.go @@ -419,7 +419,7 @@ func TestHeaderEscapeRoundTrip(t *testing.T) { func TestDebuggingRoundTripper(t *testing.T) { t.Parallel() - rawUrl := "https://127.0.0.1:12345/api/v1/pods?limit=500" + rawURL := "https://127.0.0.1:12345/api/v1/pods?limit=500" req := &http.Request{ Method: http.MethodGet, Header: map[string][]string{ @@ -440,7 +440,7 @@ func TestDebuggingRoundTripper(t *testing.T) { }{ { levels: []DebugLevel{DebugJustURL}, - expectedOutputLines: []string{fmt.Sprintf("%s %s", req.Method, rawUrl)}, + expectedOutputLines: []string{fmt.Sprintf("%s %s", req.Method, rawURL)}, }, { levels: []DebugLevel{DebugRequestHeaders}, @@ -471,7 +471,7 @@ func TestDebuggingRoundTripper(t *testing.T) { }, { levels: []DebugLevel{DebugURLTiming}, - expectedOutputLines: []string{fmt.Sprintf("%s %s %s", req.Method, rawUrl, res.Status)}, + expectedOutputLines: []string{fmt.Sprintf("%s %s %s", req.Method, rawURL, res.Status)}, }, { levels: []DebugLevel{DebugResponseStatus}, @@ -489,12 +489,12 @@ func TestDebuggingRoundTripper(t *testing.T) { klog.SetOutput(tmpWriteBuffer) klog.LogToStderr(false) - // parse rawUrl - parsedUrl, err := url.Parse(rawUrl) + // parse rawURL + parsedURL, err := url.Parse(rawURL) if err != nil { - t.Fatalf("url.Parse(%q) returned error: %v", rawUrl, err) + t.Fatalf("url.Parse(%q) returned error: %v", rawURL, err) } - req.URL = parsedUrl + req.URL = parsedURL // execute the round tripper rt := &testRoundTripper{ From 9d369ea084102ded4ef1a076b66b60872657aebb Mon Sep 17 00:00:00 2001 From: Andrea Tosatto Date: Tue, 26 Jan 2021 23:31:42 +0000 Subject: [PATCH 5/7] Update bazel BUILD file Kubernetes-commit: bdd2da5c7eb98e4f7ce02977793b7268c717d98a From e87f4d8d196e8491b03f4005bd6512a60492de66 Mon Sep 17 00:00:00 2001 From: Andrea Tosatto Date: Tue, 26 Jan 2021 23:49:25 +0000 Subject: [PATCH 6/7] Remove unexpected updates to go.mod and go.sum Kubernetes-commit: 961fa25dd4468cad40274258c701e5d48fa02c5e --- go.mod | 1 - go.sum | 2 -- transport/round_trippers.go | 2 +- transport/round_trippers_test.go | 3 ++- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 7c9d4c77..ce0f92d9 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,6 @@ require ( golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e k8s.io/api v0.0.0 k8s.io/apimachinery v0.0.0 - k8s.io/klog v1.0.0 k8s.io/klog/v2 v2.4.0 k8s.io/utils v0.0.0-20201110183641-67b214c5f920 sigs.k8s.io/yaml v1.2.0 diff --git a/go.sum b/go.sum index bd5d4aac..3b41835e 100644 --- a/go.sum +++ b/go.sum @@ -428,8 +428,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= -k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= diff --git a/transport/round_trippers.go b/transport/round_trippers.go index 554ff399..785d3b2e 100644 --- a/transport/round_trippers.go +++ b/transport/round_trippers.go @@ -23,8 +23,8 @@ import ( "time" "golang.org/x/oauth2" - "k8s.io/klog/v2" + "k8s.io/klog/v2" utilnet "k8s.io/apimachinery/pkg/util/net" ) diff --git a/transport/round_trippers_test.go b/transport/round_trippers_test.go index 81571226..c4185248 100644 --- a/transport/round_trippers_test.go +++ b/transport/round_trippers_test.go @@ -19,12 +19,13 @@ package transport import ( "bytes" "fmt" - "k8s.io/klog/v2" "net/http" "net/url" "reflect" "strings" "testing" + + "k8s.io/klog/v2" ) type testRoundTripper struct { From ef84e47785842d8108c5bd8f20be5ec6a2a9ddcc Mon Sep 17 00:00:00 2001 From: Andrea Tosatto Date: Wed, 27 Jan 2021 00:08:07 +0000 Subject: [PATCH 7/7] Re-run gofmt against staging/src/k8s.io/client-go/transport/ Kubernetes-commit: 1449af17555eb5148d11556ee205c42b83821af0 --- transport/round_trippers.go | 2 +- transport/round_trippers_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/transport/round_trippers.go b/transport/round_trippers.go index 785d3b2e..cd0a4455 100644 --- a/transport/round_trippers.go +++ b/transport/round_trippers.go @@ -24,8 +24,8 @@ import ( "golang.org/x/oauth2" - "k8s.io/klog/v2" utilnet "k8s.io/apimachinery/pkg/util/net" + "k8s.io/klog/v2" ) // HTTPWrappersForConfig wraps a round tripper with any relevant layered diff --git a/transport/round_trippers_test.go b/transport/round_trippers_test.go index c4185248..10f7132c 100644 --- a/transport/round_trippers_test.go +++ b/transport/round_trippers_test.go @@ -424,15 +424,15 @@ func TestDebuggingRoundTripper(t *testing.T) { req := &http.Request{ Method: http.MethodGet, Header: map[string][]string{ - "Authorization": []string{"bearer secretauthtoken"}, - "X-Test-Request": []string{"test"}, + "Authorization": {"bearer secretauthtoken"}, + "X-Test-Request": {"test"}, }, } res := &http.Response{ Status: "OK", StatusCode: http.StatusOK, Header: map[string][]string{ - "X-Test-Response": []string{"test"}, + "X-Test-Response": {"test"}, }, } tcs := []struct {