Documentation
¶
Overview ¶
Package k8s provides Kubernetes client functionality
Index ¶
- Constants
- type Client
- func (c *Client) ApplyClusteredResource(ctx context.Context, gvr schema.GroupVersionResource, ...) (*unstructured.Unstructured, error)
- func (c *Client) ApplyNamespacedResource(ctx context.Context, gvr schema.GroupVersionResource, namespace string, ...) (*unstructured.Unstructured, error)
- func (c *Client) DeleteClusteredResource(ctx context.Context, gvr schema.GroupVersionResource, name string) error
- func (c *Client) DeleteNamespacedResource(ctx context.Context, gvr schema.GroupVersionResource, namespace, name string) error
- func (c *Client) ExecInPod(ctx context.Context, namespace, name string, command []string, ...) (*unstructured.Unstructured, error)
- func (c *Client) GetClusteredResource(ctx context.Context, gvr schema.GroupVersionResource, name string) (interface{}, error)
- func (c *Client) GetExecInPodFunc() ExecInPodFunc
- func (c *Client) GetNamespacedResource(ctx context.Context, gvr schema.GroupVersionResource, namespace, name string) (interface{}, error)
- func (c *Client) GetPodLogs() PodLogsFunc
- func (c *Client) GetRefreshInterval() time.Duration
- func (c *Client) GetResource(ctx context.Context, gvr schema.GroupVersionResource, ...) (*unstructured.Unstructured, error)
- func (c *Client) IsReady() bool
- func (c *Client) IsRefreshing() bool
- func (c *Client) ListAPIResources(_ context.Context) ([]*metav1.APIResourceList, error)
- func (c *Client) ListClusteredResources(ctx context.Context, gvr schema.GroupVersionResource, labelSelector string, ...) (*unstructured.UnstructuredList, error)
- func (c *Client) ListNamespacedResources(ctx context.Context, gvr schema.GroupVersionResource, namespace string, ...) (*unstructured.UnstructuredList, error)
- func (c *Client) PostResource(ctx context.Context, gvr schema.GroupVersionResource, ...) (*unstructured.Unstructured, error)
- func (c *Client) RefreshClient() error
- func (c *Client) SetClientset(clientset kubernetes.Interface)
- func (c *Client) SetDiscoveryClient(discoveryClient discovery.DiscoveryInterface)
- func (c *Client) SetDynamicClient(dynamicClient dynamic.Interface)
- func (c *Client) SetExecInPodFunc(execInPodFunc ExecInPodFunc)
- func (c *Client) SetPodLogsFunc(getPodLogs PodLogsFunc)
- func (c *Client) SetRestConfigForTest(config *rest.Config)
- func (c *Client) StartPeriodicRefresh(interval time.Duration) error
- func (c *Client) StopPeriodicRefresh() error
- func (c *Client) WithImpersonation(user string, groups []string) (*Client, error)
- type ConfigGetter
- type ExecInPodFunc
- type PodLogsFunc
Constants ¶
const MaxExecTimeout = 1 * time.Minute
MaxExecTimeout is the maximum allowed timeout for exec operations to prevent abuse
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a Kubernetes client with discovery and dynamic capabilities
func (*Client) ApplyClusteredResource ¶
func (c *Client) ApplyClusteredResource( ctx context.Context, gvr schema.GroupVersionResource, obj *unstructured.Unstructured, ) (*unstructured.Unstructured, error)
ApplyClusteredResource creates or updates a clustered resource
func (*Client) ApplyNamespacedResource ¶
func (c *Client) ApplyNamespacedResource( ctx context.Context, gvr schema.GroupVersionResource, namespace string, obj *unstructured.Unstructured, ) (*unstructured.Unstructured, error)
ApplyNamespacedResource creates or updates a namespaced resource
func (*Client) DeleteClusteredResource ¶ added in v0.0.7
func (c *Client) DeleteClusteredResource(ctx context.Context, gvr schema.GroupVersionResource, name string) error
DeleteClusteredResource deletes a clustered resource
func (*Client) DeleteNamespacedResource ¶ added in v0.0.7
func (c *Client) DeleteNamespacedResource(ctx context.Context, gvr schema.GroupVersionResource, namespace, name string) error
DeleteNamespacedResource deletes a namespaced resource
func (*Client) ExecInPod ¶ added in v0.0.8
func (c *Client) ExecInPod( ctx context.Context, namespace, name string, command []string, container string, timeout time.Duration, ) (*unstructured.Unstructured, error)
ExecInPod executes a command in a pod and returns the result The command will be killed if it exceeds the timeout If timeout is 0 or negative, the default timeout (15s) will be used If timeout exceeds MaxExecTimeout, it will be capped at MaxExecTimeout
func (*Client) GetClusteredResource ¶
func (c *Client) GetClusteredResource(ctx context.Context, gvr schema.GroupVersionResource, name string) (interface{}, error)
GetClusteredResource gets a clustered resource
func (*Client) GetExecInPodFunc ¶ added in v0.0.8
func (c *Client) GetExecInPodFunc() ExecInPodFunc
GetExecInPodFunc returns the current exec in pod function
func (*Client) GetNamespacedResource ¶
func (c *Client) GetNamespacedResource( ctx context.Context, gvr schema.GroupVersionResource, namespace, name string, ) (interface{}, error)
GetNamespacedResource gets a namespaced resource
func (*Client) GetPodLogs ¶ added in v0.0.4
func (c *Client) GetPodLogs() PodLogsFunc
GetPodLogs returns the current pod logs function
func (*Client) GetRefreshInterval ¶ added in v0.0.7
GetRefreshInterval returns the current refresh interval Returns 0 if refresh is not running
func (*Client) GetResource ¶ added in v0.0.3
func (c *Client) GetResource(ctx context.Context, gvr schema.GroupVersionResource, namespace, name, subresource string, parameters map[string]string) (*unstructured.Unstructured, error)
GetResource gets a resource or its subresource If subresource is empty, the main resource is returned parameters is a map of string key-value pairs that can be used to customize the request
func (*Client) IsRefreshing ¶ added in v0.0.7
IsRefreshing returns true if the client is periodically refreshing
func (*Client) ListAPIResources ¶
ListAPIResources returns all API resources supported by the Kubernetes API server
func (*Client) ListClusteredResources ¶
func (c *Client) ListClusteredResources( ctx context.Context, gvr schema.GroupVersionResource, labelSelector string, limit int64, continueToken string, ) (*unstructured.UnstructuredList, error)
ListClusteredResources returns all clustered resources of the specified group/version/kind with optional pagination support via limit and continueToken parameters
func (*Client) ListNamespacedResources ¶
func (c *Client) ListNamespacedResources( ctx context.Context, gvr schema.GroupVersionResource, namespace string, labelSelector string, limit int64, continueToken string, ) (*unstructured.UnstructuredList, error)
ListNamespacedResources returns all namespaced resources of the specified group/version/kind in the given namespace with optional pagination support via limit and continueToken parameters
func (*Client) PostResource ¶ added in v0.0.8
func (c *Client) PostResource( ctx context.Context, gvr schema.GroupVersionResource, namespace, name, subresource string, body map[string]interface{}, _ map[string]string, ) (*unstructured.Unstructured, error)
PostResource posts to a resource or its subresource If subresource is empty, the main resource is posted to parameters is a map of string key-value pairs that can be used to customize the request
func (*Client) RefreshClient ¶ added in v0.0.7
RefreshClient re-reads the kubeconfig and updates the client's components
func (*Client) SetClientset ¶ added in v0.0.3
func (c *Client) SetClientset(clientset kubernetes.Interface)
SetClientset sets the clientset (for testing purposes)
func (*Client) SetDiscoveryClient ¶
func (c *Client) SetDiscoveryClient(discoveryClient discovery.DiscoveryInterface)
SetDiscoveryClient sets the discovery client (for testing purposes)
func (*Client) SetDynamicClient ¶
SetDynamicClient sets the dynamic client (for testing purposes)
func (*Client) SetExecInPodFunc ¶ added in v0.0.8
func (c *Client) SetExecInPodFunc(execInPodFunc ExecInPodFunc)
SetExecInPodFunc sets the function used to execute commands in pods (for testing purposes)
func (*Client) SetPodLogsFunc ¶ added in v0.0.4
func (c *Client) SetPodLogsFunc(getPodLogs PodLogsFunc)
SetPodLogsFunc sets the function used to get pod logs (for testing purposes)
func (*Client) SetRestConfigForTest ¶ added in v0.4.0
SetRestConfigForTest sets the rest config (for testing purposes)
func (*Client) StartPeriodicRefresh ¶ added in v0.0.7
StartPeriodicRefresh starts a goroutine that periodically refreshes the client's configuration The interval specifies how often to refresh the configuration Returns an error if refresh is already running
func (*Client) StopPeriodicRefresh ¶ added in v0.0.7
StopPeriodicRefresh stops the periodic refresh goroutine Returns an error if refresh is not running
func (*Client) WithImpersonation ¶ added in v0.4.0
WithImpersonation returns a new Client that impersonates the given user and groups. The underlying rest.Config is cloned with ImpersonationConfig set, and new discovery, dynamic, and clientset clients are created from it.
The returned Client is independent of the receiver — mutations to one do not affect the other. The returned Client does NOT inherit periodic refresh or testing overrides (getPodLogs, execInPod) from the base client; it uses the default implementations. This is intentional: impersonated clients are short-lived, per-request objects.
type ConfigGetter ¶ added in v0.0.7
ConfigGetter is a function type for getting Kubernetes client configuration
type ExecInPodFunc ¶ added in v0.0.8
type ExecInPodFunc func( ctx context.Context, namespace, name string, command []string, container string, timeout time.Duration, ) (*unstructured.Unstructured, error)
ExecInPodFunc is a function type for executing commands in pods
type PodLogsFunc ¶ added in v0.0.3
type PodLogsFunc func( ctx context.Context, namespace, name string, parameters map[string]string, ) (*unstructured.Unstructured, error)
PodLogsFunc is a function type for retrieving pod logs