k8sclient

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRunningInCluster

func IsRunningInCluster() bool

IsRunningInCluster returns true if the application is running inside a Kubernetes cluster.

Types

type Client

type Client interface {
	// GetClientset returns the underlying kubernetes.Interface.
	GetClientset() kubernetes.Interface

	// GetDynamicClient returns the dynamic client for unstructured resources.
	GetDynamicClient() dynamic.Interface

	// GetDiscoveryClient returns the discovery client for API discovery.
	GetDiscoveryClient() discovery.DiscoveryInterface

	// GetSecret retrieves a secret by name from the specified namespace.
	GetSecret(ctx context.Context, namespace, name string) (*corev1.Secret, error)

	// CreateSecret creates a new secret in the specified namespace.
	CreateSecret(ctx context.Context, namespace string, secret *corev1.Secret) (*corev1.Secret, error)

	// UpdateSecret updates an existing secret.
	UpdateSecret(ctx context.Context, namespace string, secret *corev1.Secret) (*corev1.Secret, error)

	// ListResources lists resources of a given type.
	ListResources(ctx context.Context, gvr schema.GroupVersionResource, namespace string) (*unstructured.UnstructuredList, error)

	// WatchResources watches for changes to resources of a given type.
	WatchResources(ctx context.Context, gvr schema.GroupVersionResource, namespace string, resourceVersion string) (watch.Interface, error)

	// GetResource retrieves a single resource by name.
	GetResource(ctx context.Context, gvr schema.GroupVersionResource, namespace, name string) (*unstructured.Unstructured, error)

	// ApplyResource applies a resource using server-side apply.
	ApplyResource(ctx context.Context, gvr schema.GroupVersionResource, namespace string, obj *unstructured.Unstructured, fieldManager string) (*unstructured.Unstructured, error)

	// DeleteResource deletes a resource by name.
	DeleteResource(ctx context.Context, gvr schema.GroupVersionResource, namespace, name string) error
}

Client abstracts Kubernetes API operations.

func NewClient

func NewClient() (Client, error)

NewClient creates a new Client that uses real K8s APIs. It supports both in-cluster and out-of-cluster (kubeconfig) execution.

func NewClientFromClients

func NewClientFromClients(clientset kubernetes.Interface, dynamicClient dynamic.Interface) Client

NewClientFromClients creates a Client from existing clients.

func NewClientFromConfig

func NewClientFromConfig(config *rest.Config) (Client, error)

NewClientFromConfig creates a Client from an existing config.

Jump to

Keyboard shortcuts

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