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
The underlying implementation has both. Exposing that in the result of
Discovery() makes it easier for consumers to call the WithContext methods
because they don't need to wrap with ToDiscoveryInterfaceWithContext().
This is a breaking Go API change because tests which implement
the interface have to be updated.
Kubernetes-commit: d8f70b87cec6888420e778bca1ea8022a6617140
Passing a context to StartWithContext enables context-aware reflector
logging. This is the main remaining source of log spam (output to stderr
instead of per-test logger) in controller unit tests.
WaitForCacheSynceWithContext takes advantage of the new cache.WaitFor +
NamedHasSynced functionality to finish "immediately" (= no virtual time
passed) in a synctest bubble. While at it, the return type gets improved so
that a failure is easier to handle.
Kubernetes-commit: 5ff323de791df88880f6e065f5de4b445e5c90ed
NewSimpleClientset was marked as deprecated when NewClientset was
introduced. This has caused some confusion:
- Not all packages have NewClientset (https://github.com/kubernetes/kubernetes/issues/135980).
- Tests that work with NewSimpleClientset fail when
switched to NewClientset (https://github.com/kubernetes/kubernetes/issues/136327)
because of missing CRD support (https://github.com/kubernetes/kubernetes/issues/126850).
It doesn't seem burdensome to keep NewSimpleClientset around forever. Some unit
tests may even prefer to use it when they don't need server-side apply (less
overhead). Therefore there is no need to deprecate it.
This avoids churn in the eco system because contributors no longer create PRs
"because the linter complains about the usage of a deprecated function".
Kubernetes-commit: e80da21868059f789c90105a00481fa8cef169e1
This has been replaced by `//build:...` for a long time now.
Removal of the old build tag was automated with:
for i in $(git grep -l '^// +build' | grep -v -e '^vendor/'); do if ! grep -q '^// Code generated' "$i"; then sed -i -e '/^\/\/ +build/d' "$i"; fi; done
Kubernetes-commit: ad79e479c2314d1de91e54bc5630c52027f12e21
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
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
Since the stop channels were replaced in e346475, the commentary is
incorrect and confusing.
Kubernetes-commit: 03be789851db6e0606b2d58c220d0cb40f127168
It seems valuable to be able to provide hand-written docs for these
first-level directories, and if don't want them, the generated doc.go
files are not actually very helpful.
This commit also adds new doc.go files for client-go listers/ and
informers/.
Kubernetes-commit: 95bf7b0afe9dd6a0f00125b1d290514a23e778e2
There should only be one source of truth for the API group's name and
version.
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Kubernetes-commit: e13198ec6f52c4a6405388e90053954dc7656a31