Documentation
¶
Overview ¶
Package client builds a *kubernetes.Clientset from a kubeconfig file or in-cluster credentials, and exposes the REST config and HTTP client it was built from so callers can share one client.
Index ¶
- Constants
- func GetConfigForFile(kubeConfig string) (*rest.Config, error)
- func InClusterConfig() (*rest.Config, error)
- type Client
- type Option
- func WithAcceptContentTypes(contentTypes ...string) Option
- func WithContentType(contentType string) Option
- func WithHttpClient(hc *http.Client) Option
- func WithInClusterConfig() Option
- func WithKubeConfig(file string) Option
- func WithKubeOrInClusterConfig(file string) Option
- func WithRestConfig(cfg *rest.Config) Option
Constants ¶
const ( ContentTypeJSON = "application/json" ContentTypeProtobuf = "application/vnd.kubernetes.protobuf" )
Wire content types accepted by the Kubernetes API server.
Variables ¶
This section is empty.
Functions ¶
func GetConfigForFile ¶
GetConfigForFile returns a REST configuration parsed from the given kubeconfig file path. Thin wrapper over clientcmd.BuildConfigFromFlags exposed for callers that need a config but not a full Client.
func InClusterConfig ¶
InClusterConfig returns the REST configuration for the pod's service account, if the process is running inside a Kubernetes cluster. Returns rest.ErrNotInCluster (wrapped) when not in a cluster.
Types ¶
type Client ¶
type Client struct {
*kubernetes.Clientset
// contains filtered or unexported fields
}
Client wraps a Kubernetes clientset together with the REST config and HTTP client it was built from. Use the embedded Clientset directly for API calls, or HttpClient()/RestConfig() to build other clients sharing the same transport.
func New ¶
New constructs a Client by applying the given options in order, defaulting to WithInClusterConfig() if none set a REST config.
func (*Client) Close ¶
func (c *Client) Close()
Close releases resources held by the Client. Safe to call on a nil or already-closed Client.
func (*Client) HttpClient ¶
HttpClient returns the Client's underlying HTTP client, e.g. for constructing other clients that share the same transport.
func (*Client) K8sClient ¶
func (c *Client) K8sClient() *kubernetes.Clientset
K8sClient returns the Client's underlying *kubernetes.Clientset. Callers may alternatively use the embedded Clientset directly on the Client value.
func (*Client) RestConfig ¶
RestConfig returns a copy of the Client's REST config. Top-level and value-typed nested fields may be freely overwritten, but nested maps/slices (e.g. TLSClientConfig.CAData) share storage with the Client's internal config and must not be mutated.
type Option ¶
Option configures a Client during construction via New. Options apply in order; config-dependent options (WithContentType, WithAcceptContentTypes) require a config-source option (WithKubeConfig, WithInClusterConfig, or WithRestConfig) earlier in the list.
func WithAcceptContentTypes ¶
WithAcceptContentTypes sets the Accept content types to negotiate with the API server, joined with commas. Requires a config-source option earlier in the list.
func WithContentType ¶
WithContentType sets the wire content type used for requests. Requires a config-source option earlier in the list.
func WithHttpClient ¶
WithHttpClient returns an Option that uses the given pre-built HTTP client. Useful when multiple components should share one client (and therefore its connection pool).
func WithInClusterConfig ¶
func WithInClusterConfig() Option
WithInClusterConfig returns an Option that resolves the REST config from the pod's service-account credentials.
func WithKubeConfig ¶
WithKubeConfig returns an Option that resolves the REST config from the given kubeconfig file.
func WithKubeOrInClusterConfig ¶
WithKubeOrInClusterConfig resolves the REST config from the given kubeconfig file if non-empty, or from in-cluster credentials otherwise.
func WithRestConfig ¶
WithRestConfig uses a deep copy (via rest.CopyConfig) of the given REST config, so the caller keeps ownership of the original.