Commit Graph

86 Commits

Author SHA1 Message Date
Michal Fojtik
0cde78477a client-go: add DNS resolver latency metrics (#115357)
* client-go: add DNS resolver latency metrics

* client-go: add locking to DNS latency metrics

* client-go: add locking for whole DNSStart and DNSDone

Signed-off-by: Vu Dinh <vudinh@outlook.com>

* Fix a mismatched ctx on the request

Signed-off-by: Vu Dinh <vudinh@outlook.com>

* Clean up request code and fix comments

Signed-off-by: Vu Dinh <vudinh@outlook.com>

---------

Signed-off-by: Vu Dinh <vudinh@outlook.com>
Co-authored-by: Vu Dinh <vudinh@outlook.com>

Kubernetes-commit: 1c7e87cff27aa009488a9d55342220e223d5c146
2023-06-28 22:56:45 +02:00
Stephen Kitt
22e2a9b6b1 client-go: add an Error() function on Request
Requests can accumulate errors with no obvious indication, e.g. if
their primary purpose is to construct a URL: URL() itself doesn't
return an error if r.err is non-nil.

Instead of changing URL() to return an error, which has quite a large
impact, add an Error() function and indicate on URL() that it should
be checked.

Signed-off-by: Stephen Kitt <skitt@redhat.com>

Kubernetes-commit: f69c1c47463ff70ad61adf6f38c4d5b7373e9d0a
2023-02-10 14:44:07 +01:00
Abu Kashem
d2388d199c client-go: add metric to count retries
Kubernetes-commit: b6c369f5c90bbef8058b3d44949f4e815dd6607f
2022-02-28 12:22:09 -05:00
Jordan Liggitt
e2f402cda3 Limit request retrying to []byte request bodies
Kubernetes-commit: 69fad419a7666ac416307de4c3ee88c7e61b94db
2022-11-15 17:47:35 -05:00
Sean Sullivan
8ff4970e81 Get response content-type
Kubernetes-commit: 4ca128d71aa94653927b0e529b746cb7428563b1
2022-11-02 00:03:24 +00:00
André Martins
e9d4627252 client-go/rest: check if url is nil to prevent nil pointer dereference
Signed-off-by: André Martins <aanm90@gmail.com>

Kubernetes-commit: 94e7b2b8fdb4028b8b9d10ce57b9b33df146beb7
2022-08-09 14:19:01 +02:00
André Martins
c501ee0eba Revert "client-go: remove no longer used finalURLTemplate"
The functionality provided by the finalURLTemplate is still used by
certain external projects to track the request latency for requests
performed to kube-apiserver.

Using a template of the URL, instead of the URL itself, prevents the
explosion of label cardinality in exposed metrics since it aggregates
the URLs in a way that common URLs requests are reported as being the
same.

This reverts commit bebf5a608f68523fc430a44f6db26b16022dc862.

Signed-off-by: André Martins <aanm90@gmail.com>

Kubernetes-commit: f8f190cdd2fa76296f8b1b019ac77128b5d40b79
2022-08-08 23:27:45 +02:00
inosato
27de641f75 Remove ioutil from client-go
Signed-off-by: inosato <si17_21@yahoo.co.jp>

Kubernetes-commit: 88dfa51b6003c90e8f0a0508939a1d79950a40df
2022-07-30 20:54:41 +09:00
Davanum Srinivas
2a6c116e40 Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: a9593d634c6a053848413e600dadbf974627515f
2022-07-19 20:54:13 -04:00
saltbo
7c3fa18b11 fix: update the typo code comment
Kubernetes-commit: d2bab218ddef3fc3f444038420dd500c0e8bc068
2022-07-13 10:16:51 +08:00
Abu Kashem
d8531f5ff0 client-go: make retry in Request thread safe
Kubernetes-commit: 6618b8ef7c0b552839555d4578b64427d20524ef
2022-03-29 13:09:26 -04:00
Abu Kashem
01ab7fb211 client-go: reset request body after response is read and closed
This commit refactors the retry logic to include resetting the
request body. The reset logic will be called iff it is not the
first attempt. This refactor is nescessary mainly because now
as per the retry logic, we always ensure that the request body
is reset *after* the response body is *fully* read and closed
in order to reuse the same TCP connection.

Previously, the reset of the request body and the call to read
and close the response body were not in the right order, which
leads to race conditions.

This commit also adds a test that verifies the order in which
the function calls are made to ensure that we seek only after
the response body is closed.

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>

Kubernetes-commit: 68c8c458ee8f6629eef806c48c1a776dedad3ec4
2022-03-28 20:40:49 -04:00
Abu Kashem
7c9347d386 client-go: wrap error from previous attempt to provide more context
Kubernetes-commit: 868b5a31d382b325f49e1b831e6b094282d50cc7
2022-03-14 18:57:56 -04:00
Patrick Ohly
9175c47d17 enhance and fix log calls
Some of these changes are cosmetic (repeatedly calling klog.V instead of
reusing the result), others address real issues:

- Logging a message only above a certain verbosity threshold without
  recording that verbosity level (if klog.V().Enabled() { klog.Info... }):
  this matters when using a logging backend which records the verbosity
  level.

- Passing a format string with parameters to a logging function that
  doesn't do string formatting.

All of these locations where found by the enhanced logcheck tool from
https://github.com/kubernetes/klog/pull/297.

In some cases it reports false positives, but those can be suppressed with
source code comments.

Kubernetes-commit: edffc700a43e610f641907290a5152ca593bad79
2022-02-16 12:17:47 +01:00
Abu Kashem
147848c452 client-go: chain the error returned by rate limiter
Kubernetes-commit: 6acbe7e6452a44057768c61909da2d5b7c878159
2022-02-24 17:28:01 -05:00
Abu Kashem
34f3aff43e client-go: refactor retry logic for backoff, rate limiter and metric
Kubernetes-commit: cecc563d3b9a9438cd3e6ae1576baa0a36f2d843
2022-02-17 16:57:45 -05:00
Antonio Ojea
e2c62ff0c0 client-go: add request and response size metrics
Get metrics for the request and response  size, so we can correlate latency
and size on a request, otherwise we could get confused because we don't know if the
network is slow or just the request size huge.

Kubernetes-commit: 64d9d0585f6dbc9266f31b6d0f795d6c0421495e
2021-12-09 12:11:01 +01:00
Antonio Ojea
83bb1e3ff2 client-go: remove no longer used finalURLTemplate
The restclient metrics were updated to track only the host field of the
url, the finalURLTemplate is not longer needed, its only goal was to
replace name and namespace in the path to avoid cardinality.

Kubernetes-commit: bebf5a608f68523fc430a44f6db26b16022dc862
2022-02-17 16:51:55 +01:00
wojtekt
608b5216df Migrate to k8s.io/utils/clock in client-go - part 1
Kubernetes-commit: 950f655bdd19c5af275846cf1940d767a5ec0115
2021-09-15 10:58:56 +02:00
Andrey Smirnov
c8b4c1e4bd fix: properly wrap errors when reading response body in the client
As `%v` doesn't allow error unwrapping, checks like `errors.Is` are not
working properly.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>

Kubernetes-commit: 6c0463bd2b616d0f22f47905bb26d66fa3b04e37
2021-06-18 23:35:31 +03:00
Abu Kashem
bbd71da939 Revert "Merge pull request #102581 from liggitt/revert-watch-retry"
This reverts commit 5a59a43957c6743995dac67fdda42bf8e0a9ca77, reversing
changes made to 81b9789eaa7bc067f417b5e74d5695dd6dd88a46.

Kubernetes-commit: 892d4fabb845e2461e3655aa414beb6ac322fc99
2021-06-04 13:45:26 -04:00
Jordan Liggitt
5ba99a7f80 Revert "client-go: add retry logic for Watch and Stream"
This reverts commit 607d3819498e64d969407c3d7cbbb8f53d98f0d4.

Kubernetes-commit: e35af41a1236943b6510a25cfb8cb47855aaa16e
2021-06-04 01:11:25 -04:00
Abu Kashem
55854fadb1 client-go: add retry logic for Watch and Stream
Kubernetes-commit: 607d3819498e64d969407c3d7cbbb8f53d98f0d4
2021-05-18 15:15:28 -04:00
Abu Kashem
239ec44d74 client-go: refactor retry logic so it can be reused
Kubernetes-commit: 5fdf196b4e9bbba036a43f4c3b5d9ed8af1672cc
2021-05-20 16:54:19 -04:00
Ivan Sim
c8704063ca Fix the missing format specifier error in log output
The message argument is mistakenly used as the format specifier, if it
contains the special '%' characters. This causes many '[%d|%s](MISSING)'
errors in the API server logs.

Signed-off-by: Ivan Sim <isim@redhat.com>

Kubernetes-commit: b1d0d401875b2076e73183f8468ecb95c3fe61aa
2021-04-15 15:26:57 -07:00
yoyinzyc
6a42ca30ba add context to restclient metrics
Kubernetes-commit: 69d40a1de7bc765647d8ef392fe406429fded807
2021-02-04 18:23:26 -08:00
Li Zhijian
bb1d67da92 request.go: correct subresource referencing
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>

Kubernetes-commit: 678e4ebaf6534e9b15fc4cc8602caadbead2e40e
2021-02-18 17:51:55 +08:00
Abu Kashem
d1fdbcd4dc client-go: add more context to request throttle message
Kubernetes-commit: bc66d3d137d3600b117be390ccb253a9dbcde25e
2021-02-12 14:39:44 -05:00
André Martins
2396a52017 client-go/rest: fix finalURLTemplate for url base == "/"
In some environments, where url base is "/", it can cause all paths to
be presented in metrics with "{prefix}" as `groupIndex` is with the wrong
index. To fix the behavior in such environments, it was added a
conditional branch to check if the URL base is "/" and, thus, print the
metrics with the correct path, for example "api/v1/nodes/{name}" instead
of "{prefix}".

Fixes: 99248b8fe1fe ("Rewrite finalURLTemplate used only for metrics because of dynamic client change")
Signed-off-by: André Martins <aanm90@gmail.com>

Kubernetes-commit: c039b02fa7281fc061455e23b6530ed8b4d19645
2019-02-21 20:25:36 +01:00
lihaowei
abfce0f8c3 Format Codes
Chore: Correct words and format codes

Revert three changes

Revert 1 change

Revert again

Revert 2 changes

Kubernetes-commit: af7cf4abc6bfeb0d2cfaca76097cf7a0603c4495
2020-08-08 13:27:28 +08:00
Jordan Liggitt
75f9ee62c1 client-go: extract warning headers from API responses
Kubernetes-commit: b1098bd0d53658bfb945e485683d543ab7dc73ba
2019-01-17 11:35:07 -05:00
Davanum Srinivas
75fea27a27 switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 442a69c3bdf6fe8e525b05887e57d89db1e2f3a5
2020-04-17 15:25:06 -04:00
Jordan Liggitt
33c1f9f2a4 Fix client watch reestablishment handling of client-side timeouts
Kubernetes-commit: 343c1e7636fe5c75cdd378c0b170b26935806de5
2020-03-30 10:36:01 -04:00
yue9944882
3e9d5317f0 make client-side max-retry override'ble
Kubernetes-commit: f373697c64e9dc5a6618e1d360ad9a51bc8b79c7
2020-03-27 16:15:46 +08:00
Jack Kleeman
a493c8da9a Add ReloadCertFromDisk flag to rest.Config and to kubeconfig which allows the provided client certificate files to be reloaded from disk (currently on every use)
Close outbound connections when using a cert callback and certificates rotate. This means that we won't get into a situation where we have open TLS connections using expires certs, which would get unauthorized errors at the apiserver

Attempt to retrieve a new certificate if open connections near expiry, to prevent the case where the cert expires but we haven't yet opened a new TLS connection and so GetClientCertificate hasn't been called.

Move certificate rotation logic to a separate function

Rely on generic transport approach to handle closing TLS client connections in exec plugin; no need to use a custom dialer as this is now the default behaviour of the transport when faced with a cert callback. As a result of handling this case, it is now safe to apply the transport approach even in cases where there is a custom Dialer (this will not affect kubelet connrotation behaviour, because that uses a custom transport, not just a dialer).

Check expiry of the full TLS certificate chain that will be presented, not only the leaf. Only do this check when the certificate actually rotates. Start the certificate as a zero value, not nil, so that we don't see a rotation when there is in fact no client certificate

Drain the timer when we first initialize it, to prevent immediate rotation. Additionally, calling Stop() on the timer isn't necessary.

Don't close connections on the first 'rotation'

Remove RotateCertFromDisk and RotateClientCertFromDisk flags.

Instead simply default to rotating certificates from disk whenever files are exclusively provided.

Add integration test for client certificate rotation

Simplify logic; rotate every 5 mins

Instead of trying to be clever and checking for rotation just before an
expiry, let's match the logic of the new apiserver cert rotation logic
as much as possible. We write a controller that checks for rotation
every 5 mins. We also check on every new connection.

Respond to review

Fix kubelet certificate rotation logic

The kubelet rotation logic seems to be broken because it expects its
cert files to end up as cert data whereas in fact they end up as a
callback. We should just call the tlsConfig GetCertificate callback
as this obtains a current cert even in cases where a static cert is
provided, and check that for validity.

Later on we can refactor all of the kubelet logic so that all it does is
write files to disk, and the cert rotation work does the rest.

Only read certificates once a second at most

Respond to review

1) Don't blat the cert file names
2) Make it more obvious where we have a neverstop
3) Naming
4) Verbosity

Avoid cache busting

Use filenames as cache keys when rotation is enabled, and add the
rotation later in the creation of the transport.

Caller should start the rotating dialer

Add continuous request rotation test

Rebase: use context in List/Watch

Swap goroutine around

Retry GETs on net.IsProbableEOF

Refactor certRotatingDialer

For simplicity, don't affect cert callbacks

To reduce change surface, lets not try to handle the case of a changing
GetCert callback in this PR. Reverting this commit should be sufficient
to handle that case in a later PR.

This PR will focus only on rotating certificate and key files.
Therefore, we don't need to modify the exec auth plugin.

Fix copyright year

Kubernetes-commit: 929b1559a0b855d996257ab3ad5364605edc253d
2019-06-14 22:08:58 +01:00
jennybuckley
2d3138825e Improve rate limiter latency logging and metrics
Kubernetes-commit: 2bcf99f05fdc47fb4bc3601b9134408483f59773
2020-02-13 13:32:12 -08:00
Michal Fojtik
3431a996fa rest: remove connection refused from the list of retriable errors
Kubernetes-commit: 0dfe0c793b5b85bd85cec7b77679ba78c1617357
2020-02-18 14:44:04 +01:00
jennybuckley
9ee80cfbdc Log when client side rate limiter latency is very high
Kubernetes-commit: 82a68be304338f0bee9ed9bdc99a7acc1895e102
2020-01-31 16:17:22 -08:00
Mike Danese
ae9f6b2601 update rest.Request signatures
Kubernetes-commit: 510aa1b432499f752fbacb2abf7e19f73311cdad
2020-01-27 17:54:13 -08:00
Mike Danese
5f8ab2bf68 various context related cleanups to rest.Request
* Move all usage of r.ctx to the beginning of Do, DoRaw, Stream, Watch
* Move tryThrottle from Do and DoRaw into request()
* Make request() and tryThrottle take a context
* In request(), remove the timeout context setting out of the loop

These changes should be entirely behavior preserving.

Kubernetes-commit: ed48ed0122c7289f458a6bc3ac616319d5c17e91
2020-01-27 19:52:47 -08:00
Mike Danese
c4a6de2f33 various context related cleanups to rest.Request
* Move all usage of r.ctx to the beginning of Do, DoRaw, Stream, Watch
* Move tryThrottle from Do and DoRaw into request()
* Make request() and tryThrottle take a context
* In request(), remove the timeout context setting out of the loop

These changes should be entirely behavior preserving.

Kubernetes-commit: d95ed2c8470158256466fb24728e63ac3afe0899
2020-01-27 19:52:47 -08:00
Robert Krawitz
c02e303b36 Report api request throttling at v=3
Kubernetes-commit: e7cc2c2d280f319b78462a37d32c5c7f1e6e5567
2019-07-26 12:59:34 -04:00
Michal Fojtik
7c85ddb6ae client-go: add connection refused to list of transient errors
Kubernetes-commit: 9aa68a5cf4b4195e5dfa9749380bc8d29be03522
2019-11-20 17:30:05 +01:00
Clayton Coleman
9bbcc2938d Always negotiate a decoder using ClientNegotiator
This commit performs two refactors and fixes a bug.

Refactor 1 changes the signature of Request to take a RESTClient, which
removes the extra copy of everything on RESTClient from Request. A pair
of optional constructors are added for testing. The major functional
change is that Request no longer has the shim HTTPClient interface and
so some test cases change slightly because we are now going through
http.Client code paths instead of direct to our test stubs.

Refactor 2 changes the signature of RESTClient to take a
ClientContentConfig instead of ContentConfig - the primary difference
being that ClientContentConfig uses ClientNegotiator instead of
NegotiatedSerializer and the old Serializers type. We also collapse
some redundancies (like the rate limiter can be created outside the
constructor).

The bug fix is to negotiate the streaming content type on a Watch()
like we do for requests. We stop caching the decoder and simply
resolve it on the request. We also clean up the dynamic client
and remove the extra WatchSpecificVersions() method by providing
a properly wrapped dynamic client.

Kubernetes-commit: 3b780c64b89606f4e6b21f48fb9c305d5998b9e5
2019-11-10 16:52:08 -05:00
Ricardo Maraschini
e6a1dc4b13 Creating function for preflight check.
Migrated code that checks for common programmer errors to a separated
function and added test coverage for it. Wrong comment stating that a
typed error is returned was also removed.

Kubernetes-commit: ad5fafd6ade2838098890a4e7727c8e347686867
2019-09-12 19:22:46 +02:00
Sukeesh
94daee0164 Cleanup: Audit log and error capitalization
Kubernetes-commit: 346fdbccf0ac06ab3fa0e51ab3b92fdc041bb4cc
2019-06-30 11:56:27 +09:00
David Eads
4747a4bccd make kubectl --raw consistent for create, update, get, delete
Kubernetes-commit: 09c55bd1172e9b044762957efeae2c34de145bef
2019-07-03 08:27:19 -04:00
chenjun.cj
8f99f83432 flowcontrol context aware and fix request may hang issue
Kubernetes-commit: ce8805f95fcf6540397eaa60b8d84db752f05eea
2019-06-21 12:17:46 +08:00
Clayton Coleman
cd12199def Report a watch error instead of eating it when we can't decode
Clients are required to handle watch events of type ERROR, so instead
of eating the decoding error we should pass it on to the client. Use
NewGenericServerError with isUnexpectedResponse to indicate that we
didn't get the bytes from the server we were expecting. For watch, the
415 error code is roughly correct and we will return an error to the
client that makes debugging a failure in either server watch or client
machinery much easier.

We do not alter the behavior when it appears the response is an EOF
or other disconnection.

Kubernetes-commit: 89620d5667adec6c132b2713b79efb1dd2391723
2019-02-11 17:34:20 -05:00
Clayton Coleman
3d7e523148 Avoid using %#v for errors when %T or %s would be more accurate
`%#v` may have significant performance costs in frequently invoked code.

Kubernetes-commit: ecd43f13cfdb18cec71c74fa4c1e202a35341498
2019-03-21 22:53:43 -04:00