Documentation
¶
Overview ¶
Package client is Kubernetes client for getting resource from Kubernetes cluster.
Index ¶
- Constants
- func NewDynamicClient(c Client) (Dynamic, RESTMapper, error)
- func NewLabelSelector(key string, op selection.Operator, vals []string) (labels.Selector, error)
- func ObjectPredicates[T any, PT interface{ ... }](filter func(PT) bool) builder.Predicates
- type Client
- type Dynamic
- type DynamicResource
- type Option
- type Patcher
- type RESTMapper
Constants ¶
const RESTScopeNameNamespace = meta.RESTScopeNameNamespace
RESTScopeNameNamespace identifies namespace-scoped resources in a RESTMapping.
Variables ¶
This section is empty.
Functions ¶
func NewDynamicClient ¶ added in v1.8.0
func NewDynamicClient(c Client) (Dynamic, RESTMapper, error)
NewDynamicClient builds a dynamic client and a RESTMapper from the Client's rest config so arbitrary GVKs can be resolved to GVRs.
func NewLabelSelector ¶ added in v1.8.0
NewLabelSelector creates a labels.Selector for Options like ListOptions.
func ObjectPredicates ¶ added in v1.8.0
func ObjectPredicates[T any, PT interface { *T cli.Object }](filter func(PT) bool) builder.Predicates
ObjectPredicates returns builder.Predicates that pass only events whose object is a PT accepted by filter. It builds on controller-runtime's predicate.NewPredicateFuncs, whose event mapping (Create/Delete/Generic use e.Object, Update uses e.ObjectNew) matches what per-Kind hand-written predicate.Funcs would do. The pointer constraint is spelled inline because reusing resource.Objectable would create an import cycle (internal/k8s/resource imports this package).
Types ¶
type Client ¶
type Client interface {
k8s.Client
// Apply applies the given apply configuration to the Kubernetes cluster
// using server-side apply. This controller-runtime version's Client
// already declares Apply as part of its Writer, so restating it here is
// purely documentation and does not require a separate implementation.
Apply(ctx context.Context, obj runtime.ApplyConfiguration, opts ...cli.ApplyOption) error
// GetClientSet returns the raw client-go clientset, for APIs
// controller-runtime's Client cannot express (typed clientset calls,
// SPDY port-forward, ServiceAccount token requests).
GetClientSet() kubernetes.Interface
// GetRESTConfig returns the *rest.Config the client and clientset were
// built from.
GetRESTConfig() *rest.Config
}
Client is the single Kubernetes client abstraction, replacing the former three-way split between the internal/k8s.Client alias, StandaloneClient and ClientSet: full CRUD via the embedded k8s.Client (controller-runtime's Client, what mgr.GetClient() returns), Apply for server-side apply, and direct client-go access (GetClientSet/GetRESTConfig) for functionality controller-runtime's Client cannot express (SPDY port-forward, ServiceAccount token requests, typed clientset calls).
func New ¶
New builds a standalone Client for code that runs outside a manager (e.g. one-shot operators, jobs, config loaders). It replaces the former client.New() (StandaloneClient) + client.NewClientSet() (ClientSet) pair: scheme construction and cli.NewWithWatch are carried over unchanged from the old New, and unless WithRESTConfig already supplied a *rest.Config, it is resolved through the same fallback chain the old NewClientSet used (an explicit kubeconfig path, then the KUBECONFIG environment variable, then the recommended home kubeconfig, then finally the in-cluster configuration). The resolved config then builds both the watch-capable controller-runtime client and the client-go Clientset.
func NewFromManager ¶ added in v1.8.0
NewFromManager builds a Client from a controller-runtime manager: the caller already has mgr.GetClient() (a working, watch-capable client scoped to the manager's cache) and mgr.GetConfig() (the REST config used to build a matching client-go Clientset).
type Dynamic ¶ added in v1.8.0
Dynamic is the dynamic client interface for operating on arbitrary resources by GroupVersionResource.
type DynamicResource ¶ added in v1.8.0
type DynamicResource = dynamic.ResourceInterface
DynamicResource operates on a single dynamic resource.
type Option ¶
type Option func(*client) error
func WithKubeConfigPath ¶ added in v1.8.0
WithKubeConfigPath sets an explicit kubeconfig file path, overriding the KUBECONFIG environment variable / recommended home file auto-detection that New falls back to when no RESTConfig is supplied.
func WithKubeContext ¶ added in v1.8.0
WithKubeContext selects a non-default context from the resolved kubeconfig.
func WithRESTConfig ¶ added in v1.8.0
WithRESTConfig sets the *rest.Config used to construct the underlying controller-runtime client and Clientset, so New can be used from environments that cannot rely on the KUBECONFIG/in-cluster auto-detection (e.g. tests or external tooling holding their own rest.Config).
func WithSchemeBuilder ¶
func WithSchemeBuilder(sb runtime.SchemeBuilder) Option
WithSchemeBuilder registers the given scheme builder's types on the client's scheme.
type Patcher ¶ added in v1.7.12
type Patcher interface {
// ApplyPodAnnotations applies the given annotations to the agent pod with server-side apply.
ApplyPodAnnotations(ctx context.Context, name, namespace string, entries map[string]string) error
}
Patcher is an interface for patching resources with controller-runtime client.
func NewPatcher ¶ added in v1.7.12
type RESTMapper ¶ added in v1.8.0
type RESTMapper = meta.RESTMapper
RESTMapper resolves GroupVersionKinds to GroupVersionResources.