cluster

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discoverer added in v0.6.0

type Discoverer interface {
	ServerResourcesForGroupVersionWithContext(ctx context.Context, groupVersion string) (*metav1.APIResourceList, error)
}

Discoverer returns the resources the API server serves for one group version. For a group version the server does not serve it must return an error satisfying apierrors.IsNotFound, and every call must reach the server so a newly installed CRD is seen; the Fetcher does its own caching. client-go's *discovery.DiscoveryClient and its fake qualify. memory.NewMemCacheClient does not: it answers ErrCacheNotFound and never refetches until invalidated.

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher retrieves resources from a Kubernetes cluster. It is safe for concurrent use and is meant to be long-lived: discovery results are cached.

func NewFetcher

func NewFetcher(kubeconfig, kubecontext string) (*Fetcher, error)

NewFetcher creates a new cluster Fetcher.

func NewFetcherFromClient

func NewFetcherFromClient(client dynamic.Interface) *Fetcher

NewFetcherFromClient creates a Fetcher from an existing dynamic client. Useful for tests and for consumers that build a dynamic client themselves. The client must be non-nil; a nil client defers failure to the first Get call.

Without discovery the Fetcher guesses the resource name from the kind (lowercase plus "s", with a fixed list of exceptions) and sends the namespace exactly as given. A kind the guess gets wrong, such as Endpoints or a CRD with an irregular plural, is reported by the API server as NotFound. Use NewFetcherWithDiscovery to resolve kinds the way the API server serves them.

func NewFetcherFromConfig

func NewFetcherFromConfig(config *rest.Config) (*Fetcher, error)

NewFetcherFromConfig creates a new cluster Fetcher from an existing *rest.Config. This is the entry point for in-cluster consumers such as a controller-runtime manager, which already hold a REST config and should not go through kubeconfig file loading. Kinds are resolved through API discovery, as with NewFetcherWithDiscovery.

func NewFetcherWithDiscovery added in v0.6.0

func NewFetcherWithDiscovery(client dynamic.Interface, disc Discoverer) *Fetcher

NewFetcherWithDiscovery creates a Fetcher that resolves each kind to its resource name and scope by reading the discovery document of the kind's group version. A cached document is trusted for maxDiscoveryAge (10 minutes), and a kind it lacks triggers a refetch at most once per rediscoveryInterval (30 seconds), so a CRD installed, or recreated with a new plural or scope, after the Fetcher was built is found. If refreshing an aged document fails, a kind it still lists is served from it. A nil disc gives the same Fetcher as NewFetcherFromClient.

func (*Fetcher) Get

func (f *Fetcher) Get(ctx context.Context, apiVersion, kind, namespace, name string) (*unstructured.Unstructured, error)

Get retrieves a single resource from the cluster.

With discovery, a kind the API server does not serve returns an error satisfying meta.IsNoMatchError, and a cluster-scoped kind is fetched without the namespace. A namespaced kind with an empty namespace is requested without one, which the API server answers with NotFound; callers that want a default namespace must fill it in before calling Get.

type ResourceFetcher

type ResourceFetcher interface {
	Get(ctx context.Context, apiVersion, kind, namespace, name string) (*unstructured.Unstructured, error)
}

ResourceFetcher is the interface for retrieving resources from a Kubernetes cluster.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL