Commit Graph
7 Commits
Author SHA1 Message Date
Patrick OhlyandKubernetes Publisher fc0b069a6b client-go: type-safe informers and indexers
All code using the result of the generated client-go Informer() (a
cache.SharedIndexInformer) constantly has to do type casts from "any" to the
actual type of the objects managed by the informer.

This is:
- annoying at best
- often done inconsistently (should failed type assertions be logged and if so,
  how?)
- a source of bugs (not handling FinalStateUnknown, not handling missing
  object, type in event handler not matching the type in the informer)

In contrast, the Lister() result *is* typed. It converts without a type check
in e.g. ResourceIndexer[T].List:

	err = cache.ListAllByNamespace(l.indexer, l.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(T))
	})

This change here does the same wrapping for SharedIndexInformer, Indexer,
index functions and event handler support code. OnDelete is passed
a DeletedObject struct to cover the different scenarios that can occur
when reporting deletion (stale or even nil object!). Extracting key or
name from DeletedObject is guaranteed to never fail because the type-safe
API is restricted to types where the necessary meta data is guaranteed
to be available. This removes another class of tedious error checking.

While not strictly needed, aliases are generated for the generic types because
they are often shorter, easier to type (in particular with auto-complete) and
may help with avoiding an import of k8s.io/client-go/tools/cache.

This is a Go API break because all generated interfaces
change.

Kubernetes-commit: b83b3b39db5eee75af14cdb8d30cfc6899792ec2
2026-06-17 16:13:15 +02:00
Richa BankerandKubernetes Publisher c7b42271a6 Generate informers with InformerName support
Kubernetes-commit: 1fec293a1d9fc53e0e3f1a6a3fe6f8970110c1a7
2026-02-05 11:42:54 -08:00
Lukasz SzaszkiewiczandKubernetes Publisher f2b8c99eff ./hack/update-codegen.sh
Kubernetes-commit: 5594d94e6716599981948d21599700d6dfe43b11
2025-10-17 14:35:36 +02:00
Patrick OhlyandKubernetes Publisher 144c6b454a client-go informers: provide ListWatch *WithContext variants
For compatibility reasons, the old functions without the ctx parameter still
get generated, now with context.Background instead of context.TODO. In practice
that code won't be used by the client-go reflector code because it prefers
the *WithContext functions, but it cannot be ruled out that some other code
only supports the old fields.

Kubernetes-commit: 8cc74e8a266e1042be1c60adfa3091852036f48a
2024-12-09 16:04:52 +01:00
Joe BetzandKubernetes Publisher 47cd9c2a21 generate
Kubernetes-commit: 2595aa13098355414a558b2d97c58d505ca7b6c2
2024-09-03 14:25:56 -04:00
Mike DaneseandKubernetes Publisher 297436d318 generated: run refactor
Kubernetes-commit: 3aa59f7f3077642592dc8a864fcef8ba98699894
2020-02-07 18:16:47 -08:00
Dr. Stefan SchimanskiandKubernetes Publisher 574892d56c Update generated code
Kubernetes-commit: 714b28cf22133d39bd637f8b0e6d5774a4eff415
2019-02-15 13:35:58 +01:00