242 Commits

Author SHA1 Message Date
Jordan Liggitt
61471be615 Deflake ThrottledLogger test
Kubernetes-commit: c84df5d66ea8d949374b67c5205b9869b984ea84
2020-11-19 13:59:27 -05:00
Chao Xu
8dde295de4 Add a unit test testing the HTTP/2 health check help the REST client
detects broken TCP connections.

Kubernetes-commit: ba7b1f7a89ffed78115ab0229b7504d05f6c7d48
2020-10-29 23:03:14 -07:00
Marek Siarkowicz
e93788d387 Add datapolicy tags to staging/src/k8s.io/client-go/
Kubernetes-commit: e29c568c4a9cd45d15665345aa015e21bcff52dd
2020-10-29 18:15:52 +01: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
Andrew Keesler
a7ba87c612 exec credential provider: ProvideClusterInfo and kubeconfig shadow
- The main idea here is that we want to 1) prevent potentially large CA
  bundles from being set in an exec plugin's environment and 2) ensure
  that the exec plugin is getting everything it needs in order to talk to
  a cluster.
- Avoid breaking existing manual declarations of rest.Config instances by
  moving exec Cluster to kubeconfig internal type.
- Use client.authentication.k8s.io/exec to qualify exec cluster extension.
- Deep copy the exec Cluster.Config when we copy a rest.Config.

Signed-off-by: Andrew Keesler <akeesler@vmware.com>

Kubernetes-commit: c4299d15d5289768808034676858e76a177eeae5
2020-10-29 13:38:42 -04:00
Monis Khan
9e147f192f exec credential provider: wire in cluster info
Signed-off-by: Monis Khan <mok@vmware.com>

Kubernetes-commit: f97422c8bd57692f5a1a3aa6dc6abc31051ebc82
2020-05-06 01:01:09 -04:00
phillc
8ea16c1919 find . -type f \( -name "*.go" -or -name "*.md" \) -print0 | xargs -0 gsed -i 's/the the /the /g'
Kubernetes-commit: adbc7c2172ea622db7399f41e893063b00ca1a87
2020-09-21 16:37:12 -04:00
Jordan Liggitt
dbb8ed36f1 Improve docs for client-go warning handlers
Kubernetes-commit: b0573d526d5eb171e7e21edd642ffe5c258c37a7
2020-08-29 10:40:33 -04: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
Gaurav Singh
d3f56086aa duplicate iteration variable in go func
Kubernetes-commit: c6ac8ea5f7b4e4a6f4d4895122ab1b613840b199
2020-05-04 21:52:06 -04:00
Gaurav Singh
be961bda71 goroutine: Convert eventType to interface{}
Kubernetes-commit: e3dde36e1410b4c9b49648378b2dea1612f612fb
2020-04-26 11:06:32 -04:00
Gaurav Singh
f74b86b7ea Fix race condition in decoder
Kubernetes-commit: 9027f30aa865f108c827060ef59ac62c9d07002b
2020-04-25 20:35:04 -04: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
Mike Danese
0caa50056a rest.Config: support configuring an explict proxy URL
With support of http, https, and socks5 proxy support. We already
support configuring this via environmnet variables, but this approach
becomes inconvenient dealing with multiple clusters on different
networks, that require different proxies to connect to. Most solutions
require wrapping clients (like kubectl) in bash scripts.

Part of: https://github.com/kubernetes/client-go/issues/351

Kubernetes-commit: f3f666d5f1f6f74a8c948a5c64af993696178244
2019-05-03 13:50:17 -07: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
09009e85ca cleanup req.Context() and ResponseWrapper
Kubernetes-commit: 968adfa99362f733ef82f4aabb34a59dbbd6e56a
2020-01-27 18:52:27 -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
clarklee92
d3a5e5f798 Modify the status code number to HTTP status semantics
Signed-off-by: clarklee92 <clarklee1992@hotmail.com>

Kubernetes-commit: f86f5ee14ef3c8adf9855ce16dcc57beca949719
2019-11-06 00:45:35 +08:00
Bob Killen
dc265f33cf Prune inactive owners from staging/src/k8s.io/client-go/* OWNERS files.
Kubernetes-commit: 3dc01f32eacb4791b248c22f7db9d6dabbec7869
2019-10-12 19:44:19 -04: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
wojtekt
33fd3701cd Implement Encoder.Identifier() method
Kubernetes-commit: cd4215ad8b95773a793f69fc2e8bf93c7ede97aa
2019-08-14 16:23:03 +02:00
Jordan Liggitt
696c159e45 Plumb NextProtos to TLS client config, honor http/2 client preference
Kubernetes-commit: aef05c8dca2c1a9967ebd9a2f67a0bf7fb16f079
2019-08-28 09:55:37 -04:00
Clayton Coleman
40d852a94d Allow gzip compression to be disabled from rest.Config
Golang automatically enables transport level gzip, but local network
clients may wish to disable it for better CPU usage and lower latency
(scheduler, controller-manager). Allow DisableCompression on rest.Config
to modify the underlying transport. This impacts the transport cache,
but it is expected that most clients connecting to the same servers
within a process will have the same compression config.

Kubernetes-commit: dee6de70d0e4ad381bd5de01b6d1fbd4fde004bc
2019-08-02 14:23:33 -04: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
Odin Ugedal
2ee65257e5 Fix file permissions for non executable files
Normal files should have permissions 644 by default,
and does not require the last bit to be
executable

Signed-off-by: Odin Ugedal <odin@ugedal.com>

Kubernetes-commit: 35cb87f9cf71776e99a970dfff751cd29ba7ebfb
2019-06-14 21:04:39 +02:00
wojtekt
deab738de6 Fix client-go request benchmark
Kubernetes-commit: 85763127c0b9399e6c48ec144c4716543a6cbe2d
2019-06-27 17:18:56 +02:00
chenjun.cj
8f99f83432 flowcontrol context aware and fix request may hang issue
Kubernetes-commit: ce8805f95fcf6540397eaa60b8d84db752f05eea
2019-06-21 12:17:46 +08:00
Mike Danese
459cb72bc6 BoundServiceAccountTokenVolume: fix InClusterConfig
Kubernetes-commit: 4198f28855cbda6dac61408fcba6f2d576a9347c
2019-05-14 09:29:16 -07:00
Zhao Yuwei
8d8ad929bb Fix a test file log error
Kubernetes-commit: a0c9d126e416f8b6822c8cc7e732b6e4766124dd
2018-12-27 10:52:34 +08:00
fansong.cfs
94d52886d7 add watch bookmark
Kubernetes-commit: d70edd3d39d4430d71c4b7c9adba8df5ba7f16c8
2019-03-19 18:16:23 +08:00
Clayton Coleman
3da8d3a9fe Use CodecFactory.WithoutConversion() everywhere
Clarifies that requesting no conversion is part of the codec factory, and
future refactors will make the codec factory less opionated about conversion.

Kubernetes-commit: 7f9dfe58f4cbe1e1b9e80f52addff70bac87bed4
2019-04-03 13:24:37 -04:00
Jordan Liggitt
f570226af0 Exclude custom transports when constructing AnonymousClientConfig()
Kubernetes-commit: 05b764dbe3e0f979f1d17293a13bafda688d5951
2019-03-27 09:29:07 -04: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
Justin SB
931e6a04ad Remove executable file permission from OWNERS files
Kubernetes-commit: dd19b923b7c26420af39fcf4eedfa213b236c8d3
2019-01-03 12:18:20 -05:00
Roy Lenferink
94093d2527 Updated OWNERS files to include link to docs
Kubernetes-commit: b43c04452f3b563473b5c2a765d4ac18cc0ff58f
2019-01-30 20:05:00 +01:00
Andrew Lytvynov
420f3f77fb Implement fmt.Stringer on rest.Config to sanitize sensitive fields
It's very easy to add glog.Info(config) calls for debugging (or actual
logging). In some scenarios those configs will carry sensitive tokens
and those tokens will end up in logs or response bodies.
Leaking of those stringified configs compromises the cluster.

Also implement fmt.GoStringer.

Kubernetes-commit: c9ad1d7339b164dfba0846ec49fa4a52474d3e23
2018-11-02 11:39:14 -07:00
Clayton Coleman
615e8e2492 Make wrapping a client transport more pleasant
Properly wrapping a transport can be tricky. Make the normal case
(adding a non-nil transport wrapper to a config) easier with a helper.
Also enforce a rough ordering, which in the future we can use to
simplify the WrapTransport mechanism down into an array of functions
we execute in order and avoid wrapping altogether.

Kubernetes-commit: 1f590e697ef64812620c787720b4b5942027e4a1
2018-12-27 11:47:50 -05:00