logo

Kubernetes - client-go

Last Updated: 2022-12-05

https://github.com/kubernetes/client-go

ListerWatcher

The ListerWatcher interface in the client-go SDK, used in all Go-based Kubernetes controllers, plays a critical role on how these events are generated, propagated and reliably consumed throughout the various Kubernetes components and actors.

type ListerWatcher interface {
  Lister
  Watcher
}

list and watch

client.Get()
client.Watch()

Cache

client-go cache:

  • Reflector watches a specified resource and causes all changes to be reflected in the given store.
  • Store is the interface of the cache; ExpirationCache is one of the implementation.

Package cache is a client-side caching mechanism. It is useful for reducing the number of server calls you'd otherwise need to make. Reflector watches a server and updates a Store. Two stores are provided; one that simply caches objects (for example, to allow a scheduler to list currently available nodes), and one that additionally acts as a FIFO queue (for example, to allow a scheduler to process incoming pods).

Used by Helm

client-go/rest/client.go

RESTClient has a http.Client inside.

k8s.io/cli-runtime/pkg/genericclioptions/config_flags.go

genericclioptions.RESTClientGetter can get configs in different formats

Helm init takes a RESTClientGetter

vendor/helm.sh/helm/v3/pkg/action/action.go

vendor/helm.sh/helm/v3/pkg/kube/client.go

kube.New(getter) takes a RESTClientGetter to create a Client

chart.Apply(restClientGetter, installOptions) to install charts