Help us shape the future of Go! Take the 2026 Go Developer Survey

kubernetes

package
v1.0.1271 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 51 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

Functions

func BytesToUtf8Lf added in v1.0.660

func BytesToUtf8Lf(file []byte) (string, error)

func GetAPIServer added in v1.0.878

func GetAPIServer(kubeconfigRaw []byte) (string, error)

func GetClusterName added in v1.0.596

func GetClusterName(config *rest.Config) string

GetClusterName returns the name of the cluster

func GetClusterNameFromKubeconfig added in v1.0.900

func GetClusterNameFromKubeconfig(config *clientcmdapi.Config) (clusterName string, server string)

func GetProxiedURL added in v1.0.1162

func GetProxiedURL(ctx context.Context, k8s kubernetes.Interface, config *rest.Config, opts PortForwardOptions, url string) (string, error)

func GetTransportRoundtripper added in v1.0.1162

func GetTransportRoundtripper(config *rest.Config) (func(http.RoundTripper) http.RoundTripper, error)

func GetUnstructuredObjects added in v1.0.660

func GetUnstructuredObjects(data []byte) ([]unstructured.Unstructured, error)

func NewClient

func NewClient(log logger.Logger, kubeconfigPaths ...string) (kubernetes.Interface, *rest.Config, error)

func NewClientFromPathOrConfig added in v1.0.763

func NewClientFromPathOrConfig(
	logger logger.Logger,
	kubeconfigOrPath string,
	collector ...*har.Collector,
) (kubernetes.Interface, *rest.Config, error)

func NewClientWithConfig

func NewClientWithConfig(log logger.Logger, kubeConfig []byte, collector ...*har.Collector) (kubernetes.Interface, *rest.Config, error)

func ParseAPIVersionKind added in v1.0.1175

func ParseAPIVersionKind(apiVersionKind string) (schema.GroupVersionKind, error)

ParseAPIVersionKind parses an apiVersion/Kind string into a GroupVersionKind. This format allows specifying the exact API group, version, and kind to avoid ambiguity when multiple resources share the same Kind name.

Supported formats:

  • "version/kind" for core API group (e.g., "v1/Pod", "v1/Service")
  • "group/version/kind" for named API groups (e.g., "apps/v1/Deployment")
  • "domain.group/version/kind" for domain-based groups (e.g., "serving.knative.dev/v1/Service")

Examples:

  • "v1/Pod" → {Group: "", Version: "v1", Kind: "Pod"}
  • "apps/v1/Deployment" → {Group: "apps", Version: "v1", Kind: "Deployment"}
  • "serving.knative.dev/v1/Service" → {Group: "serving.knative.dev", Version: "v1", Kind: "Service"}

This is useful when you need to distinguish between resources with the same Kind but different API groups (e.g., v1/Service vs serving.knative.dev/v1/Service).

func PortForward added in v1.0.1162

func PortForward(ctx context.Context, k8s kubernetes.Interface, restConfig *rest.Config, opts PortForwardOptions) (int, chan struct{}, error)

func PortForwardDeployment added in v1.0.1162

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 v1.0.1162

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 label selector. Returns the local port, a stop channel to close when done, and any error.

func PortForwardService added in v1.0.1162

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 added in v1.0.854

func RestConfigFingerprint(rc *rest.Config) string

RestConfigFingerprint generates a unique SHA-256 hash to identify the Kubernetes API server and client authentication details from the REST configuration.

Types

type Client added in v1.0.770

type Client struct {
	kubernetes.Interface

	Config *rest.Config // Prefer updaating token in place
	// contains filtered or unexported fields
}

func NewKubeClient added in v1.0.596

func NewKubeClient(logger logger.Logger, client kubernetes.Interface, config *rest.Config) *Client

func (*Client) DeleteByGVK added in v1.0.770

func (c *Client) DeleteByGVK(ctx context.Context, namespace, name string, gvk schema.GroupVersionKind) (bool, error)

func (*Client) ExecutePodf added in v1.0.770

func (c *Client) ExecutePodf(
	ctx context.Context,
	namespace, pod, container string,
	command ...string,
) (string, string, error)

func (*Client) ExpandNamespaces added in v1.0.901

func (c *Client) ExpandNamespaces(ctx context.Context, namespace string) ([]string, error)

func (*Client) FetchResources added in v1.0.770

func (c *Client) FetchResources(
	ctx context.Context,
	resources ...unstructured.Unstructured,
) ([]unstructured.Unstructured, error)

func (*Client) GetClientAndMappingByGroupVersionKind added in v1.0.1175

func (c *Client) GetClientAndMappingByGroupVersionKind(
	ctx context.Context, group, version, kind string,
) (dynamic.NamespaceableResourceInterface, *meta.RESTMapping, error)

func (*Client) GetClientByGroupVersionKind added in v1.0.770

func (c *Client) GetClientByGroupVersionKind(
	ctx context.Context, group, version, kind string,
) (dynamic.NamespaceableResourceInterface, error)

func (*Client) GetClientByKind added in v1.0.770

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 added in v1.0.770

func (c *Client) GetDynamicClient() (dynamic.Interface, error)

GetDynamicClient creates a new k8s client

func (*Client) GetPodLogs added in v1.0.770

func (c *Client) GetPodLogs(ctx context.Context, namespace, podName, container string) (io.ReadCloser, error)

func (*Client) GetRestMapper added in v1.0.770

func (c *Client) GetRestMapper() (meta.RESTMapper, error)

func (*Client) QueryResources added in v1.0.898

func (c *Client) QueryResources(ctx context.Context, selector types.ResourceSelector) ([]unstructured.Unstructured, error)

func (*Client) Reset added in v1.0.872

func (c *Client) Reset()

func (*Client) ResetRestMapper added in v1.0.916

func (c *Client) ResetRestMapper()

func (*Client) RestConfig added in v1.0.854

func (c *Client) RestConfig() *rest.Config

func (*Client) SetLogger added in v1.0.900

func (c *Client) SetLogger(logger logger.Logger)

func (*Client) StreamLogsV2 added in v1.0.770

func (c *Client) StreamLogsV2(
	ctx context.Context,
	namespace, name string,
	timeout time.Duration,
	containerNames ...string,
) error

func (*Client) WaitForContainerStart added in v1.0.770

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) WaitForPod added in v1.0.770

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

type PortForwardOptions added in v1.0.1162

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL