Commit Graph

241 Commits

Author SHA1 Message Date
Lukasz Szaszkiewicz
65a2176a48 client-go/rest: rm watchlist
Kubernetes-commit: 6a37976848b43dae9aa82854b5c5d321f148bb0b
2025-06-13 10:48:45 +02:00
Jordan Liggitt
25d4fa6ba8 Make Request#RequestURI honor configured context root
Kubernetes-commit: 5677f7ab0b1b1ab22a71d01e4a710bf0f5e633aa
2025-04-03 12:51:46 -04:00
zhangzhifei16
335b05fae2 chore: Upgrade the mockery version to v2.53.3.
Kubernetes-commit: c1ff9cf4e8113ce17215ac71b3bc7ef419626b64
2025-04-10 21:16:47 +08:00
Tim Hockin
4a6072d89f Use randfill, do API renames
Kubernetes-commit: e54719bb6674fac228671e0786d19c2cf27b08a3
2025-02-20 09:45:22 -08:00
Patrick Ohly
bad1caabde client-go + apimachinery watch: context support
The Lister and Watcher interfaces only supported methods without context, but
were typically implemented with client-go API calls which need a context. New
interfaces get added using the same approach as in
https://github.com/kubernetes/kubernetes/pull/129109.

Kubernetes-commit: 6688adae142e37114d9dfa8d94cd1d8a91fbcc13
2024-12-20 13:55:47 +01:00
Patrick Ohly
be86cb59f1 client-go rest: store logger in Result
Storing a context and making sure that it never gets canceled also has
overhead. We might as well just do the klog.FromContext when constructing
the Result and store the logger for later use.

Kubernetes-commit: b7386467c8df686e935c477eac26049a80de789b
2024-11-27 13:19:47 +01:00
Patrick Ohly
5d128adc87 client-go/rest: finish conversion to contextual logging
The remaining calls can be converted without API changes.

Kubernetes-commit: 7821abf2ae289673bbfa3b9a6b8b34f5196c7c7e
2024-09-02 17:55:12 +02:00
Patrick Ohly
7aa9904196 client-go/rest: backoff with context support
The BackoffManager interface sleeps without considering the caller's context,
i.e. cancellation is not supported. This alone is reason enough to deprecate it
and to replace it with an interface that supports a context parameter.

The other reason is that contextual logging needs that parameter.

Kubernetes-commit: b15a1943d51adfb8c5e0185d58d25e038c3d6ade
2024-09-02 20:18:47 +02:00
Patrick Ohly
2b2015d460 client-go/test: warning handler with contextual logging
The default handler now uses contextual logging. Instead of

     warnings.go:106] warning 1

it now logs the caller of client-go and uses structured, contextual
logging

     main.go:100] "Warning" message="warning 1"

Users of client-go have the choice whether the handler that they provide uses
the traditional API (no API break!) or contextual logging.

Kubernetes-commit: 48fb886325fce4b16e4067caadb7bcd3044d460f
2024-09-02 17:51:01 +02:00
Ben Luddy
49537610e8 Fix content type fallback when a client defaults to CBOR.
With the ClientsAllowCBOR client-go feature gate enabled, a 415 response to a CBOR-encoded REST
causes all subsequent requests from the client to fall back to a JSON request encoding. This
mechanism had only worked as intended when CBOR was explicitly configured in the
ClientContentConfig. When both ClientsAllowCBOR and ClientsPreferCBOR are enabled, an
unconfigured (empty) content type defaults to CBOR instead of JSON. Both ways of configuring a
client to use the CBOR request encoding are now subject to the same fallback mechanism.

Kubernetes-commit: a77f4c7ba2e761461daaf115a38903fc91916dd6
2024-11-07 00:05:03 -05:00
Ben Luddy
334e30739d Wire serving codecs to CBOR feature gate.
Integration testing has to this point relied on patching serving codecs for built-in APIs. The
test-only patching is removed and replaced by feature gated checks at runtime.

Kubernetes-commit: 439d2f7b4028638b3d8d9261bb046c3ba8d9bfcb
2024-11-01 16:05:32 -04:00
Ben Luddy
10c2fdb7f4 Use application/cbor-seq media type in streaming CBOR responses.
The media type application/cbor describes exactly one encoded item. As a new (to Kubernetes) format
with no existing clients, streaming/watch responses will use the application/cbor-seq media
type. CBOR watch responses conform to the specification of CBOR Sequences and are encoded as the
concatenation of zero or more items with no additional framing.

Kubernetes-commit: 504f14998e920ca8837b3310094b3da11c62a070
2024-11-01 13:14:06 -04:00
Ben Luddy
8cb21671f4 Add CBOR feature gates.
For alpha, there is one apiserver feature gate and two client-go feature gates controlling
CBOR. They were initially wired to separate test-only feature gate instances in order to prevent
them from being configurable at runtime via command-line flags or environment variables (for
client-go feature gates outside of Kubernetes components). All of the integration tests required by
the KEP as alpha criteria have been implemented. This adds the feature gates to the usual feature
gate instances and removes the temporary code to support separate test-only feature gate instances.

Kubernetes-commit: 072dfcb416fd4e1ddab0a89ac4faf519e268bc96
2024-11-04 10:40:19 -05:00
Antonio Ojea
d69191cc45 rest client watch: use same name for package as folder
Kubernetes-commit: 8e1d0c664c60c094605f692360213b0284cdbe0f
2024-11-04 19:56:55 +00:00
Ben Luddy
15af21a2ae Fall back to JSON request encoding after CBOR 415.
If a client is configured to encode request bodies to CBOR, but the server does not support CBOR,
the server will respond with HTTP 415 (Unsupported Media Type). By feeding this response back to the
RESTClient, subsequent requests can fall back to JSON, which is assumed to be acceptable.

Kubernetes-commit: 1745dfdd154b1a838765e70b81c861c644bfcffe
2024-10-22 17:40:08 -04:00
Ben Luddy
c957b59518 Wire client feature gates affecting RESTClient content config.
Kubernetes-commit: 67b9dc1f3e23529804345deea76d36d07dff59b1
2024-10-25 11:50:01 -04:00
Ben Luddy
d8fc5bb524 Make generated client codecs support CBOR based on feature gate.
Kubernetes-commit: 57e337dbbf9e437bcb350d6551689669bb79d579
2024-10-24 16:38:45 -04:00
Monis Khan
6f44458e5e Use protobuf for core clients
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: c2ae465355b5222dbc27b8de8c55095b4f1b431a
2024-08-19 10:37:15 -04:00
Monis Khan
1647efd5c4 client-go/rest: move content type wiring from client to request
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: fe1eda0649fdb6a15200d279be214c67246d3b12
2024-08-18 15:01:57 -04:00
ComingCL
de60f3ccb5 fix typo errors in client-go rest package
Kubernetes-commit: faf891ad2d6dd1706932c8cf8774b2c7fb2b4bb1
2024-06-15 00:28:03 +08:00
Lukasz Szaszkiewicz
d274c7ba36 client-go/rest/request: decodes initialEventsListBlueprint for watchlist requests
Kubernetes-commit: 7be192ae0bd5d9628c5ee37c2e8b843d602c0fa3
2024-10-02 15:03:39 +02:00
Alvaro Aleman
7416b2ea43 RestCfg: Add godocs on how to disable ratelimiting
I frequently find myself in the situation of not remembering which of
QPS/Burst I have to set. This change adds a small go doc to clarify
that.

Kubernetes-commit: cd1645ff2c195fbb353cfabcbc36e3c3b883c3c5
2024-09-27 10:34:15 -04:00
Abhishek Kr Srivastav
7141d012f4 Fix Go vet errors for master golang
Co-authored-by: Rajalakshmi-Girish <rajalakshmi.girish1@ibm.com>
Co-authored-by: Abhishek Kr Srivastav <Abhishek.kr.srivastav@ibm.com>

Kubernetes-commit: 95860cff1c418ea6f5494e4a6168e7acd1c390ec
2024-09-12 18:15:22 +05:30
liyuerich
68d318f3aa drop deprecated json/yaml newSerializers, use json.NewSerializerWithOptions instead
Signed-off-by: liyuerich <yue.li@daocloud.io>

Kubernetes-commit: 3c9309db463679c348934429d8487d190ed5e64a
2024-05-29 19:00:00 +08:00
Patrick Ohly
3d02d42465 client-go/rest: contextual logging of request/response
Logging in rest.Request.Body cannot be made context-aware without an API
change. Such a change is complicated if done in a backwards-compatible
fashion (must change lots of callers in Kubernetes) and prohibitive if not (all
callers of Body would have to pass a context).

Instead, logging of the request body gets moved into the functions which send
the request. This is a change of behavior, but it is limited to log levels >= 8
and thus should have no impact in production.

A request which gets sent multiple times will also log the body multiple
times. This might even be a good thing because it serves as reminder what is
being sent when it is being sent.

While at it, stack backtracing gets enhanced so that the caller of the REST API
is logged and tests for the new behavior get added.

Kubernetes-commit: 57f9b7c7a2412865e7817dbf7638881b00ac9721
2024-08-29 19:44:55 +02:00
Quan Tian
009514ecc1 Enrich the error returned from Request.Watch method
The Error method of the error returned from Request.Watch was "unknown"
even the server returned clear message in the Status struct. It was
because Request.Watch used the Result's err member directly, which is an
unstructured error from the response which the Result object may use if
the caller did not return a structured error.

The patch fixes it by calling the Result's Error method instead, which
returns the structured error when it's present.

It also removes the wrong expectation about events.

Kubernetes-commit: 596c5696c64023808af164284263647d795b0ac2
2024-07-22 17:13:43 +08:00
David Eads
d69e298e04 automatically retry GET requests when http2 connection lost
Kubernetes-commit: 332a094e231942b8b6c2052d078241ddc698fe74
2024-08-27 16:32:32 -04:00
Timo Furrer
55c0e2c777 Fix typo in type name of watch decode error
Kubernetes-commit: fed49d06aac3f003f7b2df35ffed6b2f16ef2548
2024-07-08 07:52:38 +02:00
Vinayak Goyal
1582c4c03d KEP-4633: Allow health-only anonymous auth mode.
Signed-off-by: Vinayak Goyal <vinaygo@google.com>

Kubernetes-commit: 5e6a4937f5a3e20dd77238946220461332ecddff
2024-05-16 21:18:34 +00:00
Lukasz Szaszkiewicz
e89e40c187 client-go/rest: add TestWatchListWhenFeatureGateDisabled unit test
Kubernetes-commit: 8c0c1f720182f138c3151d3d67a80fa67b86a240
2024-05-23 16:33:43 +02:00
Lukasz Szaszkiewicz
a1be94abc3 client-go/rest: introduce watchlist
Kubernetes-commit: ad3d138cda76fc0267da5131fa3ff7906e2ddf76
2024-01-08 16:43:26 +01:00
aimuz
39f724a06e cleanup: duplicate request_test TestRequestAbsPathPreservesTrailingSlash
Signed-off-by: aimuz <mr.imuz@gmail.com>

Kubernetes-commit: 7da7468a3fc3f914c7b032c25c3e35097fd85449
2023-05-15 23:14:30 +08:00
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
Timo Furrer
d11d5308d6 Export DefaultServerUrlFor utility function
Signed-off-by: Timo Furrer <tuxtimo@gmail.com>

Kubernetes-commit: ebaf49dbd709a94e0c44aa75b4c32b50898a05e3
2023-05-16 19:20:07 +02:00
HirazawaUi
84dc0417b2 fix fd leaks and failed file removing for pkg client-go
Kubernetes-commit: 73aeed8766c2c42a6cb4fc8632b1b974f4508dde
2023-05-03 01:35:16 +08:00
Chris Bandy
18ffb5c67f Replace os.Setenv with testing.T.Setenv in tests
T.Setenv ensures that the environment is returned to its prior state
when the test ends. It also panics when called from a parallel test to
prevent racy test interdependencies.

Kubernetes-commit: 89467ad3e9b051515fa9632a7373d6ef01723256
2023-04-15 10:09:47 -05:00
Stephen Kitt
20433f9965 api-machinery: replace intstr.FromInt with intstr.FromInt32
This touches cases where FromInt() is used on numeric constants, or
values which are already int32s, or int variables which are defined
close by and can be changed to int32s with little impact.

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

Kubernetes-commit: 94410ee8078971b8894e5c400ce3fc79f02bc510
2023-03-14 16:17:48 +01:00
Tim Hockin
12553015e2 Replace uses of ObjectReflectDiff with cmp.Diff
ObjectReflectDiff is already a shim over cmp.Diff, so no actual output
or behavior changes

Kubernetes-commit: bc302fa4144d21a338683cd83701661f97be4aba
2023-03-23 11:34:03 -07: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
Abu Kashem
67f1485c1d client-go: add unit test for Request thread safety
Kubernetes-commit: ca492a9b62a586caf3e3cd22bc020108a63fb395
2022-08-26 13:24:36 -04:00
Abu Kashem
79c4b4060a client-go: add test to document retry conditions
Kubernetes-commit: 68c542d52246b0b750e332616884350164018695
2022-05-27 09:13:30 -04:00
wongearl
5d95f80033 diff.ObjectReflectDiff is DEPRECATED use cmp.Diff
Kubernetes-commit: 6da08775f9fc8d70f867435f55cf712d3a6ef056
2022-11-02 17:40:19 +08:00
Jordan Liggitt
422fe1f61e Fix indentation/spacing in comments to render correctly in godoc
Kubernetes-commit: 78cb3862f11225135afdf76f3424e2d7b33104c7
2022-12-17 17:31:05 -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
Antonio Ojea
1bd914a925 client-go: test transport generation is goroutine safe
Kubernetes-commit: fe41181c3d470207772d3ac9a91d4ef2c2a6720d
2022-09-04 12:36:01 +02:00
Vatsal Parekh
bf2b395a89 Fix Infelicities in TestRESTClientLimiter
Signed-off-by: Vatsal Parekh <vatsalparekh@outlook.com>

Kubernetes-commit: c980cf489eeb39fd0fe0af7e80cfea2dbe2007db
2022-09-15 19:30:40 +05:30
Monis Khan
5dab9a0b84 client-go/transport: drop Dial and GetCert fields in favor of Holders
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: 3313a70d5bcc40a39f99f482c18effc9de6072ba
2022-09-09 08:06:01 -04:00
Shyam Jeedigunta
b8a8d94944 Add DisableCompression option to KubeConfig
Kubernetes-commit: 641fd5b482c6117d459a22d99f76aae086c3524f
2022-09-07 18:04:17 -07:00