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
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
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
It's clear that client-sets contain many versions of one group, so this
comment just seems to be out-dated.
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Kubernetes-commit: 588f016c3bc04ea2da85d7077643677028a8cb1b
SharedInformerFactory starts goroutines in Start and those can be stopped by
closing the stop channel. However, there was no API that waits for the
goroutines.
This is a problem for unit testing. A test has to return while the informers
are still running, which may get flagged by tools like
https://github.com/uber-go/goleak or by klog/ktesting when those informers
lead to log output.
While at it, more documentation gets added to address
https://github.com/kubernetes/kubernetes/issues/65036.
Kubernetes-commit: e89d1d47e8365cad31600b17dab662d3c8a359dd
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
Kubernetes-commit: a9593d634c6a053848413e600dadbf974627515f