Documentation
¶
Index ¶
- Constants
- Variables
- func BytesToUtf8Lf(file []byte) (string, error)
- func GetAPIServer(kubeconfigRaw []byte) (string, error)
- func GetClusterName(config *rest.Config) string
- func GetClusterNameFromKubeconfig(config *clientcmdapi.Config) (clusterName string, server string)
- func GetUnstructuredObjects(data []byte) ([]unstructured.Unstructured, error)
- func NewClient(log logger.Logger, kubeconfigPaths ...string) (kubernetes.Interface, *rest.Config, error)
- func NewClientFromPathOrConfig(logger logger.Logger, kubeconfigOrPath string) (kubernetes.Interface, *rest.Config, error)
- func NewClientWithConfig(log logger.Logger, kubeConfig []byte) (kubernetes.Interface, *rest.Config, error)
- func PortForward(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, ...) (int, chan struct{}, error)
- func PortForwardDeployment(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, ...) (int, chan struct{}, error)
- func PortForwardPod(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, ...) (int, chan struct{}, error)
- func PortForwardService(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, ...) (int, chan struct{}, error)
- func RestConfigFingerprint(rc *rest.Config) string
- type Client
- func (c *Client) Apply(ctx context.Context, manifest string) (Resources, error)
- func (c *Client) ApplyFile(ctx context.Context, files ...string) (Resources, error)
- func (c *Client) DeleteByGVK(ctx context.Context, namespace, name string, gvk schema.GroupVersionKind) (bool, error)
- func (c *Client) ExecutePodf(ctx context.Context, namespace, pod, container string, command ...string) (string, string, error)
- func (c *Client) ExpandNamespaces(ctx context.Context, namespace string) ([]string, error)
- func (c *Client) FetchResources(ctx context.Context, resources ...unstructured.Unstructured) ([]unstructured.Unstructured, error)
- func (c *Client) Get(ctx context.Context, kind, namespace, name string) (*unstructured.Unstructured, error)
- func (c *Client) GetClientByGroupVersionKind(ctx context.Context, group, version, kind string) (dynamic.NamespaceableResourceInterface, *meta.RESTMapping, error)
- func (c *Client) GetClientByKind(kind string) (dynamic.NamespaceableResourceInterface, *meta.RESTMapping, error)
- func (c *Client) GetDynamicClient() (dynamic.Interface, error)
- func (c *Client) GetPodIP(ctx context.Context, namespace, selector string) (string, error)
- func (c *Client) GetPodLogs(ctx context.Context, namespace, podName, container string) (io.ReadCloser, error)
- func (c *Client) GetResource(ctx context.Context, kind, namespace, name string) (*Resource, error)
- func (c *Client) GetRestMapper() (meta.RESTMapper, error)
- func (c *Client) List(ctx context.Context, kind, namespace, selector string) ([]unstructured.Unstructured, error)
- func (c *Client) QueryResources(ctx context.Context, selector types.ResourceSelector) ([]unstructured.Unstructured, error)
- func (c *Client) Reset()
- func (c *Client) ResetRestMapper()
- func (c *Client) RestConfig() *rest.Config
- func (c *Client) SetLogger(logger logger.Logger)
- func (c *Client) StreamLogsV2(ctx context.Context, namespace, name string, timeout time.Duration, ...) error
- func (c *Client) WaitFor(ctx context.Context, kind, namespace, name string, ...) (*unstructured.Unstructured, error)
- func (c *Client) WaitForContainerStart(ctx context.Context, namespace, name string, timeout time.Duration, ...) error
- func (c *Client) WaitForJob(ctx context.Context, namespace, name string, timeout time.Duration) error
- func (c *Client) WaitForPod(ctx context.Context, namespace, name string, timeout time.Duration, ...) error
- func (c *Client) WaitForReady(ctx context.Context, kind, namespace, name string, timeout ...time.Duration) (*Resource, error)
- func (c *Client) WithNamespace(namespace string) *Client
- type ForwardManager
- type PortForwardOptions
- type Resource
- type Resources
Constants ¶
const DefaultForwardIdleTimeout = 30 * time.Minute
DefaultForwardIdleTimeout is how long an idle tunnel is kept before the reaper closes it. It MUST stay >= the connection hydration cache TTL (30m): while a hydrated URL is cached its tunnel must stay up, since re-establishing would allocate a different local port and the cached localhost:<port> would be dead.
Variables ¶
var Nil = fake.NewSimpleClientset()
Functions ¶
func BytesToUtf8Lf ¶
func GetAPIServer ¶
func GetClusterName ¶
GetClusterName returns the name of the cluster
func GetClusterNameFromKubeconfig ¶
func GetClusterNameFromKubeconfig(config *clientcmdapi.Config) (clusterName string, server string)
func GetUnstructuredObjects ¶
func GetUnstructuredObjects(data []byte) ([]unstructured.Unstructured, error)
func NewClientWithConfig ¶
func PortForward ¶ added in v0.1.13
func PortForward(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, opts PortForwardOptions) (int, chan struct{}, error)
PortForward establishes an SPDY port-forward tunnel to the workload identified by opts, dispatching on Kind. It returns the allocated local port, a stop channel that tears the tunnel down when closed, and any error.
func PortForwardDeployment ¶ added in v0.1.13
func PortForwardDeployment(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, opts PortForwardOptions) (int, chan struct{}, error)
PortForwardDeployment sets up port forwarding to a pod managed by the specified deployment. The deployment is found by Name or LabelSelector. Returns the local port, a stop channel, and any error.
func PortForwardPod ¶ added in v0.1.13
func PortForwardPod(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, opts PortForwardOptions) (int, chan struct{}, error)
PortForwardPod sets up port forwarding to a pod matching the given name or label selector. Returns the local port, a stop channel to close when done, and any error.
func PortForwardService ¶ added in v0.1.13
func PortForwardService(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, opts PortForwardOptions) (int, chan struct{}, error)
PortForwardService sets up port forwarding to a pod backing the specified service. The service is found by Name or LabelSelector. Returns the local port, a stop channel, and any error.
func RestConfigFingerprint ¶
RestConfigFingerprint generates a unique SHA-256 hash to identify the Kubernetes API server and client authentication details from the REST configuration.
Types ¶
type Client ¶
type Client struct {
kubernetes.Interface
Config *rest.Config // Prefer updaating token in place
// contains filtered or unexported fields
}
func NewKubeClient ¶
func (*Client) DeleteByGVK ¶
func (*Client) ExecutePodf ¶
func (*Client) ExpandNamespaces ¶
func (*Client) FetchResources ¶
func (c *Client) FetchResources( ctx context.Context, resources ...unstructured.Unstructured, ) ([]unstructured.Unstructured, error)
func (*Client) Get ¶ added in v0.1.1
func (c *Client) Get(ctx context.Context, kind, namespace, name string) (*unstructured.Unstructured, error)
func (*Client) GetClientByGroupVersionKind ¶
func (c *Client) GetClientByGroupVersionKind( ctx context.Context, group, version, kind string, ) (dynamic.NamespaceableResourceInterface, *meta.RESTMapping, error)
func (*Client) GetClientByKind ¶
func (c *Client) GetClientByKind(kind string) (dynamic.NamespaceableResourceInterface, *meta.RESTMapping, error)
WARN: "Kind" is not specific enough. A cluster can have various resources with the same Kind. example: helmchrats.helm.cattle.io & helmcharts.source.toolkit.fluxcd.io both have HelmChart as the kind.
Use GetClientByGroupVersionKind instead.
func (*Client) GetDynamicClient ¶
GetDynamicClient creates a new k8s client
func (*Client) GetPodLogs ¶
func (*Client) GetResource ¶ added in v0.1.1
func (*Client) GetRestMapper ¶
func (c *Client) GetRestMapper() (meta.RESTMapper, error)
func (*Client) List ¶ added in v0.1.1
func (c *Client) List(ctx context.Context, kind, namespace, selector string) ([]unstructured.Unstructured, error)
func (*Client) QueryResources ¶
func (c *Client) QueryResources(ctx context.Context, selector types.ResourceSelector) ([]unstructured.Unstructured, error)
func (*Client) ResetRestMapper ¶
func (c *Client) ResetRestMapper()
func (*Client) RestConfig ¶
func (*Client) StreamLogsV2 ¶
func (*Client) WaitFor ¶ added in v0.1.1
func (c *Client) WaitFor(ctx context.Context, kind, namespace, name string, condition func(*unstructured.Unstructured) bool, timeout time.Duration) (*unstructured.Unstructured, error)
func (*Client) WaitForContainerStart ¶
func (c *Client) WaitForContainerStart( ctx context.Context, namespace, name string, timeout time.Duration, containerNames ...string, ) error
WaitForContainerStart waits for the specified containers to be started (or any container if no names are specified) - returns an error if the timeout is exceeded
func (*Client) WaitForJob ¶ added in v0.1.4
func (c *Client) WaitForJob( ctx context.Context, namespace, name string, timeout time.Duration, ) error
WaitForJob waits for a job to complete or fail within the specified timeout. Returns nil if the job completes successfully, or an error if the job fails or times out.
func (*Client) WaitForPod ¶
func (c *Client) WaitForPod( ctx context.Context, namespace, name string, timeout time.Duration, phases ...v1.PodPhase, ) error
WaitForPod waits for a pod to be in the specified phase, or returns an error if the timeout is exceeded
func (*Client) WaitForReady ¶ added in v0.1.1
func (*Client) WithNamespace ¶ added in v0.1.1
type ForwardManager ¶ added in v0.1.13
type ForwardManager struct {
// contains filtered or unexported fields
}
ForwardManager owns live port-forward tunnels and reuses them across hydrations and connections. Tunnels are keyed by cluster + target so concurrent callers requesting the same workload share one tunnel, and a reaper closes tunnels left idle past idleTimeout.
func DefaultForwardManager ¶ added in v0.1.13
func DefaultForwardManager() *ForwardManager
DefaultForwardManager returns the process-wide forward manager, creating it on first use.
func NewForwardManager ¶ added in v0.1.13
func NewForwardManager(idleTimeout time.Duration) *ForwardManager
NewForwardManager returns a manager with the given idle timeout, defaulting to DefaultForwardIdleTimeout, and starts its reaper using PortForward as the establisher.
func (*ForwardManager) Forward ¶ added in v0.1.13
func (m *ForwardManager) Forward(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, opts PortForwardOptions) (int, error)
Forward returns a local port that tunnels to the workload identified by opts, reusing a live tunnel when one already exists for the same cluster + target and (re)establishing otherwise.
type PortForwardOptions ¶ added in v0.1.13
type PortForwardOptions struct {
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
LabelSelector string `json:"labelSelector,omitempty"`
RemotePort int `json:"remotePort,omitempty"`
Kind string `json:"kind"`
}
PortForwardOptions configures port forwarding to a Kubernetes resource. Either Name or LabelSelector must be provided to identify the target resource.
type Resource ¶ added in v0.1.1
type Resource struct {
unstructured.Unstructured
health.HealthStatus
}
type Resources ¶ added in v0.1.1
type Resources []Resource
func NewResources ¶ added in v0.1.1
func NewResources(objs ...unstructured.Unstructured) Resources
func (Resources) AsUnstructured ¶ added in v0.1.1
func (r Resources) AsUnstructured() []unstructured.Unstructured