Commit Graph

103 Commits

Author SHA1 Message Date
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
Davanum Srinivas
00496caa6a Log more details when we get the 0-length error
Change-Id: I9733521a3afd91c54c19fe08d0622df4187c0c0c

Kubernetes-commit: f92ee4e4e42c260780b64cb3bd2a153947b49c50
2019-01-01 17:50:15 -05:00
xichengliudui
c2d0ac0df3 Delete some redundant code
Delete some redundant code

Kubernetes-commit: 9a25d46e8b5c079d97b909bb6e0bc1c1399c3e8c
2018-11-13 03:28:31 -05:00
Davanum Srinivas
74cd8bbeee Move from glog to klog
- Move from the old github.com/golang/glog to k8s.io/klog
- klog as explicit InitFlags() so we add them as necessary
- we update the other repositories that we vendor that made a similar
change from glog to klog
  * github.com/kubernetes/repo-infra
  * k8s.io/gengo/
  * k8s.io/kube-openapi/
  * github.com/google/cadvisor
- Entirely remove all references to glog
- Fix some tests by explicit InitFlags in their init() methods

Change-Id: I92db545ff36fcec83afe98f550c9e630098b3135

Kubernetes-commit: 954996e231074dc7429f7be1256a579bedd8344c
2018-11-09 13:49:10 -05:00
Wenjia Zhang
13b096589c Rewrite finalURLTemplate used only for metrics because of dynamic client change
Kubernetes-commit: 99248b8fe1fe1c28188657d811dc7baf8cd12982
2018-09-14 11:31:21 -07:00
W. Trevor King
045dbe7ac1 client-go/rest: Fix "segments segment" comment typo
The typo landed with SubResource in adb75e1f (generated staging area,
2016-08-06, kubernetes/kubernetes#29147).

Kubernetes-commit: e42aab6430cbc9d14891e9aaada9ec8becf62273
2018-08-02 08:30:44 -07:00
Cao Shufeng
29c058197f fix print format string
Kubernetes-commit: 199a6eba8877e8908753f9977e18360660f7e072
2018-07-04 15:55:15 +08:00
David Eads
2e1683e1a1 add easy to use dynamic client
Kubernetes-commit: 3632037e600d82a954c05ecd4f9cb6f1ca93d41c
2018-04-24 13:41:40 -04:00
Maciej Szulik
d1f4ecc28d Set a default request timeout for discovery client
Kubernetes-commit: 7bd48a7e2325381cb777d0ea1ff89b2ecece23b6
2018-04-17 16:58:38 +02:00
Maciej Szulik
a4f6f78b29 Allow passing request-timeout from NewRequest all the way down to actual request
Kubernetes-commit: 7da1002091f026d4a58c1639dd70e1310b1d8991
2017-08-21 20:47:39 +02:00
juanvallejo
f1ca0e5f1d add rest/request backoffMgr and throttle setters
Kubernetes-commit: 427884aa3969a2a5826b198854602cc62a0fff32
2017-11-16 13:06:43 -05:00
Antoine Pelisse
fba05540b8 Update truncateBody to not truncate with high level
And add a unit-tests to verify that it works properly.

Kubernetes-commit: a63ecc4a92b28eb12bde1b321c8d6ce8e3ae4191
2017-10-30 10:20:46 -07:00
Antoine Pelisse
90239c1304 client-go: Truncate body based on Verbosity level
Kubernetes-commit: b4304f8e79f8227fc7841ecc7cb80b94cbbd493d
2017-09-14 17:09:07 -07:00
ymqytw
f62736c05e return reasonable error when connection closed
Kubernetes-commit: 4de18dec2ba284657c89f7b6e1074385dc1d1baf
2017-09-01 16:19:32 +00:00
Simo Sorce
ada55fe32f Extend SetHeader Requests method ito accept multiple values
This allows to set headers that are multivalued directly.
The headers variable is not directly accessible and currently
SetHeaders allows to set only one value.

Signed-off-by: Simo Sorce <simo@redhat.com>

Kubernetes-commit: 1f44ccd01c9cea7870a4018b29fa8eabe58a90f6
2017-08-29 12:52:26 +00:00
Clayton Coleman
0103f0d62a Update generic errors with the new http package codes
All of these errors are now part of the standard HTTP method. Formalize
those into our error types and remove duplication and unclear
separation.

Kubernetes-commit: d3be1ac92eb644e284915a55fe67942c33f88d4c
2017-08-29 12:50:52 +00:00
zhangxiaoyu-zidif
fe0b3c2590 Fix comment of request.go
Kubernetes-commit: c302a72eb943debb5a24e77c709cac56bac78fb7
2017-08-29 12:49:48 +00:00
Clayton Coleman
88f7fb8192 Remove Kube specific api constructs from restclient
All callers must use VersionedParameters, which no longer has special
behavior for Kube resources.

Kubernetes-commit: 112e0fa9da069d147fffe5bd0638ebce4a9bba42
2017-07-19 03:39:07 +00:00
Clayton Coleman
526a4ea159 Remove "special" restclient parameters
Kubernetes-commit: f0e11c5b09abe46dd67a4f5e6f8bce9696888cee
2017-07-19 03:39:07 +00:00
Chao Xu
d82cfb70dd run hack/update-staging-client-go, somehow we copied listers/<authn,authz,imagepolicy>
Kubernetes-commit: ffe74d1fe749b5887711f70af24e1375856f2520
2017-06-28 00:06:44 +00:00
Chao Xu
1e9caa8e14 run root-rewrite-import-client-go-api-types
Kubernetes-commit: f2d3220a11111f86b2f481e70e3c1ca4f5896f44
2017-06-28 00:06:44 +00:00
Daniel Smith
38cb1a951d Implement dynamic admission webhooks
Also fix a bug in rest client

Kubernetes-commit: d6e1140b5d3c5c9d8696b7ccda0a5f92f36033df
2017-06-13 20:38:46 +00:00
Timothy St. Clair
656cf48fd6 Level sets dependency graph to consume etcd 3.1.5
Kubernetes-commit: 93c051e28fc43ed35cb9074f6de5a8c4de799eb2
2017-04-12 20:28:20 +00:00
fate-grand-order
7f5f33cf4b fix misspell "underlying" in request.go
Kubernetes-commit: 122ea2551202e5edb3e840a97518170e060c484f
2017-04-06 20:28:15 +00:00
Jordan Liggitt
012d8620e3 Only set a groupresource on errors if a resource was specified
Kubernetes-commit: 69510237598df78c456ebb36a312f86c8a2d2e37
2017-03-18 19:50:23 +00:00
Kubernetes Publisher
fcdf37233b published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is baaaf26609565b4299008018486ec75fb30903eb
2017-01-25 15:19:43 +00:00
Kubernetes Publisher
0eb5431cb7 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 8d5227bb2e05e01031ace81fa6611a13f598278e
2017-01-21 15:19:42 +00:00
Kubernetes Publisher
8fa0506b26 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is d9467519245c3858ac58c5fa91ec9e5b16c1f507
2017-01-18 15:19:42 +00:00
Kubernetes Publisher
204f12b1f3 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 616038db1b0d1e852b4a3d10c8c512a052f91fba
2017-01-14 15:19:47 +00:00
Kubernetes Publisher
5fe6fc56cb published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 5b2823adb9a8777f7819884fa79a6e1daa26b9c2
2016-12-17 15:19:41 +00:00
Kubernetes Publisher
243d8a9cb6 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is d8c925319a23f6bbf865baa53ae23f48f60dd73b
2016-12-11 15:19:40 +00:00
Kubernetes Publisher
124670e99d published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 81d788dd6e0748e5d53a62c16d933c5f7a0718af
2016-12-04 11:39:55 +00:00
Kubernetes Publisher
5d8c36c93c published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 124fb610dcbd445fa710da67508ac6d5b822f61d
2016-11-24 08:15:51 +00:00
Kubernetes Publisher
ae6775eeec published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 1bc5b822cd566321c115d4ebac5d97cfd347d687
2016-11-11 03:39:04 +00:00