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 ¶
NewFetcher creates a new cluster Fetcher.
func NewFetcherFromClient ¶
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 ¶
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, once per group version. A kind the cached document lacks triggers a refetch on a later Get (at most one per group version per rediscoveryInterval, 30 seconds), so a CRD installed after the Fetcher was built is found. 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.