Commit Graph

543 Commits

Author SHA1 Message Date
Marek Siarkowicz a559cb8be1 Unify references to group resource in metrics
Skip apiserver_storage_objects as it's a stable metrics that doesn't
have "group" label. As defined in KEP-1209 adding a label is considered
a breaking change so this change should be done via deprecation and
introduction of new metric.

Tested via:
```
kubectl get --raw /metrics | grep -i apiservice | grep -v APIServiceRegistrationController | grep -v aggregator_unavailable_apiservice | python3 -c "import sys; print('\n'.join([k+' ' + v for k,v in {a.split('{')[0]:'{'+a.split('{')[1].split('}')[0]+'}' for a in sys.stdin.readlines() if '#' not in a and '_sum' not in a and '_bucket' not in a}.items()]))"
```

Before:
```
apiserver_cache_list_fetched_objects_total {index="",resource_prefix="/apiregistration.k8s.io/apiservices"}
apiserver_cache_list_returned_objects_total {resource_prefix="/apiregistration.k8s.io/apiservices"}
apiserver_cache_list_total {index="",resource_prefix="/apiregistration.k8s.io/apiservices"}
apiserver_longrunning_requests {component="apiserver",group="apiregistration.k8s.io",resource="apiservices",scope="cluster",subresource="",verb="WATCH",version="v1"}
apiserver_request_body_size_bytes_count {resource="apiservices.apiregistration.k8s.io",verb="create"}
apiserver_request_duration_seconds_count {component="apiserver",dry_run="",group="apiregistration.k8s.io",resource="apiservices",scope="resource",subresource="",verb="POST",version="v1"}
apiserver_request_sli_duration_seconds_count {component="apiserver",group="apiregistration.k8s.io",resource="apiservices",scope="resource",subresource="",verb="POST",version="v1"}
apiserver_request_total {code="201",component="apiserver",dry_run="",group="apiregistration.k8s.io",resource="apiservices",scope="resource",subresource="",verb="POST",version="v1"}
apiserver_response_sizes_count {component="apiserver",group="apiregistration.k8s.io",resource="apiservices",scope="cluster",subresource="",verb="LIST",version="v1"}
apiserver_selfrequest_total {resource="apiservices",subresource="",verb="POST"}
apiserver_storage_events_received_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_storage_list_evaluated_objects_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_storage_list_fetched_objects_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_storage_list_returned_objects_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_storage_list_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_storage_objects {resource="apiservices.apiregistration.k8s.io"}
apiserver_watch_cache_events_dispatched_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_watch_cache_events_received_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_watch_cache_initializations_total {resource="apiservices.apiregistration.k8s.io"}
apiserver_watch_cache_resource_version {resource="apiservices.apiregistration.k8s.io"}
apiserver_watch_events_sizes_count {group="apiregistration.k8s.io",kind="APIService",version="v1"}
apiserver_watch_events_total {group="apiregistration.k8s.io",kind="APIService",version="v1"}
etcd_request_duration_seconds_count {operation="listWithCount",type="/registry/apiregistration.k8s.io/apiservices/"}
etcd_requests_total {operation="listWithCount",type="/registry/apiregistration.k8s.io/apiservices/"}
watch_cache_capacity {resource="apiservices.apiregistration.k8s.io"}
```

After:
```
apiserver_cache_list_fetched_objects_total {group="apiregistration.k8s.io",index="",resource="apiservices"}
apiserver_cache_list_returned_objects_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_cache_list_total {group="apiregistration.k8s.io",index="",resource="apiservices"}
apiserver_longrunning_requests {component="apiserver",group="apiregistration.k8s.io",resource="apiservices",scope="cluster",subresource="",verb="WATCH",version="v1"}
apiserver_request_body_size_bytes_count {group="apiregistration.k8s.io",resource="apiservices",verb="create"}
apiserver_request_duration_seconds_count {component="apiserver",dry_run="",group="apiregistration.k8s.io",resource="apiservices",scope="resource",subresource="",verb="POST",version="v1"}
apiserver_request_sli_duration_seconds_count {component="apiserver",group="apiregistration.k8s.io",resource="apiservices",scope="resource",subresource="",verb="POST",version="v1"}
apiserver_request_total {code="201",component="apiserver",dry_run="",group="apiregistration.k8s.io",resource="apiservices",scope="resource",subresource="",verb="POST",version="v1"}
apiserver_response_sizes_count {component="apiserver",group="apiregistration.k8s.io",resource="apiservices",scope="cluster",subresource="",verb="WATCH",version="v1"}
apiserver_selfrequest_total {group="apiregistration.k8s.io",resource="apiservices",subresource="",verb="WATCH"}
apiserver_storage_events_received_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_storage_list_evaluated_objects_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_storage_list_fetched_objects_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_storage_list_returned_objects_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_storage_list_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_storage_objects {resource="apiservices.apiregistration.k8s.io"}
apiserver_watch_cache_events_dispatched_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_watch_cache_events_received_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_watch_cache_initializations_total {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_watch_cache_resource_version {group="apiregistration.k8s.io",resource="apiservices"}
apiserver_watch_events_sizes_count {group="apiregistration.k8s.io",resource="apiservices",version="v1"}
apiserver_watch_events_total {group="apiregistration.k8s.io",resource="apiservices",version="v1"}
etcd_bookmark_counts {group="apiregistration.k8s.io",resource="apiservices"}
etcd_request_duration_seconds_count {group="apiregistration.k8s.io",operation="listWithCount",resource="apiservices"}
etcd_requests_total {group="apiregistration.k8s.io",operation="listWithCount",resource="apiservices"}
watch_cache_capacity {group="apiregistration.k8s.io",resource="apiservices"}
```

Kubernetes-commit: f712b01ddb55f6569b930ca714499051ba8cb311
2025-05-19 11:41:09 +02:00
Karl Isenberg 32e916b79d test: Close response body in watch tests
- Close response body after http calls in the watch tests
- Add apitesting utility methods for closing and testing errors
  from response body and websocket.
- Validate read after close errors.

Kubernetes-commit: 9d963298a3b7b828f01a9b02af57863a7480eb0b
2025-04-29 17:32:48 -07:00
Davanum Srinivas 1ffdd2403f Eliminate AuditContext`s SetEventLevel
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
Co-Authored-By: Jordan Liggitt <liggitt@google.com>

Set event level during context init

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

Kubernetes-commit: 960a4939f2502f2a8f2b923203e9075354e4bdc0
2025-05-09 06:57:31 -04:00
Karl Isenberg 1552f6cea3 test: pass the test context to http requests
This handles canceling the request after the test completes, cleaning
up resources on the client and server.

Kubernetes-commit: 080d6f9ead740ec1358e320e388f79cc4de97697
2025-04-29 17:05:13 -07:00
Karl Isenberg 46dd96ca03 refactor: Stop using ioutil in apiserver
- The ioutl package is deprecated. Migrate to os package functions.

Kubernetes-commit: f93e4645c18c6f56bfddc158ef7b3f674b3c41dd
2025-05-08 11:28:52 -07:00
sxllwx e6df86ea96 Fix API server crash on concurrent map iteration and write
Improve audit context handling by encapsulating event data and operations behind a structured API. Make
the Audit system more robust in concurrent environments by properly isolating mutable state. The cleaner
API simplifies interaction with audit events, improving maintainability. Encapsulation reduces bugs
by preventing direct manipulation of audit events.

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
Co-Authored-By: Jordan Liggitt <liggitt@google.com>
Co-Authored-By: sxllwx <scottwangsxll@gmail.com>

Kubernetes-commit: 75afa1e0acfb309d984be14937a06f796f220cd6
2023-10-23 20:59:40 +08:00
Karl Isenberg 61451f57b1 refactor: Add request method constants
This avoids linter errors from using inline strings as http request
methods.

Kubernetes-commit: e81887276c65acccc5486f2ff69d8bc54ac3c6ca
2025-04-29 16:45:30 -07:00
Karl Isenberg 4c858d18eb chore: move watch handler tests to handlers pkg
- Move the watch handler unit tests to the same package as the
  WatchServer implementation.
  k8s.io/apiserver/pkg/endpoints -> k8s.io/apiserver/endpoints/handlers
- Copy over minimal scheme and codec test setup
- Refactor the tests to use testify assert and require

This unblocks making WatchServer private, if we decide to do that.

Kubernetes-commit: 7fcc1bcf1d1fdb2da6ea1c5b49798a7c7eeb6e6d
2025-04-15 16:34:28 -07:00
Wei Fu 9ff9bbbc47 *: reduce tracing events during streaming JSON objects
If apiserver is handing heavy traffic volume, it's likely to trigger
tracing events. After streaming JSON objects, the number of tracing events
are same to object number. It's unneccessary to log each write call.
This patch is to reduce tracing events.

Signed-off-by: Wei Fu <fuweid89@gmail.com>

Kubernetes-commit: 003f2157671a694aefecd4dbb7df786e27200a18
2025-03-11 13:26:55 -04:00
Marek Siarkowicz 67ec836891 Implement streaming proto encoding
Kubernetes-commit: f5dd7107f7144c4f76ca6159c1eeddb48a12feaa
2024-12-19 12:30:39 +01:00
Tim Hockin 9641d30242 Use randfill, do API renames
Kubernetes-commit: e54719bb6674fac228671e0786d19c2cf27b08a3
2025-02-20 09:45:22 -08:00
Marek Siarkowicz 38b01a1f78 Streaming JSON encoder for List
Kubernetes-commit: e7c743b2ebfaed1e3132027c0369ac25b14b6f47
2024-12-19 10:38:30 +01:00
z1cheng c576a626de Implement chunking for gzip encoder in deferredResponseWriter
Signed-off-by: z1cheng <imchench@gmail.com>

Kubernetes-commit: 2472f4965fe2f2013b993b6b56539946a21a3740
2025-02-20 18:36:47 +08:00
nkeert 11288ef6c1 Add a test to validate deferredResponseWriteron multiple write calls
Signed-off-by: nkeert <197718357+nkeert@users.noreply.github.com>

Kubernetes-commit: 45e2f3e438e18b74f3b7a6645ff2073862ef0e38
2025-02-15 10:23:21 +05:30
Patrick Ohly b84662911c remove import doc comments
The "// import <path>" comment has been superseded by Go modules.
We don't have to remove them, but doing so has some advantages:

- They are used inconsistently, which is confusing.
- We can then also remove the (currently broken) hack/update-vanity-imports.sh.
- Last but not least, it would be a first step towards avoiding the k8s.io domain.

This commit was generated with
   sed -i -e 's;^package \(.*\) // import.*;package \1;' $(git grep -l '^package.*// import' | grep -v 'vendor/')

Everything was included, except for
   package labels // import k8s.io/kubernetes/pkg/util/labels
because that package is marked as "read-only".

Kubernetes-commit: 8a908e0c0bd96a3455edf7e3b5f5af90564e65b0
2024-12-02 14:43:58 +01:00
Davanum Srinivas 51b4b4971a Possible fix for alpha CI jobs failing with AllowUnsafeMalformedObjectDeletion switched on
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 9c6126e29c2dd63668c5d2320a4c26ff173fc499
2024-11-09 08:56:55 -05:00
Abu Kashem 8b8b5c0f78 add access control check for unsafe delete
add access control check to ensure that the user has permission to do
'unsafe-delete-ignore-read-error' on the resource being deleted

Kubernetes-commit: 9932dbef5787bfdc88d8ae35e90dc0965bbc6c80
2024-10-31 16:01:58 -04:00
Abu Kashem 1f27993c44 implement unsafe deletion, and wire it
- implement unsafe deletion, and wire it
- aggregate corrupt object error(s) from the storage LIST operation
- extend storage error:
a) add a new type ErrCodeCorruptObj to represent a corrupt object:
b) add a new member 'InnerErr error' to StorageError to hold
   the inner error
- add API status error

Kubernetes-commit: 5d4b4a160dc551dc8979012eeabea1a098945603
2024-09-20 17:36:27 -04:00
Abu Kashem 4ce1c97be7 api: add a new field to meta/v1 DeleteOptions
- add a new boolean field
  IgnoreStoreReadErrorWithClusterBreakingPotential to meta/v1 DeleteOptions

- add validation for the new delete option
add validation for the new field in the delete options
ignoreStoreReadErrorWithClusterBreakingPotential

- prevent the pod eviction handler from issuing an unsafe pod delete
prevent the pod eviction handler from enabling the
'ignoreStoreReadErrorWithClusterBreakingPotential' delete option

Kubernetes-commit: b6773f15897dc31190b2be7cb49dd02015440465
2024-09-23 12:22:53 -04:00
Ben Luddy 0b5852eb9a 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 dc2e401d84 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 ca9c3d965e 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
Ben Luddy 30be0a3c20 Allow nondeterministic object encoding in HTTP response bodies.
Kubernetes-commit: dee76a460ec80f15dc199c93e506586687d42291
2024-10-28 12:09:02 -04:00
Ben Luddy cf0dbba4e6 Support application/apply-patch+cbor in patch requests.
Kubernetes-commit: 37ed906a33211c7d578cab2d681941ebfd2f2f23
2024-10-22 16:08:24 -04:00
Lukasz Szaszkiewicz 36e57697d1 apiserver/handlers/watch: encode initialEventsListBlueprint with watchEncoder (#127587)
* apiserver/handlers/get: construct versionedList

* storage/cacher: document caching the serialization of bookmark events

* endpoints/handlers/response: add watchListTransformer

* endpoints/handlers/watch: wire watchListTransformer

Kubernetes-commit: fbf1a0dc181ccbeb9925ad9c284d913a25c16562
2024-10-01 11:55:50 +00:00
CasperLiu 1bb7b2e6ab introduce a proper trace context
Signed-off-by: carlory <baofa.fan@daocloud.io>
Co-authored-by: CasperLiu <qiuyuzhe521@gmail.com>

Kubernetes-commit: 5b2632f70763aeadfc334df1364946fe39fc10bb
2024-04-07 17:58:59 +08:00
Lukasz Szaszkiewicz 8cb411e993 adds watchListEndpointRestrictions for watchlist requests (#126996)
* endpoints/handlers/get: intro watchListEndpointRestrictions

* consistencydetector/list_data_consistency_detector: expose IsDataConsistencyDetectionForListEnabled

* e2e/watchlist: extract common function for adding unstructured secrets

* e2e/watchlist: new e2e scenarios for convering watchListEndpointRestrict

Kubernetes-commit: ae35048cb0b9b177891aab41346b6d6cc504582f
2024-09-25 12:48:33 +00:00
Abhishek Kr Srivastav 17ab6c21d5 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
Monis Khan cc8ff8f965 ForbiddenStatusError: make linter happy on error construction
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: bff6ce4a38077c29cdf2e1ac2fce1a551082ebfe
2024-08-05 10:50:51 -04:00
Monis Khan 757565c389 SSA: improve create authz error message
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: 857127f7c44a029f6f8dd44b0b40364aa00aa13d
2024-08-02 17:20:53 -04:00
Eric Lin 5d14d72b5c Fix httplog not logging watch duration in separate goroutines
Signed-off-by: Eric Lin <exlin@google.com>

Kubernetes-commit: 06c7058115e623126884d05c54a30db511a9cb71
2024-06-21 10:03:31 +00:00
Joe Betz b5d1135b94 Apply feedback
Kubernetes-commit: 13f809478f9322341a04715cda1b3912a9e470d5
2024-06-03 14:59:31 -04:00
Joe Betz dfdf159360 Handle unstructured objects correctly in IgnoreManagedFieldsTimestampsTransformer
Kubernetes-commit: c942ab6900ddb7b6e3e7c550c521409693180968
2024-05-31 21:25:25 -04:00
Joe Betz 30fd718497 Fix apply equality check to allow empty map to be equal to nil for builtin types
Kubernetes-commit: f8a33e3679488e5ee3700d37dd45cee8b346e89e
2024-06-04 12:11:00 -04:00
Stephen Kitt 942c16fb6a Use canonical json-patch v4 import
The canonical import for json-patch v4 is
gopkg.in/evanphx/json-patch.v4 (see
https://github.com/evanphx/json-patch/blob/master/README.md#get-it for
reference).

Using the v4-specific path should also reduce the risk of unwanted v5
upgrade attempts, because they won't be offered as automated upgrades
by dependency upgrade management tools, and they won't happen through
indirect dependencies (see
https://github.com/kubernetes/kubernetes/pull/120327 for context).

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

Kubernetes-commit: 5300466a5c8988b479a151ceb77f49dd00065c83
2024-02-16 13:57:24 +01:00
Marek Siarkowicz 74fb076497 Cleanup defer from SetFeatureGateDuringTest function call
Kubernetes-commit: 3ee81787685e47a7a5da22423c8ca4455577ecb3
2024-04-23 10:39:47 +02:00
Marek Siarkowicz 3a83dc12eb Fix SetFeatureGateDuringTest handling of Parallel tests
Stop using defer as parallel subtest will might result in main test
finishing before subtest.

Fatal when same flag is set twice.

Kubernetes-commit: 9fcf279e2b91e7549190a433373f256fb5aebe85
2024-03-05 21:56:40 +01:00
Tim Allclair 337f031e71 Stop appending AppArmor status to node ready condition
Kubernetes-commit: 24537a91317f9fd125ee805cd0b781358ac86f35
2024-02-21 13:11:07 -08:00
Eric Lin 000601bdbe Add handler to run watch serving in separate goroutine
This handler allows running execution prior to actual serving in a separate
goroutine when serving requests. Doing so benefits cases in serving long running
requests because it allows freeing memory used by the separate goroutine
and keeps the serving routines slim.

Signed-off-by: Eric Lin <exlin@google.com>

Kubernetes-commit: 7b2698a5e5c61b303481c2006847409fc8704746
2023-10-10 08:53:26 +00:00
Vandit Singh ff6a2dc722 Negative index regression test for json-patch (#122625)
* add testcase with negative index

* exercise successful negative index patching

* use different values for testing

Co-authored-by: Chris Bandy <bandy.chris@gmail.com>

---------

Co-authored-by: Chris Bandy <bandy.chris@gmail.com>

Kubernetes-commit: 83ff8a2f49f820fb355b24c65b8629710dca8a54
2024-01-18 09:31:12 +00:00
Eric Lin a2e6b85db4 handlers/watch: refactor watch serving to prepare offloading
Signed-off-by: Eric Lin <exlin@google.com>

Kubernetes-commit: 87d817e62d8c6e93cf45bf90a7ecadfe4156ab1f
2023-11-27 10:06:50 +00:00
Wojciech Tyczyński 697d456e35 Minor cleanup in watch handlers
Kubernetes-commit: d907062308563b1a9e52152c48f4240a6e11aade
2023-11-29 22:31:05 +01:00
Wojciech Tyczyński 442cc39449 Unify watch handler across http and websockets
Kubernetes-commit: 55e60db88b126013f00135f49df3296f52b2572a
2023-11-29 21:57:39 +01:00
Wojciech Tyczyński d64b183dbd Address review comments
Kubernetes-commit: 0dd495e6dc253f94b0ad0bb92178fb5e8981116b
2023-10-13 10:48:16 +02:00
Wojciech Tyczyński 65d3be7b39 Refactor watch event serialization to allow caching
Kubernetes-commit: 7ff866463af46b5f7cf068ba8d51c68e417b9ece
2023-08-25 15:41:14 +02:00
Yao Cheng 2b3f11cba2 Register metrics for apiserver handlers
Signed-off-by: Yao Cheng <chengyao09@hotmail.com>

Kubernetes-commit: 18c3b6fce43edd76620a07707af2d851b52c3fad
2023-09-06 17:25:12 +00:00
Damien Grisonnet b5b4cd7758 apiserver: rename request body size metric
Rename the apiserver_request_body_sizes metric to
apiserver_request_body_size_bytes to conform with Prometheus best
practices.

This can be done safely without deprecation because that metric wasn't
registered before.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>

Kubernetes-commit: 08006c842fd6a584bb8e2511587c999ffe7ced9d
2023-09-07 19:16:31 +02:00
Lukasz Szaszkiewicz cd87b8f62d handlers/watch: calculate and record WatchList latency metric.
Kubernetes-commit: 772b1f4cd84a738f632716e28d4067c00f0b7f13
2023-09-19 03:05:00 +02:00
HirazawaUi 91aa0e1c62 Add namespace to apiserver tracing
Kubernetes-commit: 45b9b0df41fb67cf2c71263b3577f3b3daff4899
2023-09-03 21:50:47 +08:00
HirazawaUi f5f4a6148a Add subresource to apiserver tracing
Kubernetes-commit: c83eb6dcaaacfe8b5706f7fdc969000fbef2d119
2023-09-03 21:37:13 +08:00