797 Commits

Author SHA1 Message Date
Antonio Ojea
023460f5a8 events: ensure the name is valid
The event Object is created from the referenced Object name, however,
there is no guarantee that the name from the referenced Object will be a
valid Event Name.

For those Objects with name not valid for an Event, generate a new valid
name using an UUID.

Kubernetes-commit: ee36b817df06f84ce1a48ef4d65ed559c3775404
2025-02-20 09:13:56 +00:00
Sean Sullivan
3ead27a3a2 Update websocket logging levels for better debuggability
Kubernetes-commit: d3feb5080c18fa73aa87c81a78d5cac82c6ed06d
2025-02-11 20:20:23 +00:00
Patrick Ohly
57bc261e52 client-go watch: NewIndexerInformerWatcherWithContext -> WithLogger
The ability to automatically stop on context cancellation was new functionality
that adds complexity and wasn't really used in Kubernetes. If someone wants
this, they can add it outside of the function.

A *WithLogger variant avoids the complexity and is consistent with
NewStreamWatcherWithLogger over in apimachinery.

Kubernetes-commit: 1a8d8c9b4a33daf9330434e1ad544ef3571722a3
2025-01-31 10:18:04 +01: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
David Eads
f2d9cfb8c8 switch to using the real FIFO
Kubernetes-commit: a9aab298b4738f4ea9111131cdf193a3b1ba14e5
2025-01-10 16:23:23 -05:00
David Eads
43bf1a1b0a make a real FIFO implementation
Kubernetes-commit: 24b43ea96ec60ca2c574ccc6b51c989488ca3210
2025-01-10 16:23:07 -05:00
David Eads
52af3bdc0f Remove cache.ErrRequeue
cache.ErrRequeue advertised itself as a way to requeue failures on a
FIFO, but it suffers the same problems as AddIfNotPresent.  If we do
requeue an item at the end, we'll move the informer back in time.  If we
requeue at the beginning we'll simply wedge FIFO.

We didn't find examples in the wild, but by removing the error type
those impacted will get a compile error and get to decide what action is
most appropriate for their failure.  Most of the time, proceeding to the
next item is best.

Kubernetes-commit: 238c32a1d9b2c72d648193fa8642a53a2884975f
2025-01-20 13:59:43 -05:00
David Eads
d853ccf18c Remove Queue.AddIfNotPresent
Logically a cache.Queue.AddIfNotPresent means that the informer can move
back in time since an older item is placed after newer items.  The
alternative of placing errors at the head of the queue leads to
indefinite memory growth and repeated failures on retry.

Luckily this behavior was behind RetryOnError, which was always set to
false and impossible for normal users to set to true.  By removing the
function and setting, impacted users (none found in a github search)
will get a compile failure.

Kubernetes-commit: 8e77ac000131019d5aa49c19aa1f477f6dac4d59
2025-01-20 13:54:32 -05:00
David Eads
f29637f7f2 shrink the cache.Queue interface to what is actually used
Kubernetes-commit: 0ddab1694579d523e3865c75ca44d6cdf1b0ef93
2025-01-08 15:31:47 -05:00
Tiago Silva
9f1cce41d5 client-go: transform watchErrorStream to wrap the underlying error (#129765)
* `client-go`: transform `watchErrorStream` to wrap the underlying error

This PR transforms the `client-go`'s `watchErrorStream` to wrap the error instead of transforming it into a single string. This enables clients to use `errors.Is/As/Unwrap` with the errors that come out of `StreamWithContext`

Fixes https://github.com/kubernetes/kubernetes/issues/129763

* adjust unit tests

Kubernetes-commit: 067012f5844b7390e7279f575342ae0536f80520
2025-01-23 20:07:37 +00:00
Patrick Ohly
40cace856c client-go/tools/cache: fix TestAddWhileActive
4638ba971661497b147906b8977ae206c9dd6e44 added tracking of the goroutine which
executes informer.Run. In the TestAddWhileActive the original `go
informer.Run()` was left in place, causing a data race between the two
`informer.Run` instances:

==================
WARNING: DATA RACE
Read at 0x00c000262398 by goroutine 5302:
  k8s.io/client-go/tools/cache.(*controller).RunWithContext()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/controller.go:162 +0x1ad
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).RunWithContext()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:584 +0x6c5
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).Run()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:527 +0x48
  k8s.io/client-go/tools/cache.TestAddWhileActive.gowrap1()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer_test.go:1080 +0x17

Previous write at 0x00c000262398 by goroutine 5301:
  k8s.io/client-go/tools/cache.New()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/controller.go:142 +0x9de
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).RunWithContext.func1()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:562 +0xa78
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).RunWithContext()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:565 +0x119
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).Run()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:527 +0x44
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).Run-fm()
      <autogenerated>:1 +0x17
  k8s.io/client-go/tools/cache.TestAddWhileActive.(*Group).StartWithChannel.func2()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:55 +0x38
  k8s.io/apimachinery/pkg/util/wait.(*Group).Start.func1()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:72 +0x86

Goroutine 5302 (running) created at:
  k8s.io/client-go/tools/cache.TestAddWhileActive()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer_test.go:1080 +0x93e
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1690 +0x226
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1743 +0x44

Goroutine 5301 (running) created at:
  k8s.io/apimachinery/pkg/util/wait.(*Group).Start()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:70 +0xe4
  k8s.io/apimachinery/pkg/util/wait.(*Group).StartWithChannel()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:54 +0x7e6
  k8s.io/client-go/tools/cache.TestAddWhileActive()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer_test.go:1074 +0x6a1
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1690 +0x226
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1743 +0x44
==================

Kubernetes-commit: d66ced5730fa60c04b0a39df58a156b7045585f6
2025-01-14 14:06:31 +01:00
Patrick Ohly
498e3efe74 client-go cache: fix TestHammerController
The test relied on a 100ms sleep to ensure that controller was done.  If that
race was lost, one goroutine was intentionally prevented from completing by
locking a mutex permanently. A TODO was left about detecting that.

Adding goroutine leak checking in
https://github.com/kubernetes/kubernetes/pull/126387 revealed that this race
indeed sometimes is lost because the goroutine
leaked (https://github.com/kubernetes/kubernetes/issues/129400).

Waiting for controller shutdown instead of relying on timing should fix this.

Kubernetes-commit: 8e1403563a60f3b7a258e3bbb64b5c3a7f6548fb
2024-12-29 12:18:50 +01:00
Patrick Ohly
5d289bc44c client-go/tools/cache: add APIs with context parameter
The context is used for cancellation and to support contextual logging.

In most cases, alternative *WithContext APIs get added, except for
NewIntegerResourceVersionMutationCache where code searches indicate that the
API is not used downstream.

An API break around SharedInformer couldn't be avoided because the
alternative (keeping the interface unchanged and adding a second one with
the new method) would have been worse. controller-runtime needs to be updated
because it implements that interface in a test package. Downstream consumers of
controller-runtime will work unless they use those test package.

Converting Kubernetes to use the other new alternatives will follow. In the
meantime, usage of the new alternatives cannot be enforced via logcheck
yet (see https://github.com/kubernetes/kubernetes/issues/126379 for the
process).

Passing context through and checking it for cancellation is tricky for event
handlers. A better approach is to map the context cancellation to the normal
removal of an event handler via a helper goroutine. Thanks to the new
HandleErrorWithLogr and HandleCrashWithLogr, remembering the logger is
sufficient for handling problems at runtime.

Kubernetes-commit: 4638ba971661497b147906b8977ae206c9dd6e44
2024-07-26 15:26:00 +02:00
Patrick Ohly
b836a27b07 client-go/tools/cache: goroutine leak checking
Several tests leaked goroutines. All of those get fixed where possible
without API changes. Goleak is used to prevent regressions.

One new test specifically covers shutdown of an informer and its event
handlers.

Kubernetes-commit: 0ba43734b4c8998b4aaeb1fa2bec8dee609fa50a
2024-11-28 17:59:36 +01:00
Patrick Ohly
70a4950f35 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
Jefftree
bf1a6eed35 v1alpha2 LeaseCandidate API
Kubernetes-commit: 0ce7b688a65a65031c6ee8c616989e4b0be4ce9f
2024-10-04 14:43:11 +00:00
Abu Kashem
e132ac21c9 handle watch for unsafe delete
Kubernetes-commit: 25efc8f2d136a9574166be02789ac727c5b4a3fd
2024-11-05 20:36:56 -05:00
Maciej Szulik
bf414551df Clean error handling in port-forward
This commit introduces:
1. Cleanups in port-forwarding error handling code, which ensures that
   we only compare lowercased text always.
2. E2E verifying that when a pod is removed a port-forward is stopped.

Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 0b1617ccefbc6ea61c0e7c2b0b4052703f11c51c
2024-10-16 14:02:01 +02:00
Nic
d6404c8d76 fix: draining remote stream after port-forward connection broken
Signed-off-by: Nic <qianyong@api7.ai>

Kubernetes-commit: dbe6b6657bacc846656f4009ee869ca996dde1da
2024-10-04 14:48:15 +08:00
Davanum Srinivas
6c84382029 Use k8s.io/utils/lru instead of github.com/golang/groupcache/lru
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 2b0592ee77d0a0bb3017df042066ecb8c83d2fb3
2024-11-01 22:19:11 -04:00
googs1025
1b8aded77b chore(leader-election): modify leader-election comment to OnStoppedLeading callback is always called when the LeaderElector exits, even if it did not start leading.
Kubernetes-commit: 7d2fbc7cfd49bca7d58160ed25dfd1f838629bb9
2024-09-30 09:38:10 +08:00
Federico Bongiovanni
65ed08a834 Update OWNERS
Adding  jefftree also to the reviewers list

Kubernetes-commit: 5f052ada19c43471bdcbb6da4e6f72405ca46bd7
2024-10-22 16:26:30 -07:00
Federico Bongiovanni
29ce700614 Update staging/src/k8s.io/client-go/tools/leaderelection/OWNERS
Co-authored-by: Benjamin Elder <bentheelder@google.com>

Kubernetes-commit: d20bc10645e716034e91d365d17d8b1011d3f1cd
2024-08-14 13:21:52 -07:00
Federico Bongiovanni
3c2f0814df Update OWNERS
Adding jefftree to the owners file for leaderelection

Kubernetes-commit: b5bbc1508f986df7811dd79e7b5116bbede784e8
2024-08-14 12:16:59 -07:00
Alexander Stephan
ce42c297f4 Make getter names for reflector fields idiomatic
Kubernetes-commit: fdabcb5141094cb99afde24ec1df15026b4ba349
2024-10-13 20:53:25 +00:00
Alexander Stephan
146d03f559 Export name and typeDescription members of reflector struct
Kubernetes-commit: 154b8aa8806d743c41d1acf0b498bdecf1767872
2024-09-26 15:09:59 +00:00
Jordan Liggitt
a398951ea1 Implement limited merge function
Kubernetes-commit: 4d8cbad58e21e701af735c5ffa1a9fd3393de096
2024-08-17 21:27:26 -04:00
Jordan Liggitt
56b7eaf344 Narrow merge interface to merging the same types
Kubernetes-commit: 9fde1c6a85c1390c7be7705385eb99b3ebc8e06a
2024-08-17 20:43:53 -04:00
Jordan Liggitt
b3dca7eb8a Isolate mergo use, add test coverage and error checking
Kubernetes-commit: 3b3886a4509a83aff0afe7ad42da9b7819a17aed
2024-08-17 16:42:11 -04:00
Matthieu MOREL
baf58c3d79 fix: enable error-is-as rule from testifylint in module k8s.io/client-go
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Kubernetes-commit: a28c2b6bf8657889c18b683dd42044559a96c304
2024-09-22 12:21:05 +02:00
Stephen Kitt
e996fa7a55 Drop references to auth-path and kubernetes_auth
These are long gone, removed in 2016:
* AuthPath removal: https://github.com/kubernetes/kubernetes/pull/29216
* Flag removal: https://github.com/kubernetes/kubernetes/pull/40048

This removes the remnants from clientcmd, mostly in the comments
describing how the configuration is loaded.

Since getServerIdentificationPartialConfig can no longer fail (it
copies fields from one struct to another), this drops the error
return, along with the error handling in the caller.

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

Kubernetes-commit: 8a8238ba7f850241de9c5cc4b22fa1a6b6a19480
2024-07-05 14:55:44 +02:00
guozheng-shen
4d28b8364c endpointsLeasesResourceLock and configMapsLeasesResourceLock are removed too
Kubernetes-commit: a302abb32fc94842c421a4082dfb52be07b16c34
2024-09-19 14:02:52 +08:00
Andy Goldstein
da3ab4e935 Move ncdc to emeritus
I am moving myself to emeritus as I am now firmly on the end-user side
of things.

Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>

Kubernetes-commit: 3ab816dcabf37acda33c665ab5aa85f1f6163bc1
2024-08-17 13:00:07 -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
aimuz
4379fade33 leaderelection: replace deprecated wait.PollImmediateUntil with wait.PollUntilContextTimeout
This commit refactors the `renew` function in the leader election package to replace
the deprecated `wait.PollImmediateUntil` with `wait.PollUntilContextTimeout`.
This change simplifies the context handling by removing the need for an additional
timeout context and its cancellation.

The previous implementation created a timeout context for each retry period,
which added unnecessary complexity. The new implementation directly passes the parent
context to the retry function, ensuring that the timeout is handled within `PollUntilContextTimeout`.

This change also ensures that the context passed to `tryAcquireOrRenew` and
`tryCoordinatedRenew` is consistent, improving the readability and maintainability of the code.

Kubernetes-commit: 3d2f498aa31cb2e90bcfc372b7930aed0604fbef
2024-08-30 19:25:45 +08:00
Lalit
aa6ed1bae1 Updating event spam key to allow recording of more unique events
Kubernetes-commit: 99d20307cfa41f9beefa97c5bec2ee00b2d8b620
2024-05-08 12:05:42 +05:30
mprahl
2176e80333 Stop the RetryWatcher when failing due to permissions issue
When the client does not have permission to watch a resource, the
RetryWatcher continuously retried. In this case, it's better to send an
error and stop retrying to let the caller handle this case since this is
not a transient error that can be recovered without user intervention.

This is particularly helpful in applications that leverage a user
provided service account and the application needs to notify the user to
set the correct permissions for the service account.

This also accounts for invalid credentials from the watch client.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>

Kubernetes-commit: db2218d16e3fb2a30b21ffa0f307beb515d8394b
2024-07-11 13:50:52 -04:00
Tobias Klauser
ae43527480 client-go: fix typo in leaderelection error log message
Kubernetes-commit: 99a90df3d0403315f26d643b90ab6339c22602c8
2024-08-13 11:21:57 +02:00
Dr. Stefan Schimanski
f71a5cc5d3 Call non-blocking informerFactory.Start synchronously to avoid races
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>

Kubernetes-commit: c7a1fa432a87579895eac4b3873162d5f1dba7f5
2024-07-27 16:13:16 +02:00
Jefftree
825f52e194 Change PingTime to be persistent
Kubernetes-commit: 0c774d0b1f79b0b0a6d73102a78c84853220f036
2024-07-23 19:19:12 +00:00
Jefftree
f45c45195a fix ordering issue in candidates
Kubernetes-commit: e1ea24a171ca6ba2d0f184abbd019ab3cf4a93c4
2024-07-23 17:09:37 +00:00
Jefftree
18dd587a4b feedback: leasecandidate clients
Kubernetes-commit: fac758164029e278e9bda924090ed078bb6514c8
2024-07-23 14:28:08 +00:00
Dr. Stefan Schimanski
1f27757b2f Review feedback
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>

Kubernetes-commit: 68226b0501996fc86c9c2bddb7d61e6a64c91304
2024-07-23 14:52:25 +02:00
Jefftree
20993758b7 CLE controller and client changes
Kubernetes-commit: c47ff1e1a9aec44f262674eb6cdbabf80512d981
2024-07-21 20:06:03 +00:00
mprahl
001900e4e9 Allow calling Stop multiple times on RetryWatcher
This makes the Stop method idempotent so that if Stop is called multiple
times, it does not cause a panic due to closing a closed channel.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>

Kubernetes-commit: a54ba917be42c941edf1a0359dced04e1a5e1d6f
2024-07-16 10:55:26 -04:00
Sean Sullivan
6e31289fcf moving for easier cherry-pick
Kubernetes-commit: bc526472515e1a01d41e5a94db2b74462545c984
2024-07-20 05:29:57 -07:00
Sean Sullivan
8108d4122f Falls back to SPDY for gorilla/websocket https proxy error
Kubernetes-commit: 9d560540c5268e0e2aebf5306907494cf522c260
2024-07-19 12:04:41 -07:00
Matthieu MOREL
acc5917341 fix: enable empty and len rules from testifylint on pkg package
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Co-authored-by: Patrick Ohly <patrick.ohly@intel.com>

Kubernetes-commit: f014b754fb5925dfbca6e27a44d0c3968b157e14
2024-06-28 21:20:13 +02:00
Sean Sullivan
0b664571bb Adds logging during remote command executor fallback
Kubernetes-commit: d8269e5a394dfa0116e8baeb7aac0a82eb430e5e
2024-06-16 13:51:09 -07:00