client-go/examples
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
..
create-update-delete-deployment Remove references to openstack and cinder 2022-08-08 16:01:59 -04:00
dynamic-create-update-delete-deployment Remove references to openstack and cinder 2022-08-08 16:01:59 -04:00
fake-client remove import doc comments 2024-12-02 14:43:58 +01:00
in-cluster-client-configuration client-go: remove obsolete auth plugins from examples 2024-10-03 11:08:52 +02:00
leader-election chore(leader-election): modify leader-election comment to OnStoppedLeading callback is always called when the LeaderElector exits, even if it did not start leading. 2024-09-30 09:38:10 +08:00
out-of-cluster-client-configuration client-go: remove obsolete auth plugins from examples 2024-10-03 11:08:52 +02:00
workqueue client-go/tools/cache: add APIs with context parameter 2024-07-26 15:26:00 +02:00
README.md client-go: remove reference to TPR in examples 2022-09-16 15:14:13 +01:00

client-go Examples

This directory contains examples that cover various use cases and functionality for client-go.

Auth plugins

Client configuration is typically loaded from kubeconfig files containing server and credential configuration. Several plugins for obtaining credentials from external sources are available, but are not loaded by default. To enable these plugins in your program, import them in your main package.

You can load all auth plugins:

import _ "k8s.io/client-go/plugin/pkg/client/auth"

Or you can load specific auth plugins:

import _ "k8s.io/client-go/plugin/pkg/client/auth/azure"
import _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
import _ "k8s.io/client-go/plugin/pkg/client/auth/oidc"

Configuration

Basics

Advanced Concepts

  • Work queues: Create a hotloop-free controller with the rate-limited workqueue and the informer framework.
  • Custom Resource Definition (CRD): Register a custom resource type with the API, create/update/query this custom type, and write a controller that drives the cluster state based on the changes to the custom resources.
  • Leader election: Demonstrates the use of the leader election package, which can be used to implement HA controllers.

Testing